Go to the documentation of this file.
18 #include <QGraphicsPixmapItem>
19 #include <QGraphicsScene>
22 #include <QMessageBox>
47 m_previousDigitizeState = previousState;
59 bool DigitizeStateColorPicker::computeFilterFromPixel (
CmdMediator *cmdMediator,
60 const QPointF &posScreen,
61 const QString &curveName,
74 QPointF posScreenPlusHalf = posScreen - QPointF (0.5, 0.5);
77 rtn = findNearestNonBackgroundPixel (cmdMediator,
86 int r = qRed (pixel.rgb());
87 int g = qGreen (pixel.rgb());
88 int b = qBlue (pixel.rgb());
89 if (r == g && g == b) {
122 int lowerBin = pixelBin, upperBin = pixelBin;
123 while ((lowerBin > 0) &&
124 (histogramBins [lowerBin - 1] <= histogramBins [lowerBin]) &&
125 (histogramBins [lowerBin] > 0)) {
129 (histogramBins [upperBin + 1] <= histogramBins [upperBin]) &&
130 (histogramBins [upperBin] > 0)) {
142 saveLowerValueUpperValue (modelColorFilterAfter,
147 delete [] histogramBins;
151 QMessageBox::warning (
nullptr,
152 QObject::tr (
"Color Picker"),
153 QObject::tr (
"Sorry, but the color picker point must be near a non-background pixel. Please try again."));
163 const int HOT_X_IN_BITMAP = 8;
164 const int HOT_Y_IN_BITMAP = 24;
167 QBitmap bitmap (
":/engauge/img/cursor_eyedropper.xpm");
168 QBitmap bitmapMask (
":/engauge/img/cursor_eyedropper_mask.xpm");
169 return QCursor (bitmap,
184 bool DigitizeStateColorPicker::findNearestNonBackgroundPixel (
CmdMediator *cmdMediator,
186 const QPointF &posScreenPlusHalf,
187 const QRgb &rgbBackground,
190 QPoint pos = posScreenPlusHalf.toPoint ();
195 for (
int radius = 0; radius < maxRadiusForSearch; radius++) {
197 for (
int xOffset = -radius; xOffset <= radius; xOffset++) {
198 for (
int yOffset = -radius; yOffset <= radius; yOffset++) {
201 pixel = image.pixel (pos.x () + xOffset, pos.y () - radius);
202 if (pixel != rgbBackground) {
207 pixel = image.pixel (pos.x () + xOffset, pos.y () + radius);
208 if (pixel != rgbBackground) {
213 pixel = image.pixel (pos.x () - radius, pos.y () - yOffset);
214 if (pixel != rgbBackground) {
219 pixel = image.pixel (pos.x () + radius, pos.y () + yOffset);
220 if (pixel != rgbBackground) {
231 const QString &pointIdentifier)
234 <<
" point=" << pointIdentifier.toLatin1 ().data ();
238 const QStringList &pointIdentifiers)
241 <<
"points=" << pointIdentifiers.join(
",").toLatin1 ().data ();
254 <<
" key=" << QKeySequence (key).toString ().toLatin1 ().data ();
276 if (computeFilterFromPixel (cmdMediator,
278 context().mainWindow().selectedGraphCurve(),
279 modelColorFilterAfter)) {
287 modelColorFilterBefore,
288 modelColorFilterAfter);
295 const QString &curveName,
299 int lowerValue = qFloor (lowerValueIn);
300 int upperValue = qFloor (upperValueIn);
311 modelColorFilterAfter.
setHueLow(curveName,
345 return "DigitizeStateColorPicker";
QPixmap pixmap() const
Return the image that is being digitized.
void setForegroundHigh(const QString &curveName, int foregroundHigh)
Set method for foreground higher bound.
static int HISTOGRAM_BINS()
Number of histogram bins.
void setDragMode(QGraphicsView::DragMode dragMode)
Set QGraphicsView drag mode (in m_view). Called from DigitizeStateAbstractBase subclasses.
Container for all DigitizeStateAbstractBase subclasses. This functions as the context class in a stan...
DigitizeStateColorPicker(DigitizeStateContext &context)
Single constructor.
DigitizeStateContext & context()
Reference to the DigitizeStateContext that contains all the DigitizeStateAbstractBase subclasses,...
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
virtual void handleKeyPress(CmdMediator *cmdMediator, Qt::Key key, bool atLeastOneSelectedItem)
Handle a key press that was intercepted earlier.
DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
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 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.
void setSaturationHigh(const QString &curveName, int saturationHigh)
Set method for saturation high.
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...
void generate(const ColorFilter &filter, double histogramBins[], ColorFilterMode colorFilterMode, const QImage &image, int &maxBinCount) const
Generate the histogram.
virtual void updateModelDigitizeCurve(CmdMediator *cmdMediator, const DocumentModelDigitizeCurve &modelDigitizeCurve)
Update the digitize curve settings.
MainWindow & mainWindow()
Reference to the MainWindow, without const.
QString selectedGraphCurve() const
Curve name that is currently selected in m_cmbCurve.
virtual void handleMouseRelease(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse release that was intercepted earlier.
virtual void handleCurveChange(CmdMediator *cmdMediator)
Handle the selection of a new curve. At a minimum, DigitizeStateSegment will generate a new set of Se...
int cursorSize() const
Get method for effective cursor size.
virtual void handleContextMenuEventAxis(CmdMediator *cmdMediator, const QString &pointIdentifier)
Handle a right click, on an axis point, that was intercepted earlier.
Class that generates a histogram according to the current filter.
int binFromPixel(const ColorFilter &filter, ColorFilterMode colorFilterMode, const QColor &pixel, const QRgb &rgbBackground) const
Compute histogram bin number from pixel according to filter.
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
virtual QString state() const
State name for debugging.
Command for DlgSettingsColorFilter.
virtual ~DigitizeStateColorPicker()
Class for filtering image to remove unimportant information.
virtual void begin(CmdMediator *cmdMediator, DigitizeState previousState)
Method that is called at the exact moment a state is entered.
virtual void handleContextMenuEventGraph(CmdMediator *cmdMediator, const QStringList &pointIdentifiers)
Handle a right click, on a graph point, that was intercepted earlier.
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...
virtual QCursor cursor(CmdMediator *cmdMediator) const
Returns the state-specific cursor shape.
void setSaturationLow(const QString &curveName, int saturationLow)
Set method for saturation low.
void setHueHigh(const QString &curveName, int hueHigh)
Set method for hue higher bound.
DigitizeState
Set of possible states of Digitize toolbar.
virtual void updateAfterPointAddition()
Update graphics attributes after possible new points. This is useful for highlight opacity.
#define LOG4CPP_INFO_S(logger)
virtual void handleMousePress(CmdMediator *cmdMediator, QPointF posScreen)
Handle a mouse press that was intercepted earlier.
Model for DlgSettingsSegments and CmdSettingsSegments.
void setIntensityLow(const QString &curveName, int intensityLow)
Set method for intensity lower bound.
void setCursor(CmdMediator *cmdMediator)
Update the cursor according to the current state.
void setColorFilterMode(const QString &curveName, ColorFilterMode colorFilterMode)
Set method for filter mode.
void setValueHigh(const QString &curveName, int valueHigh)
Set method for value high.
log4cpp::Category * mainCat
BackgroundImage selectOriginal(BackgroundImage backgroundImage)
Make original background visible, for DigitizeStateColorPicker.
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
void setValueLow(const QString &curveName, int valueLow)
Set method for value low.
void setHueLow(const QString &curveName, int hueLow)
Set method for hue lower bound.
void requestDelayedStateTransition(DigitizeState digitizeState)
Initiate state transition to be performed later, when DigitizeState is off the stack.
#define LOG4CPP_DEBUG_S(logger)
void setForegroundLow(const QString &curveName, int foregroundLow)
Set method for foreground lower bound.
ColorFilterMode colorFilterMode(const QString &curveName) const
Get method for filter mode.
virtual void updateModelSegments(const DocumentModelSegments &modelSegments)
Update the segments given the new settings.
int valueFromBin(const ColorFilter &filter, ColorFilterMode colorFilterMode, int bin)
Inverse of binFromPixel.
Base class for all digitizing states. This serves as an interface to DigitizeStateContext.
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
void setIntensityHigh(const QString &curveName, int intensityHigh)
Set method for intensity higher bound.
void updateViewsOfSettings(const QString &activeCurve)
Update curve-specific view of settings. Private version gets active curve name from DigitizeStateCont...