Engauge Digitizer  2
BackgroundStateAbstractBase.cpp
Go to the documentation of this file.
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
8 #include "DataKey.h"
9 #include "EngaugeAssert.h"
10 #include "GraphicsItemType.h"
11 #include "GraphicsScene.h"
12 #include "Logger.h"
13 #include "ZValues.h"
14 
16  GraphicsScene &scene) :
17  m_context (context),
18  m_scene (scene),
19  m_imageItem (nullptr)
20 {
21  // Create an image but do not show it until the appropriate state is reached
22  QPixmap dummy;
23  m_imageItem = m_scene.addPixmap (dummy);
24  m_imageItem->setVisible (false);
25  m_imageItem->setZValue (Z_VALUE_BACKGROUND);
26  m_imageItem->setData (DATA_KEY_IDENTIFIER, "view");
28 }
29 
31 {
32 }
33 
35 {
36  return m_context;
37 }
38 
40 {
41  return m_context;
42 }
43 
45 {
46  return m_image;
47 }
48 
49 QGraphicsPixmapItem &BackgroundStateAbstractBase::imageItem () const
50 {
51  return *m_imageItem;
52 }
53 
55 {
56  return m_scene;
57 }
58 
60 {
61  return m_scene;
62 }
63 
65 {
66  m_imageItem->setVisible (visible);
67 }
68 
70 {
71  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateAbstractBase::setProcessedPixmap"
72  << " map=(" << pixmap.width() << "x" << pixmap.height() << ")";
73 
74  ENGAUGE_CHECK_PTR(m_imageItem);
75 
76  m_imageItem->setPixmap (pixmap);
77 
78  // Reset scene rectangle or else small image after large image will be off-center
79  m_scene.setSceneRect (m_imageItem->boundingRect ());
80 
81  m_image = pixmap.toImage();
82 }
BackgroundStateAbstractBase::~BackgroundStateAbstractBase
virtual ~BackgroundStateAbstractBase()
Definition: BackgroundStateAbstractBase.cpp:30
DATA_KEY_GRAPHICS_ITEM_TYPE
Unique identifier for QGraphicsItem object
Definition: DataKey.h:17
GraphicsItemType.h
BackgroundStateAbstractBase::setImageVisible
void setImageVisible(bool visible)
Show/hide background image.
Definition: BackgroundStateAbstractBase.cpp:64
GRAPHICS_ITEM_TYPE_IMAGE
Definition: GraphicsItemType.h:14
BackgroundStateAbstractBase::BackgroundStateAbstractBase
BackgroundStateAbstractBase(BackgroundStateContext &context, GraphicsScene &scene)
Single constructor.
Definition: BackgroundStateAbstractBase.cpp:15
BackgroundStateAbstractBase.h
EngaugeAssert.h
BackgroundStateAbstractBase::imageItem
QGraphicsPixmapItem & imageItem() const
Graphics image item for the current state.
Definition: BackgroundStateAbstractBase.cpp:49
ENGAUGE_CHECK_PTR
#define ENGAUGE_CHECK_PTR(ptr)
#endif
Definition: EngaugeAssert.h:26
Logger.h
Z_VALUE_BACKGROUND
const int Z_VALUE_BACKGROUND
Z values for ordering of the various graphics layers, with background at the bottom.
Definition: ZValues.cpp:9
LOG4CPP_INFO_S
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
GraphicsScene
Add point and line handling to generic QGraphicsScene.
Definition: GraphicsScene.h:35
DataKey.h
ZValues.h
BackgroundStateAbstractBase::context
BackgroundStateContext & context()
Reference to the BackgroundStateContext that contains all the BackgroundStateAbstractBase subclasses,...
Definition: BackgroundStateAbstractBase.cpp:34
BackgroundStateAbstractBase::setProcessedPixmap
void setProcessedPixmap(const QPixmap &pixmap)
Save the image for this state after it has been processed by the leaf class.
Definition: BackgroundStateAbstractBase.cpp:69
mainCat
log4cpp::Category * mainCat
Definition: Logger.cpp:14
GraphicsScene.h
DATA_KEY_IDENTIFIER
Definition: DataKey.h:16
BackgroundStateAbstractBase::scene
GraphicsScene & scene()
Reference to the GraphicsScene, without const.
Definition: BackgroundStateAbstractBase.cpp:54
BackgroundStateAbstractBase::image
QImage image() const
Image for the current state.
Definition: BackgroundStateAbstractBase.cpp:44
BackgroundStateContext
Context class that manages the background image state machine.
Definition: BackgroundStateContext.h:31