Mercurial > hg > svgui
comparison layer/TimeInstantLayer.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 | e175ade2d6b0 |
children | cda569dfbdfe |
comparison
equal
deleted
inserted
replaced
286:7554ae119882 | 287:cd2492c5fe45 |
---|---|
18 #include "data/model/Model.h" | 18 #include "data/model/Model.h" |
19 #include "base/RealTime.h" | 19 #include "base/RealTime.h" |
20 #include "view/View.h" | 20 #include "view/View.h" |
21 #include "base/Profiler.h" | 21 #include "base/Profiler.h" |
22 #include "base/Clipboard.h" | 22 #include "base/Clipboard.h" |
23 #include "base/ColourDatabase.h" | |
23 | 24 |
24 #include "data/model/SparseOneDimensionalModel.h" | 25 #include "data/model/SparseOneDimensionalModel.h" |
25 | 26 |
26 #include "widgets/ItemEditDialog.h" | 27 #include "widgets/ItemEditDialog.h" |
27 | 28 |
30 | 31 |
31 #include <iostream> | 32 #include <iostream> |
32 #include <cmath> | 33 #include <cmath> |
33 | 34 |
34 TimeInstantLayer::TimeInstantLayer() : | 35 TimeInstantLayer::TimeInstantLayer() : |
35 Layer(), | 36 SingleColourLayer(), |
36 m_model(0), | 37 m_model(0), |
37 m_editing(false), | 38 m_editing(false), |
38 m_editingPoint(0, tr("New Point")), | 39 m_editingPoint(0, tr("New Point")), |
39 m_editingCommand(0), | 40 m_editingCommand(0), |
40 m_colour(QColor(200, 50, 255)), | |
41 m_plotStyle(PlotInstants) | 41 m_plotStyle(PlotInstants) |
42 { | 42 { |
43 | 43 |
44 } | 44 } |
45 | 45 |
62 } | 62 } |
63 | 63 |
64 Layer::PropertyList | 64 Layer::PropertyList |
65 TimeInstantLayer::getProperties() const | 65 TimeInstantLayer::getProperties() const |
66 { | 66 { |
67 PropertyList list; | 67 PropertyList list = SingleColourLayer::getProperties(); |
68 list.push_back("Colour"); | |
69 list.push_back("Plot Type"); | 68 list.push_back("Plot Type"); |
70 return list; | 69 return list; |
71 } | 70 } |
72 | 71 |
73 QString | 72 QString |
74 TimeInstantLayer::getPropertyLabel(const PropertyName &name) const | 73 TimeInstantLayer::getPropertyLabel(const PropertyName &name) const |
75 { | 74 { |
76 if (name == "Colour") return tr("Colour"); | |
77 if (name == "Plot Type") return tr("Plot Type"); | 75 if (name == "Plot Type") return tr("Plot Type"); |
78 return ""; | 76 return SingleColourLayer::getPropertyLabel(name); |
79 } | 77 } |
80 | 78 |
81 Layer::PropertyType | 79 Layer::PropertyType |
82 TimeInstantLayer::getPropertyType(const PropertyName &) const | 80 TimeInstantLayer::getPropertyType(const PropertyName &name) const |
83 { | 81 { |
84 return ValueProperty; | 82 if (name == "Plot Type") return ValueProperty; |
83 return SingleColourLayer::getPropertyType(name); | |
85 } | 84 } |
86 | 85 |
87 int | 86 int |
88 TimeInstantLayer::getPropertyRangeAndValue(const PropertyName &name, | 87 TimeInstantLayer::getPropertyRangeAndValue(const PropertyName &name, |
89 int *min, int *max, int *deflt) const | 88 int *min, int *max, int *deflt) const |
90 { | 89 { |
91 int val = 0; | 90 int val = 0; |
92 | 91 |
93 if (name == "Colour") { | 92 if (name == "Plot Type") { |
94 | |
95 if (min) *min = 0; | |
96 if (max) *max = 5; | |
97 if (deflt) *deflt = 0; | |
98 | |
99 if (m_colour == Qt::black) val = 0; | |
100 else if (m_colour == Qt::darkRed) val = 1; | |
101 else if (m_colour == Qt::darkBlue) val = 2; | |
102 else if (m_colour == Qt::darkGreen) val = 3; | |
103 else if (m_colour == QColor(200, 50, 255)) val = 4; | |
104 else if (m_colour == QColor(255, 150, 50)) val = 5; | |
105 | |
106 } else if (name == "Plot Type") { | |
107 | 93 |
108 if (min) *min = 0; | 94 if (min) *min = 0; |
109 if (max) *max = 1; | 95 if (max) *max = 1; |
110 if (deflt) *deflt = 0; | 96 if (deflt) *deflt = 0; |
111 | 97 |
112 val = int(m_plotStyle); | 98 val = int(m_plotStyle); |
113 | 99 |
114 } else { | 100 } else { |
115 | 101 |
116 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); | 102 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); |
117 } | 103 } |
118 | 104 |
119 return val; | 105 return val; |
120 } | 106 } |
121 | 107 |
122 QString | 108 QString |
123 TimeInstantLayer::getPropertyValueLabel(const PropertyName &name, | 109 TimeInstantLayer::getPropertyValueLabel(const PropertyName &name, |
124 int value) const | 110 int value) const |
125 { | 111 { |
126 if (name == "Colour") { | 112 if (name == "Plot Type") { |
127 switch (value) { | |
128 default: | |
129 case 0: return tr("Black"); | |
130 case 1: return tr("Red"); | |
131 case 2: return tr("Blue"); | |
132 case 3: return tr("Green"); | |
133 case 4: return tr("Purple"); | |
134 case 5: return tr("Orange"); | |
135 } | |
136 } else if (name == "Plot Type") { | |
137 switch (value) { | 113 switch (value) { |
138 default: | 114 default: |
139 case 0: return tr("Instants"); | 115 case 0: return tr("Instants"); |
140 case 1: return tr("Segmentation"); | 116 case 1: return tr("Segmentation"); |
141 } | 117 } |
142 } | 118 } |
143 return tr("<unknown>"); | 119 return SingleColourLayer::getPropertyValueLabel(name, value); |
144 } | 120 } |
145 | 121 |
146 void | 122 void |
147 TimeInstantLayer::setProperty(const PropertyName &name, int value) | 123 TimeInstantLayer::setProperty(const PropertyName &name, int value) |
148 { | 124 { |
149 if (name == "Colour") { | 125 if (name == "Plot Type") { |
150 switch (value) { | |
151 default: | |
152 case 0: setBaseColour(Qt::black); break; | |
153 case 1: setBaseColour(Qt::darkRed); break; | |
154 case 2: setBaseColour(Qt::darkBlue); break; | |
155 case 3: setBaseColour(Qt::darkGreen); break; | |
156 case 4: setBaseColour(QColor(200, 50, 255)); break; | |
157 case 5: setBaseColour(QColor(255, 150, 50)); break; | |
158 } | |
159 } else if (name == "Plot Type") { | |
160 setPlotStyle(PlotStyle(value)); | 126 setPlotStyle(PlotStyle(value)); |
161 } | 127 } else { |
162 } | 128 SingleColourLayer::setProperty(name, value); |
163 | 129 } |
164 void | |
165 TimeInstantLayer::setBaseColour(QColor colour) | |
166 { | |
167 if (m_colour == colour) return; | |
168 m_colour = colour; | |
169 emit layerParametersChanged(); | |
170 } | 130 } |
171 | 131 |
172 void | 132 void |
173 TimeInstantLayer::setPlotStyle(PlotStyle style) | 133 TimeInstantLayer::setPlotStyle(PlotStyle style) |
174 { | 134 { |
358 if (m_plotStyle == PlotSegmentation && !points.empty()) { | 318 if (m_plotStyle == PlotSegmentation && !points.empty()) { |
359 int index = m_model->getIndexOf(*points.begin()); | 319 int index = m_model->getIndexOf(*points.begin()); |
360 odd = ((index % 2) == 1); | 320 odd = ((index % 2) == 1); |
361 } | 321 } |
362 | 322 |
363 paint.setPen(m_colour); | 323 paint.setPen(getBaseQColor()); |
364 | 324 |
365 QColor brushColour(m_colour); | 325 QColor brushColour(getBaseQColor()); |
366 brushColour.setAlpha(100); | 326 brushColour.setAlpha(100); |
367 paint.setBrush(brushColour); | 327 paint.setBrush(brushColour); |
368 | 328 |
369 QColor oddBrushColour(brushColour); | 329 QColor oddBrushColour(brushColour); |
370 if (m_plotStyle == PlotSegmentation) { | 330 if (m_plotStyle == PlotSegmentation) { |
371 if (m_colour == Qt::black) { | 331 if (getBaseQColor() == Qt::black) { |
372 oddBrushColour = Qt::gray; | 332 oddBrushColour = Qt::gray; |
373 } else if (m_colour == Qt::darkRed) { | 333 } else if (getBaseQColor() == Qt::darkRed) { |
374 oddBrushColour = Qt::red; | 334 oddBrushColour = Qt::red; |
375 } else if (m_colour == Qt::darkBlue) { | 335 } else if (getBaseQColor() == Qt::darkBlue) { |
376 oddBrushColour = Qt::blue; | 336 oddBrushColour = Qt::blue; |
377 } else if (m_colour == Qt::darkGreen) { | 337 } else if (getBaseQColor() == Qt::darkGreen) { |
378 oddBrushColour = Qt::green; | 338 oddBrushColour = Qt::green; |
379 } else { | 339 } else { |
380 oddBrushColour = oddBrushColour.light(150); | 340 oddBrushColour = oddBrushColour.light(150); |
381 } | 341 } |
382 oddBrushColour.setAlpha(100); | 342 oddBrushColour.setAlpha(100); |
419 iw = 2; | 379 iw = 2; |
420 } | 380 } |
421 } | 381 } |
422 | 382 |
423 if (p.frame == illuminateFrame) { | 383 if (p.frame == illuminateFrame) { |
424 paint.setPen(Qt::black); //!!! | 384 paint.setPen(getForegroundQColor(v)); |
425 } else { | 385 } else { |
426 paint.setPen(brushColour); | 386 paint.setPen(brushColour); |
427 } | 387 } |
428 | 388 |
429 if (m_plotStyle == PlotInstants) { | 389 if (m_plotStyle == PlotInstants) { |
457 } | 417 } |
458 | 418 |
459 odd = !odd; | 419 odd = !odd; |
460 } | 420 } |
461 | 421 |
462 paint.setPen(m_colour); | 422 paint.setPen(getBaseQColor()); |
463 | 423 |
464 if (p.label != "") { | 424 if (p.label != "") { |
465 | 425 |
466 // only draw if there's enough room from here to the next point | 426 // only draw if there's enough room from here to the next point |
467 | 427 |
754 | 714 |
755 command->finish(); | 715 command->finish(); |
756 return true; | 716 return true; |
757 } | 717 } |
758 | 718 |
719 int | |
720 TimeInstantLayer::getDefaultColourHint(bool darkbg, bool &impose) | |
721 { | |
722 impose = false; | |
723 return ColourDatabase::getInstance()->getColourIndex | |
724 (QString(darkbg ? "Bright Purple" : "Purple")); | |
725 } | |
726 | |
759 QString | 727 QString |
760 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const | 728 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const |
761 { | 729 { |
762 return Layer::toXmlString(indent, extraAttributes + | 730 return SingleColourLayer::toXmlString(indent, extraAttributes + |
763 QString(" colour=\"%1\" plotStyle=\"%2\"") | 731 QString(" plotStyle=\"%1\"") |
764 .arg(encodeColour(m_colour)).arg(m_plotStyle)); | 732 .arg(m_plotStyle)); |
765 } | 733 } |
766 | 734 |
767 void | 735 void |
768 TimeInstantLayer::setProperties(const QXmlAttributes &attributes) | 736 TimeInstantLayer::setProperties(const QXmlAttributes &attributes) |
769 { | 737 { |
770 QString colourSpec = attributes.value("colour"); | 738 SingleColourLayer::setProperties(attributes); |
771 if (colourSpec != "") { | |
772 QColor colour(colourSpec); | |
773 if (colour.isValid()) { | |
774 setBaseColour(QColor(colourSpec)); | |
775 } | |
776 } | |
777 | 739 |
778 bool ok; | 740 bool ok; |
779 PlotStyle style = (PlotStyle) | 741 PlotStyle style = (PlotStyle) |
780 attributes.value("plotStyle").toInt(&ok); | 742 attributes.value("plotStyle").toInt(&ok); |
781 if (ok) setPlotStyle(style); | 743 if (ok) setPlotStyle(style); |