Engauge Digitizer  2
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 
15  GraphicsScene &scene) :
16  m_context (context),
17  m_scene (scene),
18  m_imageItem (0)
19 {
20  // Create an image but do not show it until the appropriate state is reached
21  QPixmap dummy;
22  m_imageItem = m_scene.addPixmap (dummy);
23  m_imageItem->setVisible (false);
24  m_imageItem->setData (DATA_KEY_IDENTIFIER, "view");
25  m_imageItem->setData (DATA_KEY_GRAPHICS_ITEM_TYPE, GRAPHICS_ITEM_TYPE_IMAGE);
26 }
27 
28 BackgroundStateAbstractBase::~BackgroundStateAbstractBase()
29 {
30 }
31 
33 {
34  return m_context;
35 }
36 
38 {
39  return m_context;
40 }
41 
43 {
44  return m_image;
45 }
46 
47 QGraphicsPixmapItem &BackgroundStateAbstractBase::imageItem () const
48 {
49  return *m_imageItem;
50 }
51 
53 {
54  return m_scene;
55 }
56 
58 {
59  return m_scene;
60 }
61 
63 {
64  m_imageItem->setVisible (visible);
65 }
66 
68 {
69  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateAbstractBase::setProcessedPixmap"
70  << " map=(" << pixmap.width() << "x" << pixmap.height() << ")";
71 
72  ENGAUGE_CHECK_PTR(m_imageItem);
73 
74  m_imageItem->setPixmap (pixmap);
75 
76  // Reset scene rectangle or else small image after large image will be off-center
77  m_scene.setSceneRect (m_imageItem->boundingRect ());
78 
79  m_image = pixmap.toImage();
80 }
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:31
GraphicsScene & scene()
Reference to the GraphicsScene, without const.