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