Engauge Digitizer  2
BackgroundStateAbstractBase.h
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 #ifndef BACKGROUND_STATE_ABSTRACT_BASE_H
8 #define BACKGROUND_STATE_ABSTRACT_BASE_H
9 
10 #include <QGraphicsPixmapItem>
11 #include <QImage>
12 
14 enum BackgroundState {
15  BACKGROUND_STATE_CURVE,
16  BACKGROUND_STATE_NONE,
17  BACKGROUND_STATE_ORIGINAL,
18  BACKGROUND_STATE_UNLOADED,
19  NUM_BACKGROUND_STATES
20 };
21 
25 class GraphicsScene;
26 class GraphicsView;
27 class Transformation;
28 
31 {
32  public:
37 
39  virtual void begin() = 0;
40 
43 
45  const BackgroundStateContext &context() const;
46 
48  virtual void end() = 0;
49 
51  virtual void fitInView (GraphicsView &view) = 0;
52 
54  QImage image () const;
55 
57  QGraphicsPixmapItem &imageItem () const;
58 
61 
63  const GraphicsScene &scene() const;
64 
66  virtual void setCurveSelected (const Transformation &transformation,
67  const DocumentModelGridRemoval &modelGridRemoval,
68  const DocumentModelColorFilter &colorFilter,
69  const QString &curveSelected) = 0;
70 
72  virtual void setPixmap (const Transformation &transformation,
73  const DocumentModelGridRemoval &modelGridRemoval,
74  const DocumentModelColorFilter &modelColorFilter,
75  const QPixmap &pixmap,
76  const QString &curveSelected) = 0;
77 
79  virtual QString state() const = 0;
80 
82  virtual void updateColorFilter (const Transformation &transformation,
83  const DocumentModelGridRemoval &modelGridRemoval,
84  const DocumentModelColorFilter &modelColorFilter,
85  const QString &curveSelected) = 0;
86 
87  protected:
88 
90  void setImageVisible (bool visible);
91 
93  void setProcessedPixmap (const QPixmap &pixmap);
94 
95  private:
97 
98  BackgroundStateContext &m_context;
99  GraphicsScene &m_scene;
100 
101  // Each state has its own image, although only one is shown at a time. This is null if an image has not been defined yet,
102  // so we can eliminate a dependency on the ordering of the state transitions and the update of the image by setPixmap
103  QGraphicsPixmapItem *m_imageItem;
104 
105  QImage m_image; // Original image. This is stored in addition to m_imageItem since m_imageItem cannot be used when invisible
106 };
107 
108 #endif // BACKGROUND_STATE_ABSTRACT_BASE_H
void setImageVisible(bool visible)
Show/hide background image.
void setProcessedPixmap(const QPixmap &pixmap)
Save the image for this state after it has been processed by the leaf class.
virtual void fitInView(GraphicsView &view)=0
Zoom so background fills the window.
BackgroundStateContext & context()
Reference to the BackgroundStateContext that contains all the BackgroundStateAbstractBase subclasses...
QGraphicsPixmapItem & imageItem() const
Graphics image item for the current state.
virtual void begin()=0
Method that is called at the exact moment a state is entered. Typically called just after end for the...
Affine transformation between screen and graph coordinates, based on digitized axis points...
virtual void end()=0
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
Context class that manages the background image state machine.
QGraphicsView class with event handling added. Typically the events are sent to the active digitizing...
Definition: GraphicsView.h:20
virtual void setPixmap(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QPixmap &pixmap, const QString &curveSelected)=0
Update the image for this state, after the leaf class processes it appropriately. ...
Background image state machine state base class.
QImage image() const
Image for the current state.
virtual QString state() const =0
State name for debugging.
virtual void setCurveSelected(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter, const QString &curveSelected)=0
Update the currently selected curve name.
virtual void updateColorFilter(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QString &curveSelected)=0
Apply color filter settings.
Add point and line handling to generic QGraphicsScene.
Definition: GraphicsScene.h:33
GraphicsScene & scene()
Reference to the GraphicsScene, without const.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...