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>
28DigitizeStateColorPicker::~DigitizeStateColorPicker ()
38 DigitizeState previousState)
40 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::begin";
46 m_previousDigitizeState = previousState;
52bool 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";
177bool 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";
Command for DlgSettingsColorFilter.
Class that generates a histogram according to the current filter.
void generate(const ColorFilter &filter, double histogramBins[], ColorFilterMode colorFilterMode, const QImage &image, int &maxBinCount) const
Generate the histogram.
int valueFromBin(const ColorFilter &filter, ColorFilterMode colorFilterMode, int bin)
Inverse of binFromPixel.
static int HISTOGRAM_BINS()
Number of histogram bins.
int binFromPixel(const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
Compute histogram bin number from pixel according to filter.
Class for filtering image to remove unimportant information.
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...
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses,...
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
virtual void end()
Method that is called at the exact moment a state is exited. Typically called just before begin for t...
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
virtual QString state() const
State name for debugging.
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...
DigitizeStateColorPicker(DigitizeStateContext &context)
Single constructor.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
void appendNewCmd(CmdMediator *cmdMediator, QUndoCommand *cmd)
Append just-created QUndoCommand to command stack. This is called from DigitizeStateAbstractBase subc...
void requestDelayedStateTransition(DigitizeState digitizeState)
Initiate state transition to be performed later, when DigitizeState is off the stack.
MainWindow & mainWindow()
Reference to the MainWindow, without const.
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
void setValueHigh(const QString &curveName, int valueHigh)
Set method for value high.
ColorFilterMode colorFilterMode(const QString &curveName) const
Get method for filter mode.
void setIntensityLow(const QString &curveName, int intensityLow)
Set method for intensity lower bound.
void setHueHigh(const QString &curveName, int hueHigh)
Set method for hue higher bound.
void setForegroundHigh(const QString &curveName, int foregroundHigh)
Set method for foreground higher bound.
void setSaturationHigh(const QString &curveName, int saturationHigh)
Set method for saturation high.
void setHueLow(const QString &curveName, int hueLow)
Set method for hue lower bound.
void setValueLow(const QString &curveName, int valueLow)
Set method for value low.
void setSaturationLow(const QString &curveName, int saturationLow)
Set method for saturation low.
void setColorFilterMode(const QString &curveName, ColorFilterMode colorFilterMode)
Set method for filter mode.
void setIntensityHigh(const QString &curveName, int intensityHigh)
Set method for intensity higher bound.
void setForegroundLow(const QString &curveName, int foregroundLow)
Set method for foreground lower bound.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
int cursorSize() const
Get method for effective cursor size.
Model for DlgSettingsSegments and CmdSettingsSegments.
QPixmap pixmap() const
Return the image that is being digitized.
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
BackgroundImage selectOriginal(BackgroundImage backgroundImage)
Make original background visible, for DigitizeStateColorPicker.
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.