7 #include "BackgroundStateContext.h"
8 #include "BackgroundStateCurve.h"
9 #include "BackgroundStateNone.h"
10 #include "BackgroundStateOriginal.h"
11 #include "BackgroundStateUnloaded.h"
12 #include "DocumentModelColorFilter.h"
13 #include "DocumentModelGridRemoval.h"
14 #include "EngaugeAssert.h"
15 #include "GraphicsView.h"
17 #include "MainWindow.h"
18 #include <QGraphicsPixmapItem>
19 #include "Transformation.h"
22 m_mainWindow (mainWindow)
24 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::BackgroundStateContext";
31 ENGAUGE_ASSERT (m_states.size () == NUM_BACKGROUND_STATES);
33 m_currentState = NUM_BACKGROUND_STATES;
35 completeRequestedStateTransitionIfExists();
40 qDeleteAll (m_states);
45 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::close";
49 completeRequestedStateTransitionIfExists ();
52 void BackgroundStateContext::completeRequestedStateTransitionIfExists()
54 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::completeRequestedStateTransitionIfExists";
56 if (m_currentState != m_requestedState) {
60 if (m_currentState != NUM_BACKGROUND_STATES) {
63 m_states [m_currentState]->end ();
67 m_currentState = m_requestedState;
68 m_states [m_requestedState]->begin ();
74 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView";
77 ENGAUGE_ASSERT (m_currentState != NUM_BACKGROUND_STATES);
79 const QGraphicsPixmapItem *imageItem = &m_states [BACKGROUND_STATE_CURVE]->imageItem ();
81 double width = imageItem->boundingRect().width();
82 double height = imageItem->boundingRect().height();
84 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView"
85 <<
" state=" << m_states [m_currentState]->state ().toLatin1().data()
86 <<
" boundingRect=(" << width <<
"x" << height <<
")";
89 view.fitInView (imageItem);
95 return m_states [BACKGROUND_STATE_CURVE]->image();
100 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::requestStateTransition";
102 m_requestedState = backgroundState;
107 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setBackgroundImage"
108 <<
" background=" << backgroundImageToString (backgroundImage).toLatin1().data();
110 BackgroundState backgroundState= BACKGROUND_STATE_NONE;
112 switch (backgroundImage) {
113 case BACKGROUND_IMAGE_FILTERED:
114 backgroundState = BACKGROUND_STATE_CURVE;
117 case BACKGROUND_IMAGE_NONE:
118 backgroundState = BACKGROUND_STATE_NONE;
121 case BACKGROUND_IMAGE_ORIGINAL:
122 backgroundState = BACKGROUND_STATE_ORIGINAL;
128 completeRequestedStateTransitionIfExists ();
135 const QString &curveSelected)
137 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setCurveSelected"
138 <<
" curve=" << curveSelected.toLatin1().data();
140 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
142 m_states [backgroundState]->setCurveSelected (isGnuplot,
154 const QPixmap &pixmapOriginal,
155 const QString &curveSelected)
157 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setPixmap"
158 <<
" image=" << pixmapOriginal.width() <<
"x" << pixmapOriginal.height()
159 <<
" currentState=" << m_states [m_currentState]->state().toLatin1().data();
161 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
163 m_states [backgroundState]->setPixmap (isGnuplot,
176 const QString &curveSelected)
178 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::updateColorFilter";
180 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
182 m_states [backgroundState]->updateColorFilter (isGnuplot,
void fitInView(GraphicsView &view)
Zoom so background fills the window.
void updateColorFilter(bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter, const QString &curveSelected)
Apply color filter settings.
Background image state for interval between startup and loading of the image.
void setPixmap(bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QPixmap &pixmapOriginal, const QString &curveSelected)
Update the images of all states, rather than just the current state.
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 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 setCurveSelected(bool isGnuplot, const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QString &curveSelected)
Update the selected curve.
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.
Background image state for showing original (=unfiltered) image.
BackgroundStateContext(MainWindow &mainWindow)
Single constructor.
~BackgroundStateContext()
Destructor deallocates memory.
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...