7#include "ColorConstants.h"
8#include "ColorFilter.h"
9#include "ColorFilterSettings.h"
10#include "EngaugeAssert.h"
14#include "ViewSegmentFilter.h"
16const QColor COLOR_FOR_BRUSH_DISABLED (Qt::gray);
20 m_filterIsDefined (false),
21 m_rgbBackground (QColor (Qt::white)),
27QColor ViewSegmentFilter::colorFromSetting (ColorFilterMode coloFilterMode,
34 int r = 0, g = 0, b = 0;
36 switch (coloFilterMode)
38 case COLOR_FILTER_MODE_FOREGROUND:
40 double s = (double) (foreground - FOREGROUND_MIN) / (double) (FOREGROUND_MAX - FOREGROUND_MIN);
41 if (qGray (m_rgbBackground.rgb ()) < 127) {
55 case COLOR_FILTER_MODE_HUE:
59 int HUE_THRESHOLD_LOW = 0.666 * HUE_MIN + 0.333 * HUE_MAX;
60 int HUE_THRESHOLD_HIGH = 0.333 * HUE_MIN + 0.666 * HUE_MAX;
62 if (hue < HUE_THRESHOLD_LOW) {
64 double s = (double) (hue - HUE_MIN) / (double) (HUE_THRESHOLD_LOW - HUE_MIN);
67 }
else if (hue < HUE_THRESHOLD_HIGH) {
69 double s = (double) (hue - HUE_THRESHOLD_LOW) / (double) (HUE_THRESHOLD_HIGH - HUE_THRESHOLD_LOW);
74 double s = (double) (hue - HUE_THRESHOLD_HIGH) / (double) (HUE_MAX - HUE_THRESHOLD_HIGH);
81 case COLOR_FILTER_MODE_INTENSITY:
85 double s = (double) (intensity - INTENSITY_MIN) / (double) (INTENSITY_MAX - INTENSITY_MIN);
92 case COLOR_FILTER_MODE_SATURATION:
96 double s = (double) (saturation - SATURATION_MIN) / (double) (SATURATION_MAX - SATURATION_MIN);
103 case COLOR_FILTER_MODE_VALUE:
107 double s = (double) (value - VALUE_MIN) / (double) (VALUE_MAX - VALUE_MIN);
115 ENGAUGE_ASSERT (
false);
121 int rgbAverage = (r + g + b) / 3;
127 return QColor (r, g, b);
130QColor ViewSegmentFilter::colorHigh ()
const
135 m_colorFilterSettings.
hueHigh (),
140 return QColor (COLOR_FOR_BRUSH_DISABLED);
144QColor ViewSegmentFilter::colorLow ()
const
149 m_colorFilterSettings.
hueLow (),
154 return QColor (COLOR_FOR_BRUSH_DISABLED);
160 QPainter painter(
this);
162 if (m_filterIsDefined) {
165 QLinearGradient gradient (0, height()/2, width(), height()/2);
168 gradient.setColorAt (0.0, colorLow ());
169 gradient.setColorAt (1.0, colorHigh ());
170 painter.setBrush (gradient);
173 painter.setPen (Qt::NoPen);
175 painter.drawRect (0, 0, width(), height());
179 painter.fillRect (0, 0, width (), height (), QBrush (COLOR_FOR_BRUSH_DISABLED));
185 const QPixmap &pixmap)
187 LOG4CPP_INFO_S ((*mainCat)) <<
"ViewSegmentFilter::setColorFilterSettings";
189 m_colorFilterSettings = colorFilterSettings;
190 m_filterIsDefined =
true;
194 QImage img = pixmap.toImage();
203 LOG4CPP_INFO_S ((*mainCat)) <<
"ViewSegmentFilter::setEnabled"
204 <<
" enabled=" << (enabled ?
"true" :
"false");
214 m_filterIsDefined =
false;
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
int foregroundLow() const
Get method for foreground lower bound.
int saturationLow() const
Get method for saturation lower bound.
int intensityHigh() const
Get method for intensity higher bound.
int saturationHigh() const
Get method for saturation higher bound.
ColorFilterMode colorFilterMode() const
Get method for filter mode.
int valueLow() const
Get method for value low.
int hueHigh() const
Get method for hue higher bound.
int foregroundHigh() const
Get method for foreground higher bound.
int intensityLow() const
Get method for intensity lower bound.
int hueLow() const
Get method for hue lower bound.
int valueHigh() const
Get method for value high.
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...
void unsetColorFilterSettings()
Apply no color filter.
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings, const QPixmap &pixmap)
Apply the color filter of the currently selected curve. The pixmap is included so the background colo...
void setEnabled(bool enabled)
Show the style with semi-transparency or full-transparency to indicate if associated Curve is active ...
virtual void paintEvent(QPaintEvent *event)
Paint with a horizontal linear gradient.
ViewSegmentFilter(QWidget *parent=0)
Single constructor.