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 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::close";
44 completeRequestedStateTransitionIfExists ();
47 void BackgroundStateContext::completeRequestedStateTransitionIfExists()
49 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::completeRequestedStateTransitionIfExists";
51 if (m_currentState != m_requestedState) {
55 if (m_currentState != NUM_BACKGROUND_STATES) {
58 m_states [m_currentState]->end ();
62 m_currentState = m_requestedState;
63 m_states [m_requestedState]->begin ();
69 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView";
72 ENGAUGE_ASSERT (m_currentState != NUM_BACKGROUND_STATES);
74 const QGraphicsPixmapItem *imageItem = &m_states [BACKGROUND_STATE_CURVE]->imageItem ();
76 double width = imageItem->boundingRect().width();
77 double height = imageItem->boundingRect().height();
79 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::fitInView" 80 <<
" state=" << m_states [m_currentState]->state ().toLatin1().data()
81 <<
" boundingRect=(" << width <<
"x" << height <<
")";
84 view.fitInView (imageItem);
90 return m_states [BACKGROUND_STATE_CURVE]->image();
95 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::requestStateTransition";
97 m_requestedState = backgroundState;
102 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setBackgroundImage" 103 <<
" background=" << backgroundImageToString (backgroundImage).toLatin1().data();
105 BackgroundState backgroundState;
106 switch (backgroundImage) {
107 case BACKGROUND_IMAGE_FILTERED:
108 backgroundState = BACKGROUND_STATE_CURVE;
111 case BACKGROUND_IMAGE_NONE:
112 backgroundState = BACKGROUND_STATE_NONE;
115 case BACKGROUND_IMAGE_ORIGINAL:
116 backgroundState = BACKGROUND_STATE_ORIGINAL;
120 LOG4CPP_ERROR_S ((*mainCat)) <<
"BackgroundStateContext::selectBackgroundImage";
126 completeRequestedStateTransitionIfExists ();
132 const QString &curveSelected)
134 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setCurveSelected" 135 <<
" curve=" << curveSelected.toLatin1().data();
137 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
139 m_states [backgroundState]->setCurveSelected (transformation,
149 const QPixmap &pixmapOriginal,
150 const QString &curveSelected)
152 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::setPixmap" 153 <<
" image=" << pixmapOriginal.width() <<
"x" << pixmapOriginal.height()
154 <<
" currentState=" << m_states [m_currentState]->state().toLatin1().data();
156 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
158 m_states [backgroundState]->setPixmap (transformation,
169 const QString &curveSelected)
171 LOG4CPP_INFO_S ((*mainCat)) <<
"BackgroundStateContext::updateColorFilter";
173 for (
int backgroundState = 0; backgroundState < NUM_BACKGROUND_STATES; backgroundState++) {
175 m_states [backgroundState]->updateColorFilter (transformation,
void setPixmap(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.
void updateColorFilter(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter, const QString &curveSelected)
Apply color filter settings.
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 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.
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.
QImage imageForCurveState() const
Image for the Curve state, even if the current state is different.
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...