1 #include "BackgroundStateContext.h"
2 #include "BackgroundStateCurve.h"
3 #include "BackgroundStateNone.h"
4 #include "BackgroundStateOriginal.h"
5 #include "BackgroundStateUnloaded.h"
6 #include "DocumentModelColorFilter.h"
7 #include "DocumentModelGridRemoval.h"
8 #include "EngaugeAssert.h"
9 #include "GraphicsView.h"
11 #include "MainWindow.h"
12 #include <QGraphicsPixmapItem>
13 #include "Transformation.h"
16 m_mainWindow (mainWindow)
18 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::BackgroundStateContext";
25 ENGAUGE_ASSERT (m_states.size () == NUM_BACKGROUND_STATES);
27 m_currentState = NUM_BACKGROUND_STATES;
29 completeRequestedStateTransitionIfExists();
34 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::close";
38 completeRequestedStateTransitionIfExists ();
41 void BackgroundStateContext::completeRequestedStateTransitionIfExists()
43 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::completeRequestedStateTransitionIfExists";
45 if (m_currentState != m_requestedState) {
49 if (m_currentState != NUM_BACKGROUND_STATES) {
52 m_states [m_currentState]->end ();
56 m_currentState = m_requestedState;
57 m_states [m_requestedState]->begin ();
63 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView";
66 ENGAUGE_ASSERT (m_currentState != NUM_BACKGROUND_STATES);
68 const QGraphicsPixmapItem *imageItem = &m_states [BACKGROUND_STATE_CURVE]->imageItem ();
70 double width = imageItem->boundingRect().width();
71 double height = imageItem->boundingRect().height();
73 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView"
74 <<
" state=" << m_states [m_currentState]->state ().toLatin1().data()
75 <<
" boundingRect=(" << width <<
"x" << height <<
")";
78 view.fitInView (imageItem);
84 return m_states [BACKGROUND_STATE_CURVE]->image();
89 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::requestStateTransition";
91 m_requestedState = backgroundState;
96 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setBackgroundImage"
97 <<
" background=" << backgroundImageToString (backgroundImage).toLatin1().data();
99 BackgroundState backgroundState;
100 switch (backgroundImage) {
101 case BACKGROUND_IMAGE_FILTERED:
102 backgroundState = BACKGROUND_STATE_CURVE;
105 case BACKGROUND_IMAGE_NONE:
106 backgroundState = BACKGROUND_STATE_NONE;
109 case BACKGROUND_IMAGE_ORIGINAL:
110 backgroundState = BACKGROUND_STATE_ORIGINAL;
114 LOG4CPP_ERROR_S ((*mainCat)) <<
"BackgroundStateContext::selectBackgroundImage";
120 completeRequestedStateTransitionIfExists ();
126 const QString &curveSelected)
128 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setCurveSelected"
129 <<
" curve=" << curveSelected.toLatin1().data();
131 ENGAUGE_ASSERT (!curveSelected.isEmpty ());
133 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
135 m_states [backgroundState]->setCurveSelected (transformation,
145 const QPixmap &pixmapOriginal)
147 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setPixmap";
149 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
151 m_states [backgroundState]->setPixmap (transformation,
162 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::updateColorFilter";
164 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
166 m_states [backgroundState]->updateColorFilter (transformation,
void fitInView(GraphicsView &view)
Zoom so background fills the window.
Background image state for interval between startup and loading of the image.
Background image state for showing filter image from current curve.
void requestStateTransition(BackgroundState backgroundState)
Initiate state transition to be performed later, when BackgroundState is off the stack.
Background image state for showing no image.
void setPixmap(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QPixmap &pixmapOriginal)
Update the images of all states, rather than just the current state.
void setBackgroundImage(BackgroundImage backgroundImage)
Transition to the specified state. This method is used by classes outside of the state machine to tri...
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
GraphicsScene & scene()
Scene container for the QImage and QGraphicsItems.
QGraphicsView class with event handling added. Typically the events are sent to the active digitizing...
void close()
Open Document is being closed so remove the background.
QImage imageForCurveState() const
Image for the Curve state, even if the current state is different.
void setCurveSelected(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QString &curveSelected)
Update the selected curve.
Background image state for showing original (=unfiltered) image.
BackgroundStateContext(MainWindow &mainWindow)
Single constructor.
void updateColorFilter(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter)
Apply color filter settings.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...