Mercurial > hg > svgui
comparison layer/WaveformLayer.cpp @ 285:9dd432665059
* Add a colour database, and Add New Colour function to the colour combo
in property box. The colour property is only correctly handled in the
waveform layer so far.
* Add en_GB translation, to translate those annoying Color texts in the
Qt colour picker dialog.
author | Chris Cannam |
---|---|
date | Wed, 11 Jul 2007 17:21:37 +0000 |
parents | b9380f679f70 |
children | cd2492c5fe45 |
comparison
equal
deleted
inserted
replaced
284:1284955856ab | 285:9dd432665059 |
---|---|
17 | 17 |
18 #include "base/AudioLevel.h" | 18 #include "base/AudioLevel.h" |
19 #include "view/View.h" | 19 #include "view/View.h" |
20 #include "base/Profiler.h" | 20 #include "base/Profiler.h" |
21 #include "base/RangeMapper.h" | 21 #include "base/RangeMapper.h" |
22 #include "base/ColourDatabase.h" | |
22 | 23 |
23 #include <QPainter> | 24 #include <QPainter> |
24 #include <QPixmap> | 25 #include <QPixmap> |
25 | 26 |
26 #include <iostream> | 27 #include <iostream> |
34 WaveformLayer::WaveformLayer() : | 35 WaveformLayer::WaveformLayer() : |
35 Layer(), | 36 Layer(), |
36 m_model(0), | 37 m_model(0), |
37 m_gain(1.0f), | 38 m_gain(1.0f), |
38 m_autoNormalize(false), | 39 m_autoNormalize(false), |
39 m_colour(Qt::black), | 40 //!!! m_colour(Qt::black), |
41 m_colour(0), | |
40 // m_colour(QColor(84, 177, 248)), | 42 // m_colour(QColor(84, 177, 248)), |
41 m_showMeans(true), | 43 m_showMeans(true), |
42 m_greyscale(true), | 44 m_greyscale(true), |
43 m_channelMode(SeparateChannels), | 45 m_channelMode(SeparateChannels), |
44 m_channel(-1), | 46 m_channel(-1), |
86 emit modelReplaced(); | 88 emit modelReplaced(); |
87 | 89 |
88 if (channelsChanged) emit layerParametersChanged(); | 90 if (channelsChanged) emit layerParametersChanged(); |
89 } | 91 } |
90 | 92 |
93 bool | |
94 WaveformLayer::hasLightBackground() const | |
95 { | |
96 bool dark = ColourDatabase::getInstance()->useDarkBackground(m_colour); | |
97 return !dark; | |
98 } | |
99 | |
91 Layer::PropertyList | 100 Layer::PropertyList |
92 WaveformLayer::getProperties() const | 101 WaveformLayer::getProperties() const |
93 { | 102 { |
94 PropertyList list; | 103 PropertyList list; |
95 list.push_back("Colour"); | 104 list.push_back("Colour"); |
118 Layer::PropertyType | 127 Layer::PropertyType |
119 WaveformLayer::getPropertyType(const PropertyName &name) const | 128 WaveformLayer::getPropertyType(const PropertyName &name) const |
120 { | 129 { |
121 if (name == "Gain") return RangeProperty; | 130 if (name == "Gain") return RangeProperty; |
122 if (name == "Normalize Visible Area") return ToggleProperty; | 131 if (name == "Normalize Visible Area") return ToggleProperty; |
123 if (name == "Colour") return ValueProperty; | 132 if (name == "Colour") return ColourProperty; |
124 if (name == "Channels") return ValueProperty; | 133 if (name == "Channels") return ValueProperty; |
125 if (name == "Scale") return ValueProperty; | 134 if (name == "Scale") return ValueProperty; |
126 return InvalidProperty; | 135 return InvalidProperty; |
127 } | 136 } |
128 | 137 |
161 val = (m_autoNormalize ? 1 : 0); | 170 val = (m_autoNormalize ? 1 : 0); |
162 *deflt = 0; | 171 *deflt = 0; |
163 | 172 |
164 } else if (name == "Colour") { | 173 } else if (name == "Colour") { |
165 | 174 |
166 *min = 0; | 175 ColourDatabase::getInstance()->getColourPropertyRange(min, max); |
167 *max = 5; | 176 //!!! *min = 0; |
177 // *max = 5; | |
168 *deflt = 0; | 178 *deflt = 0; |
169 | 179 |
180 val = m_colour; | |
181 | |
182 /*!!! | |
170 if (m_colour == Qt::black) val = 0; | 183 if (m_colour == Qt::black) val = 0; |
171 else if (m_colour == Qt::darkRed) val = 1; | 184 else if (m_colour == Qt::darkRed) val = 1; |
172 else if (m_colour == Qt::darkBlue || | 185 else if (m_colour == Qt::darkBlue || |
173 m_colour == QColor(84, 177, 248)) val = 2; | 186 m_colour == QColor(84, 177, 248)) val = 2; |
174 else if (m_colour == Qt::darkGreen) val = 3; | 187 else if (m_colour == Qt::darkGreen) val = 3; |
175 else if (m_colour == QColor(200, 50, 255)) val = 4; | 188 else if (m_colour == QColor(200, 50, 255)) val = 4; |
176 else if (m_colour == QColor(255, 150, 50)) val = 5; | 189 else if (m_colour == QColor(255, 150, 50)) val = 5; |
177 | 190 */ |
178 } else if (name == "Channels") { | 191 } else if (name == "Channels") { |
179 | 192 |
180 *min = 0; | 193 *min = 0; |
181 *max = 2; | 194 *max = 2; |
182 *deflt = 0; | 195 *deflt = 0; |
202 QString | 215 QString |
203 WaveformLayer::getPropertyValueLabel(const PropertyName &name, | 216 WaveformLayer::getPropertyValueLabel(const PropertyName &name, |
204 int value) const | 217 int value) const |
205 { | 218 { |
206 if (name == "Colour") { | 219 if (name == "Colour") { |
207 switch (value) { | 220 return Layer::getPropertyValueLabel(name, value); |
208 default: | |
209 case 0: return tr("Black"); | |
210 case 1: return tr("Red"); | |
211 case 2: return tr("Blue"); | |
212 case 3: return tr("Green"); | |
213 case 4: return tr("Purple"); | |
214 case 5: return tr("Orange"); | |
215 } | |
216 } | 221 } |
217 if (name == "Scale") { | 222 if (name == "Scale") { |
218 switch (value) { | 223 switch (value) { |
219 default: | 224 default: |
220 case 0: return tr("Linear"); | 225 case 0: return tr("Linear"); |
248 if (name == "Gain") { | 253 if (name == "Gain") { |
249 setGain(pow(10, float(value)/20.0)); | 254 setGain(pow(10, float(value)/20.0)); |
250 } else if (name == "Normalize Visible Area") { | 255 } else if (name == "Normalize Visible Area") { |
251 setAutoNormalize(value ? true : false); | 256 setAutoNormalize(value ? true : false); |
252 } else if (name == "Colour") { | 257 } else if (name == "Colour") { |
253 switch (value) { | 258 setBaseColour(value); |
254 default: | |
255 case 0: setBaseColour(Qt::black); break; | |
256 case 1: setBaseColour(Qt::darkRed); break; | |
257 // case 2: setBaseColour(QColor(84, 177, 248)); break; | |
258 case 2: setBaseColour(Qt::darkBlue); break; | |
259 case 3: setBaseColour(Qt::darkGreen); break; | |
260 case 4: setBaseColour(QColor(200, 50, 255)); break; | |
261 case 5: setBaseColour(QColor(255, 150, 50)); break; | |
262 } | |
263 } else if (name == "Channels") { | 259 } else if (name == "Channels") { |
264 if (value == 1) setChannelMode(MixChannels); | 260 if (value == 1) setChannelMode(MixChannels); |
265 else if (value == 2) setChannelMode(MergeChannels); | 261 else if (value == 2) setChannelMode(MergeChannels); |
266 else setChannelMode(SeparateChannels); | 262 else setChannelMode(SeparateChannels); |
267 } else if (name == "Scale") { | 263 } else if (name == "Scale") { |
292 m_cacheValid = false; | 288 m_cacheValid = false; |
293 emit layerParametersChanged(); | 289 emit layerParametersChanged(); |
294 } | 290 } |
295 | 291 |
296 void | 292 void |
297 WaveformLayer::setBaseColour(QColor colour) | 293 WaveformLayer::setBaseColour(int colour) |
298 { | 294 { |
299 if (m_colour == colour) return; | 295 if (m_colour == colour) return; |
300 m_colour = colour; | 296 m_colour = colour; |
301 m_cacheValid = false; | 297 m_cacheValid = false; |
302 emit layerParametersChanged(); | 298 emit layerParametersChanged(); |
533 | 529 |
534 RangeSummarisableTimeValueModel::RangeBlock *otherChannelRanges = 0; | 530 RangeSummarisableTimeValueModel::RangeBlock *otherChannelRanges = 0; |
535 RangeSummarisableTimeValueModel::Range range; | 531 RangeSummarisableTimeValueModel::Range range; |
536 | 532 |
537 QColor greys[3]; | 533 QColor greys[3]; |
538 if (m_colour == Qt::black) { | 534 QColor baseColour = ColourDatabase::getInstance()->getColour(m_colour); |
535 if (baseColour == Qt::black) { | |
539 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest | 536 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest |
540 int level = 192 - 64 * i; | 537 int level = 192 - 64 * i; |
541 greys[i] = QColor(level, level, level); | 538 greys[i] = QColor(level, level, level); |
542 } | 539 } |
543 } else { | 540 } else { |
544 int hue, sat, val; | 541 int hue, sat, val; |
545 m_colour.getHsv(&hue, &sat, &val); | 542 baseColour.getHsv(&hue, &sat, &val); |
546 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest | 543 for (int i = 0; i < 3; ++i) { // 0 lightest, 2 darkest |
547 if (v->hasLightBackground()) { | 544 if (v->hasLightBackground()) { |
548 greys[i] = QColor::fromHsv(hue, sat * (i + 1) / 4, val); | 545 greys[i] = QColor::fromHsv(hue, sat * (i + 1) / 4, val); |
549 } else { | 546 } else { |
550 greys[i] = QColor::fromHsv(hue, sat * (3 - i) / 4, val); | 547 greys[i] = QColor::fromHsv(hue, sat * (3 - i) / 4, val); |
551 } | 548 } |
552 } | 549 } |
553 } | 550 } |
554 | 551 |
555 QColor midColour = m_colour; | 552 QColor midColour = baseColour; |
556 if (midColour == Qt::black) { | 553 if (midColour == Qt::black) { |
557 midColour = Qt::gray; | 554 midColour = Qt::gray; |
558 } else if (v->hasLightBackground()) { | 555 } else if (v->hasLightBackground()) { |
559 midColour = midColour.light(150); | 556 midColour = midColour.light(150); |
560 } else { | 557 } else { |
566 } | 563 } |
567 | 564 |
568 for (size_t ch = minChannel; ch <= maxChannel; ++ch) { | 565 for (size_t ch = minChannel; ch <= maxChannel; ++ch) { |
569 | 566 |
570 int prevRangeBottom = -1, prevRangeTop = -1; | 567 int prevRangeBottom = -1, prevRangeTop = -1; |
571 QColor prevRangeBottomColour = m_colour, prevRangeTopColour = m_colour; | 568 QColor prevRangeBottomColour = baseColour, prevRangeTopColour = baseColour; |
572 | 569 |
573 m_effectiveGains[ch] = m_gain; | 570 m_effectiveGains[ch] = m_gain; |
574 | 571 |
575 if (m_autoNormalize) { | 572 if (m_autoNormalize) { |
576 RangeSummarisableTimeValueModel::Range range = | 573 RangeSummarisableTimeValueModel::Range range = |
835 | 832 |
836 if (x != x0 && prevRangeBottom != -1) { | 833 if (x != x0 && prevRangeBottom != -1) { |
837 if (prevRangeBottom > rangeBottom && | 834 if (prevRangeBottom > rangeBottom && |
838 prevRangeTop > rangeBottom) { | 835 prevRangeTop > rangeBottom) { |
839 // paint->setPen(midColour); | 836 // paint->setPen(midColour); |
840 paint->setPen(m_colour); | 837 paint->setPen(baseColour); |
841 paint->drawLine(x-1, prevRangeTop, x, rangeBottom); | 838 paint->drawLine(x-1, prevRangeTop, x, rangeBottom); |
842 paint->setPen(prevRangeTopColour); | 839 paint->setPen(prevRangeTopColour); |
843 paint->drawPoint(x-1, prevRangeTop); | 840 paint->drawPoint(x-1, prevRangeTop); |
844 } else if (prevRangeBottom < rangeTop && | 841 } else if (prevRangeBottom < rangeTop && |
845 prevRangeTop < rangeTop) { | 842 prevRangeTop < rangeTop) { |
846 // paint->setPen(midColour); | 843 // paint->setPen(midColour); |
847 paint->setPen(m_colour); | 844 paint->setPen(baseColour); |
848 paint->drawLine(x-1, prevRangeBottom, x, rangeTop); | 845 paint->drawLine(x-1, prevRangeBottom, x, rangeTop); |
849 paint->setPen(prevRangeBottomColour); | 846 paint->setPen(prevRangeBottomColour); |
850 paint->drawPoint(x-1, prevRangeBottom); | 847 paint->drawPoint(x-1, prevRangeBottom); |
851 } | 848 } |
852 } | 849 } |
853 | 850 |
854 if (ready) { | 851 if (ready) { |
855 if (clipped /*!!! || | 852 if (clipped /*!!! || |
856 range.min * gain <= -1.0 || | 853 range.min * gain <= -1.0 || |
857 range.max * gain >= 1.0 */) { | 854 range.max * gain >= 1.0 */) { |
858 paint->setPen(Qt::red); | 855 paint->setPen(Qt::red); //!!! getContrastingColour |
859 } else { | 856 } else { |
860 paint->setPen(m_colour); | 857 paint->setPen(baseColour); |
861 } | 858 } |
862 } else { | 859 } else { |
863 paint->setPen(midColour); | 860 paint->setPen(midColour); |
864 } | 861 } |
865 | 862 |
866 paint->drawLine(x, rangeBottom, x, rangeTop); | 863 paint->drawLine(x, rangeBottom, x, rangeTop); |
867 | 864 |
868 prevRangeTopColour = m_colour; | 865 prevRangeTopColour = baseColour; |
869 prevRangeBottomColour = m_colour; | 866 prevRangeBottomColour = baseColour; |
870 | 867 |
871 if (m_greyscale && (m_scale == LinearScale) && ready) { | 868 if (m_greyscale && (m_scale == LinearScale) && ready) { |
872 if (!clipped) { | 869 if (!clipped) { |
873 if (rangeTop < rangeBottom) { | 870 if (rangeTop < rangeBottom) { |
874 if (topFill > 0 && | 871 if (topFill > 0 && |
1280 QString | 1277 QString |
1281 WaveformLayer::toXmlString(QString indent, QString extraAttributes) const | 1278 WaveformLayer::toXmlString(QString indent, QString extraAttributes) const |
1282 { | 1279 { |
1283 QString s; | 1280 QString s; |
1284 | 1281 |
1282 QString colourName, colourSpec, darkbg; | |
1283 ColourDatabase::getInstance()->getStringValues | |
1284 (m_colour, colourName, colourSpec, darkbg); | |
1285 | |
1285 s += QString("gain=\"%1\" " | 1286 s += QString("gain=\"%1\" " |
1286 "colour=\"%2\" " | 1287 "colourName=\"%2\" " |
1287 "showMeans=\"%3\" " | 1288 "colour=\"%3\" " |
1288 "greyscale=\"%4\" " | 1289 "darkBackground=\"%4\" " |
1289 "channelMode=\"%5\" " | 1290 "showMeans=\"%5\" " |
1290 "channel=\"%6\" " | 1291 "greyscale=\"%6\" " |
1291 "scale=\"%7\" " | 1292 "channelMode=\"%7\" " |
1292 "aggressive=\"%8\" " | 1293 "channel=\"%8\" ") |
1293 "autoNormalize=\"%9\"") | |
1294 .arg(m_gain) | 1294 .arg(m_gain) |
1295 .arg(encodeColour(m_colour)) | 1295 .arg(colourName) |
1296 .arg(colourSpec) | |
1297 .arg(darkbg) | |
1296 .arg(m_showMeans) | 1298 .arg(m_showMeans) |
1297 .arg(m_greyscale) | 1299 .arg(m_greyscale) |
1298 .arg(m_channelMode) | 1300 .arg(m_channelMode) |
1299 .arg(m_channel) | 1301 .arg(m_channel); |
1302 | |
1303 s += QString("scale=\"%1\" " | |
1304 "aggressive=\"%2\" " | |
1305 "autoNormalize=\"%3\"") | |
1300 .arg(m_scale) | 1306 .arg(m_scale) |
1301 .arg(m_aggressive) | 1307 .arg(m_aggressive) |
1302 .arg(m_autoNormalize); | 1308 .arg(m_autoNormalize); |
1303 | 1309 |
1304 return Layer::toXmlString(indent, extraAttributes + " " + s); | 1310 return Layer::toXmlString(indent, extraAttributes + " " + s); |
1310 bool ok = false; | 1316 bool ok = false; |
1311 | 1317 |
1312 float gain = attributes.value("gain").toFloat(&ok); | 1318 float gain = attributes.value("gain").toFloat(&ok); |
1313 if (ok) setGain(gain); | 1319 if (ok) setGain(gain); |
1314 | 1320 |
1321 QString colourName = attributes.value("colourName"); | |
1315 QString colourSpec = attributes.value("colour"); | 1322 QString colourSpec = attributes.value("colour"); |
1316 if (colourSpec != "") { | 1323 QString darkbg = attributes.value("darkBackground"); |
1317 QColor colour(colourSpec); | 1324 m_colour = ColourDatabase::getInstance()->putStringValues |
1318 if (colour.isValid()) { | 1325 (colourName, colourSpec, darkbg); |
1319 setBaseColour(QColor(colourSpec)); | |
1320 } | |
1321 } | |
1322 | 1326 |
1323 bool showMeans = (attributes.value("showMeans") == "1" || | 1327 bool showMeans = (attributes.value("showMeans") == "1" || |
1324 attributes.value("showMeans") == "true"); | 1328 attributes.value("showMeans") == "true"); |
1325 setShowMeans(showMeans); | 1329 setShowMeans(showMeans); |
1326 | 1330 |