Mercurial > hg > svgui
diff layer/RegionLayer.cpp @ 701:084f65094203
Extend numerical and colour scales (and piano where applicable) to note and region layers
author | Chris Cannam |
---|---|
date | Wed, 04 Dec 2013 13:39:41 +0000 |
parents | 1a0dfcbffaf1 |
children | 137d3ff48f73 |
line wrap: on
line diff
--- a/layer/RegionLayer.cpp Wed Dec 04 13:12:09 2013 +0000 +++ b/layer/RegionLayer.cpp Wed Dec 04 13:39:41 2013 +0000 @@ -20,12 +20,19 @@ #include "base/Profiler.h" #include "base/LogRange.h" #include "ColourDatabase.h" + #include "ColourMapper.h" +#include "LinearNumericalScale.h" +#include "LogNumericalScale.h" +#include "LinearColourScale.h" +#include "LogColourScale.h" + #include "view/View.h" #include "data/model/RegionModel.h" #include "widgets/ItemEditDialog.h" +#include "widgets/TextAbbrev.h" #include <QPainter> #include <QPainterPath> @@ -146,7 +153,7 @@ if (deflt) *deflt = 0; if (m_model) { val = UnitDatabase::getInstance()->getUnitId - (m_model->getScaleUnits()); + (getScaleUnits()); } } else { @@ -270,7 +277,7 @@ if (!m_model) return false; min = m_model->getValueMinimum(); max = m_model->getValueMaximum(); - unit = m_model->getScaleUnits(); + unit = getScaleUnits(); if (m_verticalScale == LogScale) logarithmic = true; @@ -419,7 +426,7 @@ QString valueText; - valueText = tr("%1 %2").arg(region.value).arg(m_model->getScaleUnits()); + valueText = tr("%1 %2").arg(region.value).arg(getScaleUnits()); QString text; @@ -597,6 +604,13 @@ return found; } +QString +RegionLayer::getScaleUnits() const +{ + if (m_model) return m_model->getScaleUnits(); + else return ""; +} + void RegionLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const { @@ -605,7 +619,7 @@ log = false; QString queryUnits; - queryUnits = m_model->getScaleUnits(); + queryUnits = getScaleUnits(); if (m_verticalScale == AutoAlignScale) { @@ -707,6 +721,12 @@ } float +RegionLayer::getValueForY(View *v, int y) const +{ + return getValueForY(v, y, -1); +} + +float RegionLayer::getValueForY(View *v, int y, int avoid) const { float min = 0.0, max = 0.0; @@ -947,7 +967,7 @@ paint.setPen(v->getForeground()); paint.setBrush(v->getForeground()); - QString vlabel = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits()); + QString vlabel = QString("%1%2").arg(p.value).arg(getScaleUnits()); v->drawVisibleText(paint, x - paint.fontMetrics().width(vlabel) - 2, y + paint.fontMetrics().height()/2 @@ -996,7 +1016,7 @@ if (!illuminated) { QString label = p.label; if (label == "") { - label = QString("%1%2").arg(p.value).arg(m_model->getScaleUnits()); + label = QString("%1%2").arg(p.value).arg(getScaleUnits()); } int labelX, labelY; @@ -1024,6 +1044,72 @@ paint.restore(); } +int +RegionLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const +{ + if (!m_model || + m_verticalScale == AutoAlignScale || + m_verticalScale == EqualSpaced) { + return 0; + } else if (m_plotStyle == PlotSegmentation) { + if (m_verticalScale == LogScale) { + return LogColourScale().getWidth(v, paint); + } else { + return LinearColourScale().getWidth(v, paint); + } + } else { + if (m_verticalScale == LogScale) { + return LogNumericalScale().getWidth(v, paint); + } else { + return LinearNumericalScale().getWidth(v, paint); + } + } +} + +void +RegionLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const +{ + if (!m_model) return; + + QString unit; + float min, max; + bool logarithmic; + + int w = getVerticalScaleWidth(v, false, paint); + int h = v->height(); + + if (m_plotStyle == PlotSegmentation) { + + getValueExtents(min, max, logarithmic, unit); + + if (logarithmic) { + LogRange::mapRange(min, max); + LogColourScale().paintVertical(v, this, paint, 0, min, max); + } else { + LinearColourScale().paintVertical(v, this, paint, 0, min, max); + } + + } else { + + getScaleExtents(v, min, max, logarithmic); + + if (logarithmic) { + LogNumericalScale().paintVertical(v, this, paint, 0, min, max); + } else { + LinearNumericalScale().paintVertical(v, this, paint, 0, min, max); + } + } + + if (getScaleUnits() != "") { + int mw = w - 5; + paint.drawText(5, + 5 + paint.fontMetrics().ascent(), + TextAbbrev::abbreviate(getScaleUnits(), + paint.fontMetrics(), + mw)); + } +} + void RegionLayer::drawStart(View *v, QMouseEvent *e) { @@ -1234,7 +1320,7 @@ ItemEditDialog::ShowDuration | ItemEditDialog::ShowValue | ItemEditDialog::ShowText, - m_model->getScaleUnits()); + getScaleUnits()); dialog->setFrameTime(region.frame); dialog->setValue(region.value);