7 #include "CmdMediator.h"
8 #include "CmdSettingsColorFilter.h"
9 #include "ColorFilter.h"
10 #include "ColorFilterHistogram.h"
11 #include "DigitizeStateContext.h"
12 #include "DigitizeStateColorPicker.h"
13 #include "DocumentModelColorFilter.h"
14 #include "EngaugeAssert.h"
16 #include "MainWindow.h"
18 #include <QGraphicsPixmapItem>
19 #include <QGraphicsScene>
21 #include <QMessageBox>
28 DigitizeStateColorPicker::~DigitizeStateColorPicker ()
38 DigitizeState previousState)
40 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::begin";
46 m_previousDigitizeState = previousState;
52 bool DigitizeStateColorPicker::computeFilterFromPixel (
CmdMediator *cmdMediator,
53 const QPointF &posScreen,
54 const QString &curveName,
57 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::computeFilterFromPixel";
67 QPointF posScreenPlusHalf = posScreen - QPointF (0.5, 0.5);
70 rtn = findNearestNonBackgroundPixel (cmdMediator,
79 int r = qRed (pixel.rgb());
80 int g = qGreen (pixel.rgb());
81 int b = qBlue (pixel.rgb());
82 if (r == g && g == b) {
86 COLOR_FILTER_MODE_INTENSITY);
92 COLOR_FILTER_MODE_HUE);
115 int lowerBin = pixelBin, upperBin = pixelBin;
116 while ((lowerBin > 0) &&
117 (histogramBins [lowerBin - 1] <= histogramBins [lowerBin]) &&
118 (histogramBins [lowerBin] > 0)) {
122 (histogramBins [upperBin + 1] <= histogramBins [upperBin]) &&
123 (histogramBins [upperBin] > 0)) {
135 saveLowerValueUpperValue (modelColorFilterAfter,
140 delete histogramBins;
144 QMessageBox::warning (0,
145 QObject::tr (
"Color Picker"),
146 QObject::tr (
"Sorry, but the color picker point must be near a non-background pixel. Please try again."));
156 const int HOT_X_IN_BITMAP = 8;
157 const int HOT_Y_IN_BITMAP = 24;
158 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateColorPicker::cursor";
160 QBitmap bitmap (
":/engauge/img/cursor_eyedropper.xpm");
161 QBitmap bitmapMask (
":/engauge/img/cursor_eyedropper_mask.xpm");
162 return QCursor (bitmap,
170 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::end";
177 bool DigitizeStateColorPicker::findNearestNonBackgroundPixel (
CmdMediator *cmdMediator,
179 const QPointF &posScreenPlusHalf,
180 const QRgb &rgbBackground,
183 QPoint pos = posScreenPlusHalf.toPoint ();
188 for (
int radius = 0; radius < maxRadiusForSearch; radius++) {
190 for (
int xOffset = -radius; xOffset <= radius; xOffset++) {
191 for (
int yOffset = -radius; yOffset <= radius; yOffset++) {
194 pixel = image.pixel (pos.x () + xOffset, pos.y () - radius);
195 if (pixel != rgbBackground) {
200 pixel = image.pixel (pos.x () + xOffset, pos.y () + radius);
201 if (pixel != rgbBackground) {
206 pixel = image.pixel (pos.x () - radius, pos.y () - yOffset);
207 if (pixel != rgbBackground) {
212 pixel = image.pixel (pos.x () + radius, pos.y () + yOffset);
213 if (pixel != rgbBackground) {
225 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleCurveChange";
232 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleKeyPress"
233 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
245 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleMousePress";
251 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleMouseRelease";
255 if (computeFilterFromPixel (cmdMediator,
257 context().mainWindow().selectedGraphCurve(),
258 modelColorFilterAfter)) {
266 modelColorFilterBefore,
267 modelColorFilterAfter);
274 const QString &curveName,
279 case COLOR_FILTER_MODE_FOREGROUND:
286 case COLOR_FILTER_MODE_HUE:
287 modelColorFilterAfter.
setHueLow(curveName,
293 case COLOR_FILTER_MODE_INTENSITY:
300 case COLOR_FILTER_MODE_SATURATION:
307 case COLOR_FILTER_MODE_VALUE:
315 ENGAUGE_ASSERT (
false);
321 return "DigitizeStateColorPicker";
327 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::updateModelDigitizeCurve";
332 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::updateModelSegments";
void requestDelayedStateTransition(DigitizeState digitizeState)
Initiate state transition to be performed later, when DigitizeState is off the stack.
void generate(const ColorFilter &filter, double histogramBins[], ColorFilterMode colorFilterMode, const QImage &image, int &maxBinCount) const
Generate the histogram.
virtual void handleMouseMove(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse move. This is part of an experiment to see if augmenting the cursor in Point Match mod...
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
void setColorFilterMode(const QString &curveName, ColorFilterMode colorFilterMode)
Set method for filter mode.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
DigitizeStateColorPicker(DigitizeStateContext &context)
Single constructor.
virtual QString state() const
State name for debugging.
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
int cursorSize() const
Get method for effective cursor size.
QPixmap pixmap() const
Return the image that is being digitized.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
Class for filtering image to remove unimportant information.
BackgroundImage selectOriginal(BackgroundImage backgroundImage)
Make original background visible, for DigitizeStateColorPicker.
void setValueLow(const QString &curveName, int valueLow)
Set method for value low.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses...
MainWindow & mainWindow()
Reference to the MainWindow, without const.
void setForegroundLow(const QString &curveName, int foregroundLow)
Set method for foreground lower bound.
void setHueLow(const QString &curveName, int hueLow)
Set method for hue lower bound.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
void setIntensityLow(const QString &curveName, int intensityLow)
Set method for intensity lower bound.
void setForegroundHigh(const QString &curveName, int foregroundHigh)
Set method for foreground higher bound.
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
void setIntensityHigh(const QString &curveName, int intensityHigh)
Set method for intensity higher bound.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
QRgb marginColor(const QImage *image) const
Identify the margin color of the image, which is defined as the most common color in the four margins...
int binFromPixel(const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
Compute histogram bin number from pixel according to filter.
ColorFilterMode colorFilterMode(const QString &curveName) const
Get method for filter mode.
Command for DlgSettingsColorFilter.
void setSaturationLow(const QString &curveName, int saturationLow)
Set method for saturation low.
int valueFromBin(const ColorFilter &filter, ColorFilterMode colorFilterMode, int bin)
Inverse of binFromPixel.
void setSaturationHigh(const QString &curveName, int saturationHigh)
Set method for saturation high.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
void setHueHigh(const QString &curveName, int hueHigh)
Set method for hue higher bound.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
Model for DlgSettingsSegments and CmdSettingsSegments.
void setValueHigh(const QString &curveName, int valueHigh)
Set method for value high.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
Class that generates a histogram according to the current filter.
static int HISTOGRAM_BINS()
Number of histogram bins.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.