1 #include "CmdMediator.h"
2 #include "ColorConstants.h"
3 #include "ColorFilterSettings.h"
4 #include "DocumentSerialize.h"
5 #include "EngaugeAssert.h"
6 #include "GridCoordDisable.h"
9 #include <QXmlStreamWriter>
13 m_colorFilterMode (COLOR_FILTER_MODE_INTENSITY),
14 m_intensityLow (INTENSITY_LOW_DEFAULT),
15 m_intensityHigh (INTENSITY_HIGH_DEFAULT),
16 m_foregroundLow (FOREGROUND_LOW_DEFAULT),
17 m_foregroundHigh (FOREGROUND_HIGH_DEFAULT),
18 m_hueLow (HUE_LOW_DEFAULT),
19 m_hueHigh (HUE_HIGH_DEFAULT),
20 m_saturationLow (SATURATION_LOW_DEFAULT),
21 m_saturationHigh (SATURATION_HIGH_DEFAULT),
22 m_valueLow (VALUE_LOW_DEFAULT),
23 m_valueHigh (VALUE_HIGH_DEFAULT)
38 m_colorFilterMode (colorFilterMode),
39 m_intensityLow (intensityLow),
40 m_intensityHigh (intensityHigh),
41 m_foregroundLow (foregroundLow),
42 m_foregroundHigh (foregroundHigh),
45 m_saturationLow (saturationLow),
46 m_saturationHigh (saturationHigh),
47 m_valueLow (valueLow),
48 m_valueHigh (valueHigh)
53 m_colorFilterMode (other.colorFilterMode()),
54 m_intensityLow (other.intensityLow()),
55 m_intensityHigh (other.intensityHigh()),
56 m_foregroundLow (other.foregroundLow()),
57 m_foregroundHigh (other.foregroundHigh()),
58 m_hueLow (other.hueLow()),
59 m_hueHigh (other.hueHigh()),
60 m_saturationLow (other.saturationLow()),
61 m_saturationHigh (other.saturationHigh()),
62 m_valueLow (other.valueLow()),
63 m_valueHigh (other.valueHigh())
91 return m_colorFilterMode;
101 return m_foregroundHigh;
106 return m_foregroundLow;
111 switch (m_colorFilterMode)
113 case COLOR_FILTER_MODE_FOREGROUND:
114 return (
double) (m_foregroundHigh - FOREGROUND_MIN) /
115 (
double) (FOREGROUND_MAX - FOREGROUND_MIN);
117 case COLOR_FILTER_MODE_HUE:
118 return (
double) (m_hueHigh - HUE_MIN) /
119 ((
double) HUE_MAX - HUE_MIN);
121 case COLOR_FILTER_MODE_INTENSITY:
122 return (
double) (m_intensityHigh - INTENSITY_MIN) /
123 (
double) (INTENSITY_MAX - INTENSITY_MIN);
125 case COLOR_FILTER_MODE_SATURATION:
126 return (
double) (m_saturationHigh - SATURATION_MIN) /
127 (
double) (SATURATION_MAX - SATURATION_MIN);
129 case COLOR_FILTER_MODE_VALUE:
130 return (
double) (m_valueHigh - VALUE_MIN) /
131 (
double) (VALUE_MAX - VALUE_MIN);
134 ENGAUGE_ASSERT (
false);
135 return (
double) (m_intensityHigh - INTENSITY_MIN) /
136 (
double) (INTENSITY_MAX - INTENSITY_MIN);
152 return m_intensityHigh;
157 return m_intensityLow;
162 LOG4CPP_INFO_S ((*mainCat)) <<
"ColorFilterSettings::loadXml";
166 QXmlStreamAttributes attributes = reader.attributes();
168 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE) &&
169 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW) &&
170 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH) &&
171 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW) &&
172 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH) &&
173 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW) &&
174 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH) &&
175 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW) &&
176 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH) &&
177 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW) &&
178 attributes.hasAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH)) {
180 setColorFilterMode ((ColorFilterMode) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE).toInt());
181 setIntensityLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW).toInt());
182 setIntensityHigh ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH).toInt());
183 setForegroundLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW).toInt());
184 setForegroundHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH).toInt());
185 setHueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW).toInt());
186 setHueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH).toInt());
187 setSaturationLow ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW).toInt());
188 setSaturationHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH).toInt());
189 setValueLow (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW).toInt());
190 setValueHigh (attributes.value(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH).toInt());
193 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
194 (reader.name() != DOCUMENT_SERIALIZE_COLOR_FILTER)){
195 loadNextFromReader(reader);
197 if (reader.atEnd()) {
205 reader.raiseError (
"Cannot read curve filter data");
211 switch (m_colorFilterMode)
213 case COLOR_FILTER_MODE_FOREGROUND:
214 return (
double) (m_foregroundLow - FOREGROUND_MIN) /
215 (
double) (FOREGROUND_MAX - FOREGROUND_MIN);
217 case COLOR_FILTER_MODE_HUE:
218 return (
double) (m_hueLow - HUE_MIN) /
219 ((
double) HUE_MAX - HUE_MIN);
221 case COLOR_FILTER_MODE_INTENSITY:
222 return (
double) (m_intensityLow - INTENSITY_MIN) /
223 (
double) (INTENSITY_MAX - INTENSITY_MIN);
225 case COLOR_FILTER_MODE_SATURATION:
226 return (
double) (m_saturationLow - SATURATION_MIN) /
227 (
double) (SATURATION_MAX - SATURATION_MIN);
229 case COLOR_FILTER_MODE_VALUE:
230 return (
double) (m_valueLow - VALUE_MIN) /
231 (
double) (VALUE_MAX - VALUE_MIN);
234 ENGAUGE_ASSERT (
false);
235 return (
double) (m_intensityLow - INTENSITY_MIN) /
236 (
double) (INTENSITY_MAX - INTENSITY_MIN);
241 QTextStream &str)
const
243 str << indentation <<
"ColorFilterSettings\n";
245 indentation += INDENTATION_DELTA;
247 switch (m_colorFilterMode) {
248 case COLOR_FILTER_MODE_INTENSITY:
249 str << indentation <<
"intensityLow=" << m_intensityLow <<
"\n";
250 str << indentation <<
"intensityHigh=" << m_intensityHigh <<
"\n";
253 case COLOR_FILTER_MODE_FOREGROUND:
254 str << indentation <<
"foregroundLow=" << m_foregroundLow <<
"\n";
255 str << indentation <<
"foregroundHigh=" << m_foregroundHigh <<
"\n";
258 case COLOR_FILTER_MODE_HUE:
259 str << indentation <<
"hueLow=" << m_hueLow <<
"\n";
260 str << indentation <<
"hueHigh=" << m_hueHigh <<
"\n";
263 case COLOR_FILTER_MODE_SATURATION:
264 str << indentation <<
"saturationLow" << m_saturationLow <<
"\n";
265 str << indentation <<
"saturationHigh" << m_saturationHigh <<
"\n";
268 case COLOR_FILTER_MODE_VALUE:
269 str << indentation <<
"valueLow=" << m_valueLow <<
"\n";
270 str << indentation <<
"valueHigh=" << m_valueHigh <<
"\n";
280 return m_saturationHigh;
285 return m_saturationLow;
290 LOG4CPP_INFO_S ((*mainCat)) <<
"ColorFilterSettings::saveXml";
292 writer.writeStartElement(DOCUMENT_SERIALIZE_COLOR_FILTER);
293 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE, QString::number (m_colorFilterMode));
294 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_MODE_STRING, colorFilterModeToString (m_colorFilterMode));
295 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_LOW, QString::number (m_intensityLow));
296 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_INTENSITY_HIGH, QString::number (m_intensityHigh));
297 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_LOW, QString::number (m_foregroundLow));
298 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_FOREGROUND_HIGH, QString::number (m_foregroundHigh));
299 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_LOW, QString::number (m_hueLow));
300 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_HUE_HIGH, QString::number (m_hueHigh));
301 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_LOW, QString::number (m_saturationLow));
302 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_SATURATION_HIGH, QString::number (m_saturationHigh));
303 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_LOW, QString::number (m_valueLow));
304 writer.writeAttribute(DOCUMENT_SERIALIZE_COLOR_FILTER_VALUE_HIGH, QString::number (m_valueHigh));
305 writer.writeEndElement();
315 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundHigh && foregroundHigh <= FOREGROUND_MAX);
321 ENGAUGE_ASSERT (FOREGROUND_MIN <= foregroundLow && foregroundLow <= FOREGROUND_MAX);
327 switch (m_colorFilterMode) {
328 case COLOR_FILTER_MODE_FOREGROUND:
332 case COLOR_FILTER_MODE_HUE:
333 setHueHigh (HUE_MIN + s0To1 * (HUE_MAX - HUE_MIN));
336 case COLOR_FILTER_MODE_INTENSITY:
340 case COLOR_FILTER_MODE_SATURATION:
344 case COLOR_FILTER_MODE_VALUE:
345 setValueHigh (VALUE_MIN + s0To1 * (VALUE_MAX - VALUE_MIN));
349 ENGAUGE_ASSERT (
false);
355 ENGAUGE_ASSERT (HUE_MIN <= hueHigh && hueHigh <= HUE_MAX);
361 ENGAUGE_ASSERT (HUE_MIN <= hueLow && hueLow <= HUE_MAX);
367 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityHigh && intensityHigh <= INTENSITY_MAX);
373 ENGAUGE_ASSERT (INTENSITY_MIN <= intensityLow && intensityLow <= INTENSITY_MAX);
379 switch (m_colorFilterMode) {
380 case COLOR_FILTER_MODE_FOREGROUND:
381 setForegroundLow (FOREGROUND_MIN + s0To1 * (FOREGROUND_MAX - FOREGROUND_MIN));
384 case COLOR_FILTER_MODE_HUE:
385 setHueLow (HUE_MIN + s0To1 * (HUE_MAX - HUE_MIN));
388 case COLOR_FILTER_MODE_INTENSITY:
389 setIntensityLow (INTENSITY_MIN + s0To1 * (INTENSITY_MAX - INTENSITY_MIN));
392 case COLOR_FILTER_MODE_SATURATION:
393 setSaturationLow (SATURATION_MIN + s0To1 * (SATURATION_MAX - SATURATION_MIN));
396 case COLOR_FILTER_MODE_VALUE:
397 setValueLow (VALUE_MIN + s0To1 * (VALUE_MAX - VALUE_MIN));
401 ENGAUGE_ASSERT (
false);
407 ENGAUGE_ASSERT (SATURATION_MIN <= saturationHigh && saturationHigh <= SATURATION_MAX);
413 ENGAUGE_ASSERT (SATURATION_MIN <= saturationLow && saturationLow <= SATURATION_MAX);
419 ENGAUGE_ASSERT (VALUE_MIN <= valueHigh && valueHigh <= VALUE_MAX);
425 ENGAUGE_ASSERT (VALUE_MIN <= valueLow && valueLow <= VALUE_MAX);
void setSaturationLow(int saturationLow)
Set method for saturation low.
void setLow(double s0To1)
Set the low value for the current filter mode.
void setHueLow(int hueLow)
Set method for hue lower bound.
int saturationLow() const
Get method for saturation lower bound.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
void setColorFilterMode(ColorFilterMode colorFilterMode)
Set method for filter mode.
int hueLow() const
Get method for hue lower bound.
int foregroundHigh() const
Get method for foreground higher bound.
int hueHigh() const
Get method for hue higher bound.
int saturationHigh() const
Get method for saturation higher bound.
ColorFilterSettings & operator=(const ColorFilterSettings &other)
Assignment operator.
void setForegroundLow(int foregroundLow)
Set method for foreground lower bound.
void setHigh(double s0To1)
Set the high value for the current filter mode.
int foregroundLow() const
Get method for foreground lower bound.
void setHueHigh(int hueHigh)
Set method for hue higher bound.
ColorFilterMode colorFilterMode() const
Get method for filter mode.
int valueLow() const
Get method for value low.
void setForegroundHigh(int foregroundHigh)
Set method for foreground higher bound.
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
void setIntensityHigh(int intensityHigh)
Set method for intensity higher bound.
int intensityHigh() const
Get method for intensity higher bound.
void saveXml(QXmlStreamWriter &writer) const
Save curve filter to stream.
void setValueHigh(int valueHigh)
Set method for value high.
void setIntensityLow(int intensityLow)
Set method for intensity lower bound.
int valueHigh() const
Get method for value high.
double low() const
Low value of foreground, hue, intensity, saturation or value according to current filter mode...
void setValueLow(int valueLow)
Set method for value low.
void setSaturationHigh(int saturationHigh)
Set method for saturation high.
void loadXml(QXmlStreamReader &reader)
Load curve filter to stream.
double high() const
High value of foreground, hue, intensity, saturation or value according to current filter mode...
ColorFilterSettings()
Default constructor only for use when this class is being stored by a container that requires the def...
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
int intensityLow() const
Get method for intensity lower bound.