Engauge Digitizer  2
BackgroundStateCurve.cpp
1 #include "BackgroundStateContext.h"
2 #include "BackgroundStateCurve.h"
3 #include "DocumentModelColorFilter.h"
4 #include "DocumentModelGridRemoval.h"
5 #include "FilterImage.h"
6 #include "GraphicsScene.h"
7 #include "GraphicsView.h"
8 #include "Logger.h"
9 #include <QPixmap>
10 #include "Transformation.h"
11 
13  GraphicsScene &scene) :
15  scene)
16 {
17 }
18 
20 {
21  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::begin";
22 
23  setImageVisible (true);
24 }
25 
27 {
28  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::end";
29 
30  setImageVisible (false);
31 }
32 
34 {
35  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::fitInView";
36 
37  view.fitInView (imageItem ().boundingRect());
38 }
39 
40 void BackgroundStateCurve::processImageFromSavedInputs (const Transformation &transformation,
41  const DocumentModelGridRemoval &modelGridRemoval,
42  const DocumentModelColorFilter &modelColorFilter)
43 {
44  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::processImageFromSavedInputs";
45 
46  // Use the settings if the selected curve is known
47  if (!m_curveSelected.isEmpty()) {
48 
49  // Generate filtered image
50  FilterImage filterImage;
51  QPixmap pixmapFiltered = filterImage.filter (m_pixmapOriginal.toImage(),
52  transformation,
53  m_curveSelected,
54  modelColorFilter,
55  modelGridRemoval);
56 
57  setProcessedPixmap (pixmapFiltered);
58 
59  } else {
60 
61  // Set the image in case BackgroundStateContext::fitInView is called, so the bounding rect is available
62  setProcessedPixmap (m_pixmapOriginal);
63 
64  }
65 }
66 
68  const DocumentModelGridRemoval &modelGridRemoval,
69  const DocumentModelColorFilter &modelColorFilter,
70  const QString &curveSelected)
71 {
72  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::setCurveSelected"
73  << " curve=" << curveSelected.toLatin1().data();
74 
75  // Even if m_curveSelected equals curveSelected we update the image, since the transformation
76  // may have changed
77  m_curveSelected = curveSelected;
78  processImageFromSavedInputs (transformation,
79  modelGridRemoval,
80  modelColorFilter);
81 }
82 
83 void BackgroundStateCurve::setPixmap (const Transformation &transformation,
84  const DocumentModelGridRemoval &modelGridRemoval,
85  const DocumentModelColorFilter &modelColorFilter,
86  const QPixmap &pixmapOriginal)
87 {
88  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::setPixmap";
89 
90  m_pixmapOriginal = pixmapOriginal;
91  processImageFromSavedInputs (transformation,
92  modelGridRemoval,
93  modelColorFilter);
94 }
95 
97 {
98  return "BackgroundStateCurve";
99 }
100 
102  const DocumentModelGridRemoval &modelGridRemoval,
103  const DocumentModelColorFilter &modelColorFilter)
104 {
105  LOG4CPP_INFO_S ((*mainCat)) << "BackgroundStateCurve::updateColorFilter";
106 
107  processImageFromSavedInputs (transformation,
108  modelGridRemoval,
109  modelColorFilter);
110 }
QGraphicsPixmapItem & imageItem() const
Graphics image item for the current state.
virtual void begin()
Method that is called at the exact moment a state is entered. Typically called just after end for the...
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 QString state() const
State name for debugging.
BackgroundStateCurve(BackgroundStateContext &context, GraphicsScene &scene)
Single constructor.
Affine transformation between screen and graph coordinates, based on digitized axis points...
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:13
virtual void setCurveSelected(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter, const QString &curveSelected)
Update the currently selected curve name.
QPixmap filter(const QImage &imageUnfiltered, const Transformation &transformation, const QString &curveSelected, const DocumentModelColorFilter &modelColorFilter, const DocumentModelGridRemoval &modelGridRemoval) const
Filter original unfiltered image into filtered pixmap.
Definition: FilterImage.cpp:15
Background image state machine state base class.
virtual void fitInView(GraphicsView &view)
Zoom so background fills the window.
Filters an image using a combination of color filtering and grid removal.
Definition: FilterImage.h:12
virtual void setPixmap(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &modelColorFilter, const QPixmap &pixmapOriginal)
Update the image for this state, after the leaf class processes it appropriately. ...
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual void updateColorFilter(const Transformation &transformation, const DocumentModelGridRemoval &modelGridRemoval, const DocumentModelColorFilter &colorFilter)
Apply color filter settings.
Add point and line handling to generic QGraphicsScene.
Definition: GraphicsScene.h:25
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...