Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
BackgroundStateAbstractBase.cpp
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 
7 #include "BackgroundStateAbstractBase.h"
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 (0)
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");
27  m_imageItem->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_IMAGE);
28 }
29 
30 BackgroundStateAbstractBase::~BackgroundStateAbstractBase()
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 }
QImage image() const
Image for the current state.
QGraphicsPixmapItem & imageItem() const
Graphics image item for the current state.
void setImageVisible(bool visible)
Show/hide background image.
void setProcessedPixmap(const QPixmap &pixmap)
Save the image for this state after it has been processed by the leaf class.
BackgroundStateAbstractBase(BackgroundStateContext &context, GraphicsScene &scene)
Single constructor.
BackgroundStateContext & context()
Reference to the BackgroundStateContext that contains all the BackgroundStateAbstractBase subclasses...
Context class that manages the background image state machine.
Add point and line handling to generic QGraphicsScene.
Definition: GraphicsScene.h:33
GraphicsScene & scene()
Reference to the GraphicsScene, without const.