Mercurial > hg > svgui
diff 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 |
line wrap: on
line diff
--- a/layer/TimeInstantLayer.cpp Wed Jul 11 20:46:37 2007 +0000 +++ b/layer/TimeInstantLayer.cpp Thu Jul 12 16:14:59 2007 +0000 @@ -20,6 +20,7 @@ #include "view/View.h" #include "base/Profiler.h" #include "base/Clipboard.h" +#include "base/ColourDatabase.h" #include "data/model/SparseOneDimensionalModel.h" @@ -32,12 +33,11 @@ #include <cmath> TimeInstantLayer::TimeInstantLayer() : - Layer(), + SingleColourLayer(), m_model(0), m_editing(false), m_editingPoint(0, tr("New Point")), m_editingCommand(0), - m_colour(QColor(200, 50, 255)), m_plotStyle(PlotInstants) { @@ -64,8 +64,7 @@ Layer::PropertyList TimeInstantLayer::getProperties() const { - PropertyList list; - list.push_back("Colour"); + PropertyList list = SingleColourLayer::getProperties(); list.push_back("Plot Type"); return list; } @@ -73,15 +72,15 @@ QString TimeInstantLayer::getPropertyLabel(const PropertyName &name) const { - if (name == "Colour") return tr("Colour"); if (name == "Plot Type") return tr("Plot Type"); - return ""; + return SingleColourLayer::getPropertyLabel(name); } Layer::PropertyType -TimeInstantLayer::getPropertyType(const PropertyName &) const +TimeInstantLayer::getPropertyType(const PropertyName &name) const { - return ValueProperty; + if (name == "Plot Type") return ValueProperty; + return SingleColourLayer::getPropertyType(name); } int @@ -90,20 +89,7 @@ { int val = 0; - if (name == "Colour") { - - if (min) *min = 0; - if (max) *max = 5; - if (deflt) *deflt = 0; - - if (m_colour == Qt::black) val = 0; - else if (m_colour == Qt::darkRed) val = 1; - else if (m_colour == Qt::darkBlue) val = 2; - else if (m_colour == Qt::darkGreen) val = 3; - else if (m_colour == QColor(200, 50, 255)) val = 4; - else if (m_colour == QColor(255, 150, 50)) val = 5; - - } else if (name == "Plot Type") { + if (name == "Plot Type") { if (min) *min = 0; if (max) *max = 1; @@ -113,7 +99,7 @@ } else { - val = Layer::getPropertyRangeAndValue(name, min, max, deflt); + val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt); } return val; @@ -121,55 +107,29 @@ QString TimeInstantLayer::getPropertyValueLabel(const PropertyName &name, - int value) const + int value) const { - if (name == "Colour") { - switch (value) { - default: - case 0: return tr("Black"); - case 1: return tr("Red"); - case 2: return tr("Blue"); - case 3: return tr("Green"); - case 4: return tr("Purple"); - case 5: return tr("Orange"); - } - } else if (name == "Plot Type") { + if (name == "Plot Type") { switch (value) { default: case 0: return tr("Instants"); case 1: return tr("Segmentation"); } } - return tr("<unknown>"); + return SingleColourLayer::getPropertyValueLabel(name, value); } void TimeInstantLayer::setProperty(const PropertyName &name, int value) { - if (name == "Colour") { - switch (value) { - default: - case 0: setBaseColour(Qt::black); break; - case 1: setBaseColour(Qt::darkRed); break; - case 2: setBaseColour(Qt::darkBlue); break; - case 3: setBaseColour(Qt::darkGreen); break; - case 4: setBaseColour(QColor(200, 50, 255)); break; - case 5: setBaseColour(QColor(255, 150, 50)); break; - } - } else if (name == "Plot Type") { + if (name == "Plot Type") { setPlotStyle(PlotStyle(value)); + } else { + SingleColourLayer::setProperty(name, value); } } void -TimeInstantLayer::setBaseColour(QColor colour) -{ - if (m_colour == colour) return; - m_colour = colour; - emit layerParametersChanged(); -} - -void TimeInstantLayer::setPlotStyle(PlotStyle style) { if (m_plotStyle == style) return; @@ -360,21 +320,21 @@ odd = ((index % 2) == 1); } - paint.setPen(m_colour); + paint.setPen(getBaseQColor()); - QColor brushColour(m_colour); + QColor brushColour(getBaseQColor()); brushColour.setAlpha(100); paint.setBrush(brushColour); QColor oddBrushColour(brushColour); if (m_plotStyle == PlotSegmentation) { - if (m_colour == Qt::black) { + if (getBaseQColor() == Qt::black) { oddBrushColour = Qt::gray; - } else if (m_colour == Qt::darkRed) { + } else if (getBaseQColor() == Qt::darkRed) { oddBrushColour = Qt::red; - } else if (m_colour == Qt::darkBlue) { + } else if (getBaseQColor() == Qt::darkBlue) { oddBrushColour = Qt::blue; - } else if (m_colour == Qt::darkGreen) { + } else if (getBaseQColor() == Qt::darkGreen) { oddBrushColour = Qt::green; } else { oddBrushColour = oddBrushColour.light(150); @@ -421,7 +381,7 @@ } if (p.frame == illuminateFrame) { - paint.setPen(Qt::black); //!!! + paint.setPen(getForegroundQColor(v)); } else { paint.setPen(brushColour); } @@ -459,7 +419,7 @@ odd = !odd; } - paint.setPen(m_colour); + paint.setPen(getBaseQColor()); if (p.label != "") { @@ -756,24 +716,26 @@ return true; } +int +TimeInstantLayer::getDefaultColourHint(bool darkbg, bool &impose) +{ + impose = false; + return ColourDatabase::getInstance()->getColourIndex + (QString(darkbg ? "Bright Purple" : "Purple")); +} + QString TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const { - return Layer::toXmlString(indent, extraAttributes + - QString(" colour=\"%1\" plotStyle=\"%2\"") - .arg(encodeColour(m_colour)).arg(m_plotStyle)); + return SingleColourLayer::toXmlString(indent, extraAttributes + + QString(" plotStyle=\"%1\"") + .arg(m_plotStyle)); } void TimeInstantLayer::setProperties(const QXmlAttributes &attributes) { - QString colourSpec = attributes.value("colour"); - if (colourSpec != "") { - QColor colour(colourSpec); - if (colour.isValid()) { - setBaseColour(QColor(colourSpec)); - } - } + SingleColourLayer::setProperties(attributes); bool ok; PlotStyle style = (PlotStyle)