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();
32 void BackgroundStateContext::completeRequestedStateTransitionIfExists()
34 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::completeRequestedStateTransitionIfExists";
36 if (m_currentState != m_requestedState) {
40 if (m_currentState != NUM_BACKGROUND_STATES) {
43 m_states [m_currentState]->end ();
47 m_currentState = m_requestedState;
48 m_states [m_requestedState]->begin ();
54 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView";
57 ENGAUGE_ASSERT (m_currentState != NUM_BACKGROUND_STATES);
59 const QGraphicsPixmapItem *imageItem = &m_states [BACKGROUND_STATE_CURVE]->imageItem ();
61 double width = imageItem->boundingRect().width();
62 double height = imageItem->boundingRect().height();
64 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView"
65 <<
" state=" << m_states [m_currentState]->state ().toLatin1().data()
66 <<
" boundingRect=(" << width <<
"x" << height <<
")";
69 view.fitInView (imageItem);
75 return m_states [BACKGROUND_STATE_CURVE]->image();
80 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::requestStateTransition";
82 m_requestedState = backgroundState;
87 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setBackgroundImage"
88 <<
" background=" << backgroundImageToString (backgroundImage).toLatin1().data();
90 BackgroundState backgroundState;
91 switch (backgroundImage) {
92 case BACKGROUND_IMAGE_FILTERED:
93 backgroundState = BACKGROUND_STATE_CURVE;
96 case BACKGROUND_IMAGE_NONE:
97 backgroundState = BACKGROUND_STATE_NONE;
100 case BACKGROUND_IMAGE_ORIGINAL:
101 backgroundState = BACKGROUND_STATE_ORIGINAL;
105 LOG4CPP_ERROR_S ((*mainCat)) <<
"BackgroundStateContext::selectBackgroundImage";
111 completeRequestedStateTransitionIfExists ();
117 const QString &curveSelected)
119 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setCurveSelected"
120 <<
" curve=" << curveSelected.toLatin1().data();
122 ENGAUGE_ASSERT (!curveSelected.isEmpty ());
124 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
126 m_states [backgroundState]->setCurveSelected (transformation,
136 const QPixmap &pixmapOriginal)
138 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setPixmap";
140 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
142 m_states [backgroundState]->setPixmap (transformation,
153 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::updateColorFilter";
155 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
157 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...
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...