1 #include "ColorConstants.h"
2 #include "ColorFilter.h"
3 #include "ColorFilterSettings.h"
4 #include "EngaugeAssert.h"
8 #include "ViewSegmentFilter.h"
10 const double OPACITY_WHEN_DISABLED = 0.5;
11 const QColor COLOR_FOR_BRUSH_DISABLED (Qt::gray);
15 m_filterIsDefined (false),
16 m_rgbBackground (QColor (Qt::white)),
22 QColor ViewSegmentFilter::colorFromSetting (ColorFilterMode coloFilterMode,
29 int r = 0, g = 0, b = 0;
31 switch (coloFilterMode)
33 case COLOR_FILTER_MODE_FOREGROUND:
35 double s = (double) (foreground - FOREGROUND_MIN) / (double) (FOREGROUND_MAX - FOREGROUND_MIN);
36 if (qGray (m_rgbBackground.rgb ()) < 127) {
50 case COLOR_FILTER_MODE_HUE:
54 int HUE_THRESHOLD_LOW = 0.666 * HUE_MIN + 0.333 * HUE_MAX;
55 int HUE_THRESHOLD_HIGH = 0.333 * HUE_MIN + 0.666 * HUE_MAX;
57 if (hue < HUE_THRESHOLD_LOW) {
59 double s = (double) (hue - HUE_MIN) / (double) (HUE_THRESHOLD_LOW - HUE_MIN);
62 }
else if (hue < HUE_THRESHOLD_HIGH) {
64 double s = (double) (hue - HUE_THRESHOLD_LOW) / (double) (HUE_THRESHOLD_HIGH - HUE_THRESHOLD_LOW);
69 double s = (double) (hue - HUE_THRESHOLD_HIGH) / (double) (HUE_MAX - HUE_THRESHOLD_HIGH);
76 case COLOR_FILTER_MODE_INTENSITY:
80 double s = (double) (intensity - INTENSITY_MIN) / (double) (INTENSITY_MAX - INTENSITY_MIN);
87 case COLOR_FILTER_MODE_SATURATION:
91 double s = (double) (saturation - SATURATION_MIN) / (double) (SATURATION_MAX - SATURATION_MIN);
98 case COLOR_FILTER_MODE_VALUE:
102 double s = (double) (value - VALUE_MIN) / (double) (VALUE_MAX - VALUE_MIN);
110 ENGAUGE_ASSERT (
false);
116 int rgbAverage = (r + g + b) / 3;
122 return QColor (r, g, b);
125 QColor ViewSegmentFilter::colorHigh ()
const
130 m_colorFilterSettings.
hueHigh (),
135 return QColor (COLOR_FOR_BRUSH_DISABLED);
139 QColor ViewSegmentFilter::colorLow ()
const
144 m_colorFilterSettings.
hueLow (),
149 return QColor (COLOR_FOR_BRUSH_DISABLED);
155 QPainter painter(
this);
157 if (m_filterIsDefined) {
160 QLinearGradient gradient (0, height()/2, width(), height()/2);
163 gradient.setColorAt (0.0, colorLow ());
164 gradient.setColorAt (1.0, colorHigh ());
165 painter.setBrush (gradient);
168 painter.setPen (Qt::NoPen);
170 painter.drawRect (0, 0, width(), height());
174 painter.fillRect (0, 0, width (), height (), QBrush (COLOR_FOR_BRUSH_DISABLED));
180 const QPixmap &pixmap)
182 LOG4CPP_INFO_S ((*mainCat)) <<
"ViewSegmentFilter::setColorFilterSettings";
184 m_colorFilterSettings = colorFilterSettings;
185 m_filterIsDefined =
true;
189 QImage img = pixmap.toImage();
198 LOG4CPP_INFO_S ((*mainCat)) <<
"ViewSegmentFilter::setEnabled"
199 <<
" enabled=" << (enabled ?
"true" :
"false");
209 m_filterIsDefined =
false;
int saturationLow() const
Get method for saturation lower bound.
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...
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
int hueLow() const
Get method for hue lower bound.
int foregroundHigh() const
Get method for foreground higher bound.
void setEnabled(bool enabled)
Show the style with semi-transparency or full-transparency to indicate if associated Curve is active ...
int hueHigh() const
Get method for hue higher bound.
ViewSegmentFilter(QWidget *parent=0)
Single constructor.
int saturationHigh() const
Get method for saturation higher bound.
Class for filtering image to remove unimportant information.
int foregroundLow() const
Get method for foreground lower bound.
ColorFilterMode colorFilterMode() const
Get method for filter mode.
int valueLow() const
Get method for value low.
int intensityHigh() const
Get method for intensity higher bound.
virtual void paintEvent(QPaintEvent *event)
Paint with a horizontal linear gradient.
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...
int valueHigh() const
Get method for value high.
void unsetColorFilterSettings()
Apply no color filter.
int intensityLow() const
Get method for intensity lower bound.