18#include <QGraphicsPixmapItem>
19#include <QGraphicsScene>
47 m_previousDigitizeState = previousState;
60bool DigitizeStateColorPicker::computeFilterFromPixel (
CmdMediator *cmdMediator,
61 const QPointF &posScreen,
62 const QString &curveName,
75 QPointF posScreenPlusHalf = posScreen - QPointF (0.5, 0.5);
78 rtn = findNearestNonBackgroundPixel (cmdMediator,
87 int r = qRed (pixel.rgb());
88 int g = qGreen (pixel.rgb());
89 int b = qBlue (pixel.rgb());
90 if (r == g && g == b) {
107 ColorFilterHistogram filterHistogram;
123 int lowerBin = pixelBin, upperBin = pixelBin;
124 while ((lowerBin > 0) &&
125 (histogramBins [lowerBin - 1] <= histogramBins [lowerBin]) &&
126 (histogramBins [lowerBin] > 0)) {
130 (histogramBins [upperBin + 1] <= histogramBins [upperBin]) &&
131 (histogramBins [upperBin] > 0)) {
143 saveLowerValueUpperValue (modelColorFilterAfter,
148 delete [] histogramBins;
152 QMessageBox::warning (
nullptr,
153 QObject::tr (
"Color Picker"),
154 QObject::tr (
"Sorry, but the color picker point must be near a non-background pixel. Please try again."));
164 const int HOT_X_IN_BITMAP = 8;
165 const int HOT_Y_IN_BITMAP = 24;
168 QBitmap bitmap (
":/engauge/img/cursor_eyedropper.xpm");
169 QBitmap bitmapMask (
":/engauge/img/cursor_eyedropper_mask.xpm");
170 return QCursor (bitmap,
185bool DigitizeStateColorPicker::findNearestNonBackgroundPixel (
CmdMediator *cmdMediator,
187 const QPointF &posScreenPlusHalf,
188 const QRgb &rgbBackground,
191 QPoint pos = posScreenPlusHalf.toPoint ();
196 for (
int radius = 0; radius < maxRadiusForSearch; radius++) {
198 for (
int xOffset = -radius; xOffset <= radius; xOffset++) {
199 for (
int yOffset = -radius; yOffset <= radius; yOffset++) {
202 pixel = image.pixel (pos.x () + xOffset, pos.y () - radius);
203 if (pixel != rgbBackground) {
208 pixel = image.pixel (pos.x () + xOffset, pos.y () + radius);
209 if (pixel != rgbBackground) {
214 pixel = image.pixel (pos.x () - radius, pos.y () - yOffset);
215 if (pixel != rgbBackground) {
220 pixel = image.pixel (pos.x () + radius, pos.y () + yOffset);
221 if (pixel != rgbBackground) {
237 const QString &pointIdentifier)
240 <<
" point=" << pointIdentifier.toLatin1 ().data ();
244 const QStringList &pointIdentifiers)
247 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
260 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
282 if (computeFilterFromPixel (cmdMediator,
284 context().mainWindow().selectedGraphCurve(),
285 modelColorFilterAfter)) {
293 modelColorFilterBefore,
294 modelColorFilterAfter);
301 const QString &curveName,
305 int lowerValue = qFloor (lowerValueIn);
306 int upperValue = qFloor (upperValueIn);
317 modelColorFilterAfter.
setHueLow(curveName,
345 LOG4CPP_ERROR_S ((*
mainCat)) <<
"DigitizeStateColorPicker::saveLowerValueUpperValue unexpected color filter mode "
353 return "DigitizeStateColorPicker";
@ BACKGROUND_IMAGE_ORIGINAL
@ COLOR_FILTER_MODE_FOREGROUND
@ COLOR_FILTER_MODE_VALUE
@ COLOR_FILTER_MODE_INTENSITY
@ COLOR_FILTER_MODE_SATURATION
DigitizeState
Set of possible states of Digitize toolbar.
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
log4cpp::Category * mainCat
Command for DlgSettingsColorFilter.
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...
DigitizeStateAbstractBase(DigitizeStateContext &context)
Single constructor.
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 handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
virtual bool guidelinesAreSelectable() const
Enable/disable guidelines according to state.
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity.
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 ~DigitizeStateColorPicker()
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 void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, 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...
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...
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...
void handleGuidelinesActiveChange(bool active)
Handle Guidelines active status toggle.
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
#define LOG4CPP_INFO_S(logger)
#define LOG4CPP_DEBUG_S(logger)
#define LOG4CPP_ERROR_S(logger)