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;
58 bool DigitizeStateColorPicker::computeFilterFromPixel (
CmdMediator *cmdMediator,
59 const QPointF &posScreen,
60 const QString &curveName,
63 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::computeFilterFromPixel";
73 QPointF posScreenPlusHalf = posScreen - QPointF (0.5, 0.5);
76 rtn = findNearestNonBackgroundPixel (cmdMediator,
85 int r = qRed (pixel.rgb());
86 int g = qGreen (pixel.rgb());
87 int b = qBlue (pixel.rgb());
88 if (r == g && g == b) {
92 COLOR_FILTER_MODE_INTENSITY);
98 COLOR_FILTER_MODE_HUE);
121 int lowerBin = pixelBin, upperBin = pixelBin;
122 while ((lowerBin > 0) &&
123 (histogramBins [lowerBin - 1] <= histogramBins [lowerBin]) &&
124 (histogramBins [lowerBin] > 0)) {
128 (histogramBins [upperBin + 1] <= histogramBins [upperBin]) &&
129 (histogramBins [upperBin] > 0)) {
141 saveLowerValueUpperValue (modelColorFilterAfter,
146 delete [] histogramBins;
150 QMessageBox::warning (0,
151 QObject::tr (
"Color Picker"),
152 QObject::tr (
"Sorry, but the color picker point must be near a non-background pixel. Please try again."));
162 const int HOT_X_IN_BITMAP = 8;
163 const int HOT_Y_IN_BITMAP = 24;
164 LOG4CPP_DEBUG_S ((*mainCat)) <<
"DigitizeStateColorPicker::cursor";
166 QBitmap bitmap (
":/engauge/img/cursor_eyedropper.xpm");
167 QBitmap bitmapMask (
":/engauge/img/cursor_eyedropper_mask.xpm");
168 return QCursor (bitmap,
176 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::end";
183 bool DigitizeStateColorPicker::findNearestNonBackgroundPixel (
CmdMediator *cmdMediator,
185 const QPointF &posScreenPlusHalf,
186 const QRgb &rgbBackground,
189 QPoint pos = posScreenPlusHalf.toPoint ();
194 for (
int radius = 0; radius < maxRadiusForSearch; radius++) {
196 for (
int xOffset = -radius; xOffset <= radius; xOffset++) {
197 for (
int yOffset = -radius; yOffset <= radius; yOffset++) {
200 pixel = image.pixel (pos.x () + xOffset, pos.y () - radius);
201 if (pixel != rgbBackground) {
206 pixel = image.pixel (pos.x () + xOffset, pos.y () + radius);
207 if (pixel != rgbBackground) {
212 pixel = image.pixel (pos.x () - radius, pos.y () - yOffset);
213 if (pixel != rgbBackground) {
218 pixel = image.pixel (pos.x () + radius, pos.y () + yOffset);
219 if (pixel != rgbBackground) {
230 const QString &pointIdentifier)
232 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleContextMenuEventAxis " 233 <<
" point=" << pointIdentifier.toLatin1 ().data ();
237 const QStringList &pointIdentifiers)
239 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker ::handleContextMenuEventGraph " 240 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
245 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleCurveChange";
252 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleKeyPress" 253 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
265 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleMousePress";
271 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleMouseRelease";
275 if (computeFilterFromPixel (cmdMediator,
277 context().mainWindow().selectedGraphCurve(),
278 modelColorFilterAfter)) {
286 modelColorFilterBefore,
287 modelColorFilterAfter);
294 const QString &curveName,
299 case COLOR_FILTER_MODE_FOREGROUND:
306 case COLOR_FILTER_MODE_HUE:
307 modelColorFilterAfter.
setHueLow(curveName,
313 case COLOR_FILTER_MODE_INTENSITY:
320 case COLOR_FILTER_MODE_SATURATION:
327 case COLOR_FILTER_MODE_VALUE:
335 ENGAUGE_ASSERT (
false);
341 return "DigitizeStateColorPicker";
346 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::updateAfterPointAddition";
352 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::updateModelDigitizeCurve";
357 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::updateModelSegments";
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity...
void requestDelayedStateTransition(DigitizeState digitizeState)
Initiate state transition to be performed later, when DigitizeState is off the stack.
virtual QString activeCurve() const
Name of the active Curve. This can include AXIS_CURVE_NAME.
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.
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.
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...
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
DigitizeStateColorPicker(DigitizeStateContext &context)
Single constructor.
virtual bool canPaste(const Transformation &transformation, const QSize &viewSize) const
Return true if there is good data in the clipboard for pasting, and that is compatible with the curre...
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
Class for filtering image to remove unimportant information.
ColorFilterMode colorFilterMode(const QString &curveName) const
Get method for filter mode.
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...
void generate(const ColorFilter &filter, double histogramBins [], ColorFilterMode colorFilterMode, const QImage &image, int &maxBinCount) const
Generate the histogram.
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.
int binFromPixel(const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
Compute histogram bin number from pixel according to filter.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
int cursorSize() const
Get method for effective cursor size.
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...
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
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 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.
virtual QString state() const
State name for debugging.
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.
QPixmap pixmap() const
Return the image that is being digitized.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
Class that generates a histogram according to the current filter.
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
static int HISTOGRAM_BINS()
Number of histogram bins.