Engauge Digitizer 2
Loading...
Searching...
No Matches
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
28BackgroundStateAbstractBase::~BackgroundStateAbstractBase()
29{
30}
31
36
38{
39 return m_context;
40}
41
43{
44 return m_image;
45}
46
47QGraphicsPixmapItem &BackgroundStateAbstractBase::imageItem () const
48{
49 return *m_imageItem;
50}
51
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}
BackgroundStateAbstractBase(BackgroundStateContext &context, GraphicsScene &scene)
Single constructor.
QGraphicsPixmapItem & imageItem() const
Graphics image item for the current state.
GraphicsScene & scene()
Reference to the GraphicsScene, without const.
BackgroundStateContext & context()
Reference to the BackgroundStateContext that contains all the BackgroundStateAbstractBase subclasses,...
void setImageVisible(bool visible)
Show/hide background image.
QImage image() const
Image for the current state.
void setProcessedPixmap(const QPixmap &pixmap)
Save the image for this state after it has been processed by the leaf class.
Context class that manages the background image state machine.
Add point and line handling to generic QGraphicsScene.