Mercurial > hg > svgui
comparison layer/WaveformLayer.cpp @ 287:cd2492c5fe45
* Add SingleColourLayer to manage colours for layers that have a single
predominant colour (i.e. most of them).
author | Chris Cannam |
---|---|
date | Thu, 12 Jul 2007 16:14:59 +0000 |
parents | 9dd432665059 |
children | 5804703450d8 |
comparison
equal
deleted
inserted
replaced
286:7554ae119882 | 287:cd2492c5fe45 |
---|---|
31 | 31 |
32 using std::cerr; | 32 using std::cerr; |
33 using std::endl; | 33 using std::endl; |
34 | 34 |
35 WaveformLayer::WaveformLayer() : | 35 WaveformLayer::WaveformLayer() : |
36 Layer(), | 36 SingleColourLayer(), |
37 m_model(0), | 37 m_model(0), |
38 m_gain(1.0f), | 38 m_gain(1.0f), |
39 m_autoNormalize(false), | 39 m_autoNormalize(false), |
40 //!!! m_colour(Qt::black), | |
41 m_colour(0), | |
42 // m_colour(QColor(84, 177, 248)), | |
43 m_showMeans(true), | 40 m_showMeans(true), |
44 m_greyscale(true), | 41 m_greyscale(true), |
45 m_channelMode(SeparateChannels), | 42 m_channelMode(SeparateChannels), |
46 m_channel(-1), | 43 m_channel(-1), |
47 m_scale(LinearScale), | 44 m_scale(LinearScale), |
88 emit modelReplaced(); | 85 emit modelReplaced(); |
89 | 86 |
90 if (channelsChanged) emit layerParametersChanged(); | 87 if (channelsChanged) emit layerParametersChanged(); |
91 } | 88 } |
92 | 89 |
93 bool | |
94 WaveformLayer::hasLightBackground() const | |
95 { | |
96 bool dark = ColourDatabase::getInstance()->useDarkBackground(m_colour); | |
97 return !dark; | |
98 } | |
99 | |
100 Layer::PropertyList | 90 Layer::PropertyList |
101 WaveformLayer::getProperties() const | 91 WaveformLayer::getProperties() const |
102 { | 92 { |
103 PropertyList list; | 93 PropertyList list = SingleColourLayer::getProperties(); |
104 list.push_back("Colour"); | |
105 list.push_back("Scale"); | 94 list.push_back("Scale"); |
106 list.push_back("Gain"); | 95 list.push_back("Gain"); |
107 list.push_back("Normalize Visible Area"); | 96 list.push_back("Normalize Visible Area"); |
108 | 97 |
109 if (m_model && m_model->getChannelCount() > 1 && m_channel == -1) { | 98 if (m_model && m_model->getChannelCount() > 1 && m_channel == -1) { |
114 } | 103 } |
115 | 104 |
116 QString | 105 QString |
117 WaveformLayer::getPropertyLabel(const PropertyName &name) const | 106 WaveformLayer::getPropertyLabel(const PropertyName &name) const |
118 { | 107 { |
119 if (name == "Colour") return tr("Colour"); | |
120 if (name == "Scale") return tr("Scale"); | 108 if (name == "Scale") return tr("Scale"); |
121 if (name == "Gain") return tr("Gain"); | 109 if (name == "Gain") return tr("Gain"); |
122 if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); | 110 if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); |
123 if (name == "Channels") return tr("Channels"); | 111 if (name == "Channels") return tr("Channels"); |
124 return ""; | 112 return SingleColourLayer::getPropertyLabel(name); |
125 } | 113 } |
126 | 114 |
127 Layer::PropertyType | 115 Layer::PropertyType |
128 WaveformLayer::getPropertyType(const PropertyName &name) const | 116 WaveformLayer::getPropertyType(const PropertyName &name) const |
129 { | 117 { |
130 if (name == "Gain") return RangeProperty; | 118 if (name == "Gain") return RangeProperty; |
131 if (name == "Normalize Visible Area") return ToggleProperty; | 119 if (name == "Normalize Visible Area") return ToggleProperty; |
132 if (name == "Colour") return ColourProperty; | |
133 if (name == "Channels") return ValueProperty; | 120 if (name == "Channels") return ValueProperty; |
134 if (name == "Scale") return ValueProperty; | 121 if (name == "Scale") return ValueProperty; |
135 return InvalidProperty; | 122 return SingleColourLayer::getPropertyType(name); |
136 } | 123 } |
137 | 124 |
138 QString | 125 QString |
139 WaveformLayer::getPropertyGroupName(const PropertyName &name) const | 126 WaveformLayer::getPropertyGroupName(const PropertyName &name) const |
140 { | 127 { |
168 } else if (name == "Normalize Visible Area") { | 155 } else if (name == "Normalize Visible Area") { |
169 | 156 |
170 val = (m_autoNormalize ? 1 : 0); | 157 val = (m_autoNormalize ? 1 : 0); |
171 *deflt = 0; | 158 *deflt = 0; |
172 | 159 |
173 } else if (name == "Colour") { | |
174 | |
175 ColourDatabase::getInstance()->getColourPropertyRange(min, max); | |
176 //!!! *min = 0; | |
177 // *max = 5; | |
178 *deflt = 0; | |
179 | |
180 val = m_colour; | |
181 | |
182 /*!!! | |
183 if (m_colour == Qt::black) val = 0; | |
184 else if (m_colour == Qt::darkRed) val = 1; | |
185 else if (m_colour == Qt::darkBlue || | |
186 m_colour == QColor(84, 177, 248)) val = 2; | |
187 else if (m_colour == Qt::darkGreen) val = 3; | |
188 else if (m_colour == QColor(200, 50, 255)) val = 4; | |
189 else if (m_colour == QColor(255, 150, 50)) val = 5; | |
190 */ | |
191 } else if (name == "Channels") { | 160 } else if (name == "Channels") { |
192 | 161 |
193 *min = 0; | 162 *min = 0; |
194 *max = 2; | 163 *max = 2; |
195 *deflt = 0; | 164 *deflt = 0; |
204 *deflt = 0; | 173 *deflt = 0; |
205 | 174 |
206 val = (int)m_scale; | 175 val = (int)m_scale; |
207 | 176 |
208 } else { | 177 } else { |
209 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); | 178 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); |
210 } | 179 } |
211 | 180 |
212 return val; | 181 return val; |
213 } | 182 } |
214 | 183 |
215 QString | 184 QString |
216 WaveformLayer::getPropertyValueLabel(const PropertyName &name, | 185 WaveformLayer::getPropertyValueLabel(const PropertyName &name, |
217 int value) const | 186 int value) const |
218 { | 187 { |
219 if (name == "Colour") { | |
220 return Layer::getPropertyValueLabel(name, value); | |
221 } | |
222 if (name == "Scale") { | 188 if (name == "Scale") { |
223 switch (value) { | 189 switch (value) { |
224 default: | 190 default: |
225 case 0: return tr("Linear"); | 191 case 0: return tr("Linear"); |
226 case 1: return tr("Meter"); | 192 case 1: return tr("Meter"); |
233 case 0: return tr("Separate"); | 199 case 0: return tr("Separate"); |
234 case 1: return tr("Mean"); | 200 case 1: return tr("Mean"); |
235 case 2: return tr("Butterfly"); | 201 case 2: return tr("Butterfly"); |
236 } | 202 } |
237 } | 203 } |
238 return tr("<unknown>"); | 204 return SingleColourLayer::getPropertyValueLabel(name, value); |
239 } | 205 } |
240 | 206 |
241 RangeMapper * | 207 RangeMapper * |
242 WaveformLayer::getNewPropertyRangeMapper(const PropertyName &name) const | 208 WaveformLayer::getNewPropertyRangeMapper(const PropertyName &name) const |
243 { | 209 { |
252 { | 218 { |
253 if (name == "Gain") { | 219 if (name == "Gain") { |
254 setGain(pow(10, float(value)/20.0)); | 220 setGain(pow(10, float(value)/20.0)); |
255 } else if (name == "Normalize Visible Area") { | 221 } else if (name == "Normalize Visible Area") { |
256 setAutoNormalize(value ? true : false); | 222 setAutoNormalize(value ? true : false); |
257 } else if (name == "Colour") { | |
258 setBaseColour(value); | |
259 } else if (name == "Channels") { | 223 } else if (name == "Channels") { |
260 if (value == 1) setChannelMode(MixChannels); | 224 if (value == 1) setChannelMode(MixChannels); |
261 else if (value == 2) setChannelMode(MergeChannels); | 225 else if (value == 2) setChannelMode(MergeChannels); |
262 else setChannelMode(SeparateChannels); | 226 else setChannelMode(SeparateChannels); |
263 } else if (name == "Scale") { | 227 } else if (name == "Scale") { |
265 default: | 229 default: |
266 case 0: setScale(LinearScale); break; | 230 case 0: setScale(LinearScale); break; |
267 case 1: setScale(MeterScale); break; | 231 case 1: setScale(MeterScale); break; |
268 case 2: setScale(dBScale); break; | 232 case 2: setScale(dBScale); break; |
269 } | 233 } |
234 } else { | |
235 SingleColourLayer::setProperty(name, value); | |
270 } | 236 } |
271 } | 237 } |
272 | 238 |
273 void | 239 void |
274 WaveformLayer::setGain(float gain) | 240 WaveformLayer::setGain(float gain) |
283 void | 249 void |
284 WaveformLayer::setAutoNormalize(bool autoNormalize) | 250 WaveformLayer::setAutoNormalize(bool autoNormalize) |
285 { | 251 { |
286 if (m_autoNormalize == autoNormalize) return; | 252 if (m_autoNormalize == autoNormalize) return; |
287 m_autoNormalize = autoNormalize; | 253 m_autoNormalize = autoNormalize; |
288 m_cacheValid = false; | |
289 emit layerParametersChanged(); | |
290 } | |
291 | |
292 void | |
293 WaveformLayer::setBaseColour(int colour) | |
294 { | |
295 if (m_colour == colour) return; | |
296 m_colour = colour; | |
297 m_cacheValid = false; | 254 m_cacheValid = false; |
298 emit layerParametersChanged(); | 255 emit layerParametersChanged(); |
299 } | 256 } |
300 | 257 |
301 void | 258 void |
492 } | 449 } |
493 | 450 |
494 paint = new QPainter(m_cache); | 451 paint = new QPainter(m_cache); |
495 | 452 |
496 paint->setPen(Qt::NoPen); | 453 paint->setPen(Qt::NoPen); |
497 paint->setBrush(v->palette().background()); | 454 paint->setBrush(getBackgroundQColor(v)); |
498 paint->drawRect(rect); | 455 paint->drawRect(rect); |
499 | 456 |
500 paint->setPen(Qt::black); | 457 paint->setPen(getForegroundQColor(v)); |
501 paint->setBrush(Qt::NoBrush); | 458 paint->setBrush(Qt::NoBrush); |
502 | 459 |
503 } else { | 460 } else { |
504 paint = &viewPainter; | 461 paint = &viewPainter; |
505 } | 462 } |
527 RangeSummarisableTimeValueModel::RangeBlock *ranges = | 484 RangeSummarisableTimeValueModel::RangeBlock *ranges = |
528 new RangeSummarisableTimeValueModel::RangeBlock; | 485 new RangeSummarisableTimeValueModel::RangeBlock; |
529 | 486 |
530 RangeSummarisableTimeValueModel::RangeBlock *otherChannelRanges = 0; | 487 RangeSummarisableTimeValueModel::RangeBlock *otherChannelRanges = 0; |
531 RangeSummarisableTimeValueModel::Range range; | 488 RangeSummarisableTimeValueModel::Range range; |
532 | 489 |
533 QColor greys[3]; | 490 QColor baseColour = getBaseQColor(); |
534 QColor baseColour = ColourDatabase::getInstance()->getColour(m_colour); | 491 std::vector<QColor> greys = getPartialShades(v); |
535 if (baseColour == Qt::black) { | |
536 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest | |
537 int level = 192 - 64 * i; | |
538 greys[i] = QColor(level, level, level); | |
539 } | |
540 } else { | |
541 int hue, sat, val; | |
542 baseColour.getHsv(&hue, &sat, &val); | |
543 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest | |
544 if (v->hasLightBackground()) { | |
545 greys[i] = QColor::fromHsv(hue, sat * (i + 1) / 4, val); | |
546 } else { | |
547 greys[i] = QColor::fromHsv(hue, sat * (3 - i) / 4, val); | |
548 } | |
549 } | |
550 } | |
551 | 492 |
552 QColor midColour = baseColour; | 493 QColor midColour = baseColour; |
553 if (midColour == Qt::black) { | 494 if (midColour == Qt::black) { |
554 midColour = Qt::gray; | 495 midColour = Qt::gray; |
555 } else if (v->hasLightBackground()) { | 496 } else if (v->hasLightBackground()) { |
1282 QString colourName, colourSpec, darkbg; | 1223 QString colourName, colourSpec, darkbg; |
1283 ColourDatabase::getInstance()->getStringValues | 1224 ColourDatabase::getInstance()->getStringValues |
1284 (m_colour, colourName, colourSpec, darkbg); | 1225 (m_colour, colourName, colourSpec, darkbg); |
1285 | 1226 |
1286 s += QString("gain=\"%1\" " | 1227 s += QString("gain=\"%1\" " |
1287 "colourName=\"%2\" " | 1228 "showMeans=\"%2\" " |
1288 "colour=\"%3\" " | 1229 "greyscale=\"%3\" " |
1289 "darkBackground=\"%4\" " | 1230 "channelMode=\"%4\" " |
1290 "showMeans=\"%5\" " | 1231 "channel=\"%5\" " |
1291 "greyscale=\"%6\" " | 1232 "scale=\"%6\" " |
1292 "channelMode=\"%7\" " | 1233 "aggressive=\"%7\" " |
1293 "channel=\"%8\" ") | 1234 "autoNormalize=\"%8\"") |
1294 .arg(m_gain) | 1235 .arg(m_gain) |
1295 .arg(colourName) | |
1296 .arg(colourSpec) | |
1297 .arg(darkbg) | |
1298 .arg(m_showMeans) | 1236 .arg(m_showMeans) |
1299 .arg(m_greyscale) | 1237 .arg(m_greyscale) |
1300 .arg(m_channelMode) | 1238 .arg(m_channelMode) |
1301 .arg(m_channel); | 1239 .arg(m_channel) |
1302 | |
1303 s += QString("scale=\"%1\" " | |
1304 "aggressive=\"%2\" " | |
1305 "autoNormalize=\"%3\"") | |
1306 .arg(m_scale) | 1240 .arg(m_scale) |
1307 .arg(m_aggressive) | 1241 .arg(m_aggressive) |
1308 .arg(m_autoNormalize); | 1242 .arg(m_autoNormalize); |
1309 | 1243 |
1310 return Layer::toXmlString(indent, extraAttributes + " " + s); | 1244 return SingleColourLayer::toXmlString(indent, extraAttributes + " " + s); |
1311 } | 1245 } |
1312 | 1246 |
1313 void | 1247 void |
1314 WaveformLayer::setProperties(const QXmlAttributes &attributes) | 1248 WaveformLayer::setProperties(const QXmlAttributes &attributes) |
1315 { | 1249 { |
1316 bool ok = false; | 1250 bool ok = false; |
1317 | 1251 |
1252 SingleColourLayer::setProperties(attributes); | |
1253 | |
1318 float gain = attributes.value("gain").toFloat(&ok); | 1254 float gain = attributes.value("gain").toFloat(&ok); |
1319 if (ok) setGain(gain); | 1255 if (ok) setGain(gain); |
1320 | |
1321 QString colourName = attributes.value("colourName"); | |
1322 QString colourSpec = attributes.value("colour"); | |
1323 QString darkbg = attributes.value("darkBackground"); | |
1324 m_colour = ColourDatabase::getInstance()->putStringValues | |
1325 (colourName, colourSpec, darkbg); | |
1326 | 1256 |
1327 bool showMeans = (attributes.value("showMeans") == "1" || | 1257 bool showMeans = (attributes.value("showMeans") == "1" || |
1328 attributes.value("showMeans") == "true"); | 1258 attributes.value("showMeans") == "true"); |
1329 setShowMeans(showMeans); | 1259 setShowMeans(showMeans); |
1330 | 1260 |