7 #include "ColorConstants.h" 8 #include "ColorFilter.h" 9 #include "ColorFilterSettings.h" 10 #include "EngaugeAssert.h" 15 #include "ViewSegmentFilter.h" 17 const QColor COLOR_FOR_BRUSH_DISABLED (Qt::gray);
21 m_filterIsDefined (false),
22 m_rgbBackground (QColor (Qt::white)),
28 QColor ViewSegmentFilter::colorFromSetting (ColorFilterMode coloFilterMode,
35 int r = 0, g = 0, b = 0;
37 switch (coloFilterMode)
39 case COLOR_FILTER_MODE_FOREGROUND:
41 double s = double (foreground - FOREGROUND_MIN) / double (FOREGROUND_MAX - FOREGROUND_MIN);
42 if (qGray (m_rgbBackground.rgb ()) < 127) {
49 r = qFloor ((1.0 - s) * 255);
50 g = qFloor ((1.0 - s) * 255);
51 b = qFloor ((1.0 - s) * 255);
56 case COLOR_FILTER_MODE_HUE:
60 int HUE_THRESHOLD_LOW = qFloor (0.666 * HUE_MIN + 0.333 * HUE_MAX);
61 int HUE_THRESHOLD_HIGH = qFloor (0.333 * HUE_MIN + 0.666 * HUE_MAX);
63 if (hue < HUE_THRESHOLD_LOW) {
65 double s = double (hue - HUE_MIN) / double (HUE_THRESHOLD_LOW - HUE_MIN);
66 r = qFloor ((1.0 - s) * 255);
68 }
else if (hue < HUE_THRESHOLD_HIGH) {
70 double s = double (hue - HUE_THRESHOLD_LOW) / double (HUE_THRESHOLD_HIGH - HUE_THRESHOLD_LOW);
71 g = qFloor ((1.0 - s) * 255);
75 double s = double (hue - HUE_THRESHOLD_HIGH) / double (HUE_MAX - HUE_THRESHOLD_HIGH);
76 b = qFloor ((1.0 - s) * 255);
82 case COLOR_FILTER_MODE_INTENSITY:
86 double s = double (intensity - INTENSITY_MIN) / double (INTENSITY_MAX - INTENSITY_MIN);
93 case COLOR_FILTER_MODE_SATURATION:
97 double s = double (saturation - SATURATION_MIN) / double (SATURATION_MAX - SATURATION_MIN);
99 g = qFloor ((1.0 - s) * 255);
100 b = qFloor ((1.0 - s) * 255);
104 case COLOR_FILTER_MODE_VALUE:
108 double s = double (value - VALUE_MIN) / double (VALUE_MAX - VALUE_MIN);
109 r = qFloor (s * 255);
116 ENGAUGE_ASSERT (
false);
122 int rgbAverage = (r + g + b) / 3;
128 return QColor (r, g, b);
131 QColor ViewSegmentFilter::colorHigh ()
const 136 m_colorFilterSettings.
hueHigh (),
141 return QColor (COLOR_FOR_BRUSH_DISABLED);
145 QColor ViewSegmentFilter::colorLow ()
const 150 m_colorFilterSettings.
hueLow (),
155 return QColor (COLOR_FOR_BRUSH_DISABLED);
161 QPainter painter(
this);
163 if (m_filterIsDefined) {
166 QLinearGradient gradient (0, height()/2, width(), height()/2);
169 gradient.setColorAt (0.0, colorLow ());
170 gradient.setColorAt (1.0, colorHigh ());
171 painter.setBrush (gradient);
174 painter.setPen (Qt::NoPen);
176 painter.drawRect (0, 0, width(), height());
180 painter.fillRect (0, 0, width (), height (), QBrush (COLOR_FOR_BRUSH_DISABLED));
186 const QPixmap &pixmap)
188 LOG4CPP_INFO_S ((*mainCat)) <<
"ViewSegmentFilter::setColorFilterSettings";
190 m_colorFilterSettings = colorFilterSettings;
191 m_filterIsDefined =
true;
195 QImage img = pixmap.toImage();
204 LOG4CPP_INFO_S ((*mainCat)) <<
"ViewSegmentFilter::setEnabled" 205 <<
" enabled=" << (enabled ?
"true" :
"false");
215 m_filterIsDefined =
false;
int valueHigh() const
Get method for value high.
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 hueHigh() const
Get method for hue higher bound.
int foregroundLow() const
Get method for foreground lower bound.
void setEnabled(bool enabled)
Show the style with semi-transparency or full-transparency to indicate if associated Curve is active ...
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...
ViewSegmentFilter(QWidget *parent=0)
Single constructor.
Class for filtering image to remove unimportant information.
int foregroundHigh() const
Get method for foreground higher bound.
int intensityHigh() const
Get method for intensity higher bound.
int intensityLow() const
Get method for intensity lower bound.
int saturationHigh() const
Get method for saturation higher bound.
virtual void paintEvent(QPaintEvent *event)
Paint with a horizontal linear gradient.
int valueLow() const
Get method for value low.
ColorFilterMode colorFilterMode() const
Get method for filter mode.
void unsetColorFilterSettings()
Apply no color filter.
int hueLow() const
Get method for hue lower bound.
int saturationLow() const
Get method for saturation lower bound.