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) {
224 const QString &pointIdentifier)
226 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleContextMenuEventAxis " 227 <<
" point=" << pointIdentifier.toLatin1 ().data ();
231 const QStringList &pointIdentifiers)
233 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker ::handleContextMenuEventGraph " 234 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
239 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleCurveChange";
246 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleKeyPress" 247 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
259 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleMousePress";
265 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::handleMouseRelease";
269 if (computeFilterFromPixel (cmdMediator,
271 context().mainWindow().selectedGraphCurve(),
272 modelColorFilterAfter)) {
280 modelColorFilterBefore,
281 modelColorFilterAfter);
288 const QString &curveName,
293 case COLOR_FILTER_MODE_FOREGROUND:
300 case COLOR_FILTER_MODE_HUE:
301 modelColorFilterAfter.
setHueLow(curveName,
307 case COLOR_FILTER_MODE_INTENSITY:
314 case COLOR_FILTER_MODE_SATURATION:
321 case COLOR_FILTER_MODE_VALUE:
329 ENGAUGE_ASSERT (
false);
335 return "DigitizeStateColorPicker";
340 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::updateAfterPointAddition";
346 LOG4CPP_INFO_S ((*mainCat)) <<
"DigitizeStateColorPicker::updateModelDigitizeCurve";
351 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 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.