Mercurial > hg > svgui
comparison layer/TextLayer.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 | a66ff2059dae |
comparison
equal
deleted
inserted
replaced
286:7554ae119882 | 287:cd2492c5fe45 |
---|---|
16 #include "TextLayer.h" | 16 #include "TextLayer.h" |
17 | 17 |
18 #include "data/model/Model.h" | 18 #include "data/model/Model.h" |
19 #include "base/RealTime.h" | 19 #include "base/RealTime.h" |
20 #include "base/Profiler.h" | 20 #include "base/Profiler.h" |
21 #include "base/ColourDatabase.h" | |
21 #include "view/View.h" | 22 #include "view/View.h" |
22 | 23 |
23 #include "data/model/TextModel.h" | 24 #include "data/model/TextModel.h" |
24 | 25 |
25 #include <QPainter> | 26 #include <QPainter> |
28 | 29 |
29 #include <iostream> | 30 #include <iostream> |
30 #include <cmath> | 31 #include <cmath> |
31 | 32 |
32 TextLayer::TextLayer() : | 33 TextLayer::TextLayer() : |
33 Layer(), | 34 SingleColourLayer(), |
34 m_model(0), | 35 m_model(0), |
35 m_editing(false), | 36 m_editing(false), |
36 m_originalPoint(0, 0.0, tr("Empty Label")), | 37 m_originalPoint(0, 0.0, tr("Empty Label")), |
37 m_editingPoint(0, 0.0, tr("Empty Label")), | 38 m_editingPoint(0, 0.0, tr("Empty Label")), |
38 m_editingCommand(0), | 39 m_editingCommand(0) |
39 m_colour(255, 150, 50) // orange | |
40 { | 40 { |
41 | 41 |
42 } | 42 } |
43 | 43 |
44 void | 44 void |
60 } | 60 } |
61 | 61 |
62 Layer::PropertyList | 62 Layer::PropertyList |
63 TextLayer::getProperties() const | 63 TextLayer::getProperties() const |
64 { | 64 { |
65 PropertyList list; | 65 PropertyList list = SingleColourLayer::getProperties(); |
66 list.push_back("Colour"); | |
67 return list; | 66 return list; |
68 } | 67 } |
69 | 68 |
70 QString | 69 QString |
71 TextLayer::getPropertyLabel(const PropertyName &name) const | 70 TextLayer::getPropertyLabel(const PropertyName &name) const |
72 { | 71 { |
73 if (name == "Colour") return tr("Colour"); | 72 return SingleColourLayer::getPropertyLabel(name); |
74 return ""; | |
75 } | 73 } |
76 | 74 |
77 Layer::PropertyType | 75 Layer::PropertyType |
78 TextLayer::getPropertyType(const PropertyName &) const | 76 TextLayer::getPropertyType(const PropertyName &name) const |
79 { | 77 { |
80 return ValueProperty; | 78 return SingleColourLayer::getPropertyType(name); |
81 } | 79 } |
82 | 80 |
83 int | 81 int |
84 TextLayer::getPropertyRangeAndValue(const PropertyName &name, | 82 TextLayer::getPropertyRangeAndValue(const PropertyName &name, |
85 int *min, int *max, int *deflt) const | 83 int *min, int *max, int *deflt) const |
86 { | 84 { |
87 //!!! factor this colour handling stuff out into a colour manager class | 85 return SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); |
88 | |
89 int val = 0; | |
90 | |
91 if (name == "Colour") { | |
92 | |
93 if (min) *min = 0; | |
94 if (max) *max = 5; | |
95 if (deflt) *deflt = 0; | |
96 | |
97 if (m_colour == Qt::black) val = 0; | |
98 else if (m_colour == Qt::darkRed) val = 1; | |
99 else if (m_colour == Qt::darkBlue) val = 2; | |
100 else if (m_colour == Qt::darkGreen) val = 3; | |
101 else if (m_colour == QColor(200, 50, 255)) val = 4; | |
102 else if (m_colour == QColor(255, 150, 50)) val = 5; | |
103 | |
104 } else { | |
105 | |
106 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); | |
107 } | |
108 | |
109 return val; | |
110 } | 86 } |
111 | 87 |
112 QString | 88 QString |
113 TextLayer::getPropertyValueLabel(const PropertyName &name, | 89 TextLayer::getPropertyValueLabel(const PropertyName &name, |
114 int value) const | 90 int value) const |
115 { | 91 { |
116 if (name == "Colour") { | 92 return SingleColourLayer::getPropertyValueLabel(name, value); |
117 switch (value) { | |
118 default: | |
119 case 0: return tr("Black"); | |
120 case 1: return tr("Red"); | |
121 case 2: return tr("Blue"); | |
122 case 3: return tr("Green"); | |
123 case 4: return tr("Purple"); | |
124 case 5: return tr("Orange"); | |
125 } | |
126 } | |
127 return tr("<unknown>"); | |
128 } | 93 } |
129 | 94 |
130 void | 95 void |
131 TextLayer::setProperty(const PropertyName &name, int value) | 96 TextLayer::setProperty(const PropertyName &name, int value) |
132 { | 97 { |
133 if (name == "Colour") { | 98 SingleColourLayer::setProperty(name, value); |
134 switch (value) { | |
135 default: | |
136 case 0: setBaseColour(Qt::black); break; | |
137 case 1: setBaseColour(Qt::darkRed); break; | |
138 case 2: setBaseColour(Qt::darkBlue); break; | |
139 case 3: setBaseColour(Qt::darkGreen); break; | |
140 case 4: setBaseColour(QColor(200, 50, 255)); break; | |
141 case 5: setBaseColour(QColor(255, 150, 50)); break; | |
142 } | |
143 } | |
144 } | 99 } |
145 | 100 |
146 bool | 101 bool |
147 TextLayer::getValueExtents(float &, float &, bool &, QString &) const | 102 TextLayer::getValueExtents(float &, float &, bool &, QString &) const |
148 { | 103 { |
149 return false; | 104 return false; |
150 } | |
151 | |
152 void | |
153 TextLayer::setBaseColour(QColor colour) | |
154 { | |
155 if (m_colour == colour) return; | |
156 m_colour = colour; | |
157 emit layerParametersChanged(); | |
158 } | 105 } |
159 | 106 |
160 bool | 107 bool |
161 TextLayer::isLayerScrollable(const View *v) const | 108 TextLayer::isLayerScrollable(const View *v) const |
162 { | 109 { |
348 long frame1 = v->getFrameForX(x1); | 295 long frame1 = v->getFrameForX(x1); |
349 | 296 |
350 TextModel::PointList points(m_model->getPoints(frame0, frame1)); | 297 TextModel::PointList points(m_model->getPoints(frame0, frame1)); |
351 if (points.empty()) return; | 298 if (points.empty()) return; |
352 | 299 |
353 QColor brushColour(m_colour); | 300 QColor brushColour(getBaseQColor()); |
354 | 301 |
355 int h, s, val; | 302 int h, s, val; |
356 brushColour.getHsv(&h, &s, &val); | 303 brushColour.getHsv(&h, &s, &val); |
357 brushColour.setHsv(h, s, 255, 100); | 304 brushColour.setHsv(h, s, 255, 100); |
358 | 305 |
359 QColor penColour; | 306 QColor penColour; |
360 if (v->hasLightBackground()) { | 307 penColour = v->getForeground(); |
361 penColour = Qt::black; | |
362 } else { | |
363 penColour = Qt::white; | |
364 } | |
365 | 308 |
366 // std::cerr << "TextLayer::paint: resolution is " | 309 // std::cerr << "TextLayer::paint: resolution is " |
367 // << m_model->getResolution() << " frames" << std::endl; | 310 // << m_model->getResolution() << " frames" << std::endl; |
368 | 311 |
369 QPoint localPos; | 312 QPoint localPos; |
389 int x = v->getXForFrame(p.frame); | 332 int x = v->getXForFrame(p.frame); |
390 int y = getYForHeight(v, p.height); | 333 int y = getYForHeight(v, p.height); |
391 | 334 |
392 if (illuminateFrame == p.frame) { | 335 if (illuminateFrame == p.frame) { |
393 paint.setBrush(penColour); | 336 paint.setBrush(penColour); |
394 if (v->hasLightBackground()) { | 337 paint.setPen(v->getBackground()); |
395 paint.setPen(Qt::white); | |
396 } else { | |
397 paint.setPen(Qt::black); | |
398 } | |
399 } else { | 338 } else { |
400 paint.setPen(penColour); | 339 paint.setPen(penColour); |
401 paint.setBrush(brushColour); | 340 paint.setBrush(brushColour); |
402 } | 341 } |
403 | 342 |
754 | 693 |
755 command->finish(); | 694 command->finish(); |
756 return true; | 695 return true; |
757 } | 696 } |
758 | 697 |
698 int | |
699 TextLayer::getDefaultColourHint(bool darkbg, bool &impose) | |
700 { | |
701 impose = false; | |
702 return ColourDatabase::getInstance()->getColourIndex | |
703 (QString(darkbg ? "Bright Orange" : "Orange")); | |
704 } | |
705 | |
759 QString | 706 QString |
760 TextLayer::toXmlString(QString indent, QString extraAttributes) const | 707 TextLayer::toXmlString(QString indent, QString extraAttributes) const |
761 { | 708 { |
762 return Layer::toXmlString(indent, extraAttributes + | 709 return SingleColourLayer::toXmlString(indent, extraAttributes); |
763 QString(" colour=\"%1\"") | |
764 .arg(encodeColour(m_colour))); | |
765 } | 710 } |
766 | 711 |
767 void | 712 void |
768 TextLayer::setProperties(const QXmlAttributes &attributes) | 713 TextLayer::setProperties(const QXmlAttributes &attributes) |
769 { | 714 { |
770 QString colourSpec = attributes.value("colour"); | 715 SingleColourLayer::setProperties(attributes); |
771 if (colourSpec != "") { | 716 } |
772 QColor colour(colourSpec); | 717 |
773 if (colour.isValid()) { | |
774 setBaseColour(QColor(colourSpec)); | |
775 } | |
776 } | |
777 } | |
778 |