# HG changeset patch # User Chris Cannam # Date 1467286822 -3600 # Node ID ee01a4062747a8e4c781dca61e42211b1e1d2b90 # Parent 5144d7185fb5efc40d78c976adab41f6a2b7dcd7 Move drawVisibleText to PaintAssistant diff -r 5144d7185fb5 -r ee01a4062747 layer/Colour3DPlotLayer.cpp --- a/layer/Colour3DPlotLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/Colour3DPlotLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -21,6 +21,7 @@ #include "ColourMapper.h" #include "LayerGeometryProvider.h" +#include "PaintAssistant.h" #include "view/ViewManager.h" @@ -867,12 +868,12 @@ paint.setWorldMatrix(m); - v->drawVisibleText(paint, 2, 0, minstr, LayerGeometryProvider::OutlinedText); + PaintAssistant::drawVisibleText(v, paint, 2, 0, minstr, PaintAssistant::OutlinedText); m.translate(ch - msw - 2, 0); paint.setWorldMatrix(m); - v->drawVisibleText(paint, 0, 0, maxstr, LayerGeometryProvider::OutlinedText); + PaintAssistant::drawVisibleText(v, paint, 0, 0, maxstr, PaintAssistant::OutlinedText); paint.restore(); } @@ -1440,12 +1441,13 @@ double value = m_model->getValueAt(sx, sy); snprintf(labelbuf, buflen, "%06f", value); QString text(labelbuf); - v->drawVisibleText - (paint, + PaintAssistant::drawVisibleText + (v, + paint, rx0 + 2, ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), text, - LayerGeometryProvider::OutlinedText); + PaintAssistant::OutlinedText); } } } diff -r 5144d7185fb5 -r ee01a4062747 layer/FlexiNoteLayer.cpp --- a/layer/FlexiNoteLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/FlexiNoteLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -22,12 +22,13 @@ #include "base/Pitch.h" #include "base/LogRange.h" #include "base/RangeMapper.h" + #include "ColourDatabase.h" #include "LayerGeometryProvider.h" - #include "PianoScale.h" #include "LinearNumericalScale.h" #include "LogNumericalScale.h" +#include "PaintAssistant.h" #include "data/model/FlexiNoteModel.h" @@ -869,34 +870,34 @@ // paint.setBrush(v->getForeground()); QString vlabel = QString("freq: %1%2").arg(p.value).arg(m_model->getScaleUnits()); - // v->drawVisibleText(paint, + // PaintAssistant::drawVisibleText(v, paint, // x - paint.fontMetrics().width(vlabel) - 2, // y + paint.fontMetrics().height()/2 // - paint.fontMetrics().descent(), - // vlabel, LayerGeometryProvider::OutlinedText); - v->drawVisibleText(paint, + // vlabel, PaintAssistant::OutlinedText); + PaintAssistant::drawVisibleText(v, paint, x, y - h/2 - 2 - paint.fontMetrics().height() - paint.fontMetrics().descent(), - vlabel, LayerGeometryProvider::OutlinedText); + vlabel, PaintAssistant::OutlinedText); QString hlabel = "dur: " + QString(RealTime::frame2RealTime (p.duration, m_model->getSampleRate()).toText(true).c_str()); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, x, y - h/2 - paint.fontMetrics().descent() - 2, - hlabel, LayerGeometryProvider::OutlinedText); + hlabel, PaintAssistant::OutlinedText); QString llabel = QString("%1").arg(p.label); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, x, y + h + 2 + paint.fontMetrics().descent(), - llabel, LayerGeometryProvider::OutlinedText); + llabel, PaintAssistant::OutlinedText); QString nlabel = QString("%1").arg(noteNumber); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, x + paint.fontMetrics().averageCharWidth() / 2, y + h/2 - paint.fontMetrics().descent(), - nlabel, LayerGeometryProvider::OutlinedText); + nlabel, PaintAssistant::OutlinedText); } paint.drawRect(x, y - h/2, w, h); diff -r 5144d7185fb5 -r ee01a4062747 layer/LayerGeometryProvider.h --- a/layer/LayerGeometryProvider.h Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/LayerGeometryProvider.h Thu Jun 30 12:40:22 2016 +0100 @@ -153,15 +153,6 @@ virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const = 0; virtual bool shouldShowFeatureLabels() const = 0; - enum TextStyle { - BoxedText, - OutlinedText, - OutlinedItalicText - }; - - virtual void drawVisibleText(QPainter &p, int x, int y, - QString text, TextStyle style) const = 0; - virtual void drawMeasurementRect(QPainter &p, const Layer *, QRect rect, bool focus) const = 0; diff -r 5144d7185fb5 -r ee01a4062747 layer/NoteLayer.cpp --- a/layer/NoteLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/NoteLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -21,12 +21,13 @@ #include "base/Pitch.h" #include "base/LogRange.h" #include "base/RangeMapper.h" -#include "ColourDatabase.h" #include "view/View.h" +#include "ColourDatabase.h" #include "PianoScale.h" #include "LinearNumericalScale.h" #include "LogNumericalScale.h" +#include "PaintAssistant.h" #include "data/model/NoteModel.h" @@ -809,18 +810,18 @@ paint.setBrush(v->getForeground()); QString vlabel = QString("%1%2").arg(p.value).arg(getScaleUnits()); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, x - paint.fontMetrics().width(vlabel) - 2, y + paint.fontMetrics().height()/2 - paint.fontMetrics().descent(), - vlabel, LayerGeometryProvider::OutlinedText); + vlabel, PaintAssistant::OutlinedText); QString hlabel = RealTime::frame2RealTime (p.frame, m_model->getSampleRate()).toText(true).c_str(); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, x, y - h/2 - paint.fontMetrics().descent() - 2, - hlabel, LayerGeometryProvider::OutlinedText); + hlabel, PaintAssistant::OutlinedText); } paint.drawRect(x, y - h/2, w, h); diff -r 5144d7185fb5 -r ee01a4062747 layer/PaintAssistant.cpp --- a/layer/PaintAssistant.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/PaintAssistant.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -15,6 +15,8 @@ #include "PaintAssistant.h" +#include "LayerGeometryProvider.h" + #include "base/AudioLevel.h" #include @@ -207,3 +209,55 @@ return vy; } + +void +PaintAssistant::drawVisibleText(const LayerGeometryProvider *v, + QPainter &paint, int x, int y, + QString text, TextStyle style) +{ + if (style == OutlinedText || style == OutlinedItalicText) { + + paint.save(); + + if (style == OutlinedItalicText) { + QFont f(paint.font()); + f.setItalic(true); + paint.setFont(f); + } + + QColor penColour, surroundColour, boxColour; + + penColour = v->getForeground(); + surroundColour = v->getBackground(); + boxColour = surroundColour; + boxColour.setAlpha(127); + + paint.setPen(Qt::NoPen); + paint.setBrush(boxColour); + + QRect r = paint.fontMetrics().boundingRect(text); + r.translate(QPoint(x, y)); +// cerr << "drawVisibleText: r = " << r.x() << "," < #include class QPainter; +class Layer; +class LayerGeometryProvider; class PaintAssistant { @@ -34,6 +36,16 @@ static int getYForValue(Scale scale, double value, double minVal, double maxVal, int minY, int height); + + enum TextStyle { + BoxedText, + OutlinedText, + OutlinedItalicText + }; + + static void drawVisibleText(const LayerGeometryProvider *, + QPainter &p, int x, int y, + QString text, TextStyle style); }; #endif diff -r 5144d7185fb5 -r ee01a4062747 layer/RegionLayer.cpp --- a/layer/RegionLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/RegionLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -19,13 +19,14 @@ #include "base/RealTime.h" #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 "PaintAssistant.h" #include "view/View.h" @@ -979,18 +980,18 @@ paint.setBrush(v->getForeground()); QString vlabel = QString("%1%2").arg(p.value).arg(getScaleUnits()); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, x - paint.fontMetrics().width(vlabel) - 2, y + paint.fontMetrics().height()/2 - paint.fontMetrics().descent(), - vlabel, LayerGeometryProvider::OutlinedText); + vlabel, PaintAssistant::OutlinedText); QString hlabel = RealTime::frame2RealTime (p.frame, m_model->getSampleRate()).toText(true).c_str(); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, x, y - h/2 - paint.fontMetrics().descent() - 2, - hlabel, LayerGeometryProvider::OutlinedText); + hlabel, PaintAssistant::OutlinedText); } paint.drawLine(x, y-1, x + w, y-1); @@ -1048,7 +1049,7 @@ nextLabelMinX = labelX + paint.fontMetrics().width(label); } - v->drawVisibleText(paint, labelX, labelY, label, LayerGeometryProvider::OutlinedText); + PaintAssistant::drawVisibleText(v, paint, labelX, labelY, label, PaintAssistant::OutlinedText); } } diff -r 5144d7185fb5 -r ee01a4062747 layer/SliceLayer.cpp --- a/layer/SliceLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/SliceLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -485,17 +485,17 @@ v->drawVisibleText (paint, xorigin + 5, paint.fontMetrics().ascent() + 5, - startText, View::OutlinedText); + startText, PaintAssistant::OutlinedText); v->drawVisibleText (paint, xorigin + 5, paint.fontMetrics().ascent() + paint.fontMetrics().height() + 10, - endText, View::OutlinedText); + endText, PaintAssistant::OutlinedText); v->drawVisibleText (paint, xorigin + 5, paint.fontMetrics().ascent() + 2*paint.fontMetrics().height() + 15, - durationText, View::OutlinedText); + durationText, PaintAssistant::OutlinedText); } */ } diff -r 5144d7185fb5 -r ee01a4062747 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -25,10 +25,12 @@ #include "base/LogRange.h" #include "base/ColumnOp.h" #include "widgets/CommandHistory.h" +#include "data/model/Dense3DModelPeakCache.h" + #include "ColourMapper.h" #include "ImageRegionFinder.h" -#include "data/model/Dense3DModelPeakCache.h" #include "PianoScale.h" +#include "PaintAssistant.h" #include #include @@ -2850,35 +2852,35 @@ double fundamental = getFrequencyForY(v, cursorPos.y()); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, sw + 2, cursorPos.y() - 2, QString("%1 Hz").arg(fundamental), - View::OutlinedText); + PaintAssistant::OutlinedText); if (Pitch::isFrequencyInMidiRange(fundamental)) { QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, sw + 2, cursorPos.y() + paint.fontMetrics().ascent() + 2, pitchLabel, - View::OutlinedText); + PaintAssistant::OutlinedText); } sv_frame_t frame = v->getFrameForX(cursorPos.x()); RealTime rt = RealTime::frame2RealTime(frame, m_model->getSampleRate()); QString rtLabel = QString("%1 s").arg(rt.toText(true).c_str()); QString frameLabel = QString("%1").arg(frame); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, cursorPos.x() - paint.fontMetrics().width(frameLabel) - 2, v->getPaintHeight() - 2, frameLabel, - View::OutlinedText); - v->drawVisibleText(paint, + PaintAssistant::OutlinedText); + PaintAssistant::drawVisibleText(v, paint, cursorPos.x() + 2, v->getPaintHeight() - 2, rtLabel, - View::OutlinedText); + PaintAssistant::OutlinedText); int harmonic = 2; diff -r 5144d7185fb5 -r ee01a4062747 layer/SpectrumLayer.cpp --- a/layer/SpectrumLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/SpectrumLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -21,7 +21,9 @@ #include "base/Preferences.h" #include "base/RangeMapper.h" #include "base/Pitch.h" + #include "ColourMapper.h" +#include "PaintAssistant.h" #include #include @@ -491,19 +493,19 @@ int hoffset = 2; if (m_binScale == LogBins) hoffset = 13; - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, cursorPos.x() + 2, v->getPaintHeight() - 2 - hoffset, QString("%1 Hz").arg(fundamental), - View::OutlinedText); + PaintAssistant::OutlinedText); if (Pitch::isFrequencyInMidiRange(fundamental)) { QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, v->getPaintHeight() - 2 - hoffset, pitchLabel, - View::OutlinedText); + PaintAssistant::OutlinedText); } double value = getValueForY(cursorPos.y(), v); @@ -512,17 +514,17 @@ if (value > 0.0) db = 10.0 * log10(value); if (db < thresh) db = thresh; - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, xorigin + 2, cursorPos.y() - 2, QString("%1 V").arg(value), - View::OutlinedText); + PaintAssistant::OutlinedText); - v->drawVisibleText(paint, + PaintAssistant::drawVisibleText(v, paint, xorigin + 2, cursorPos.y() + 2 + paint.fontMetrics().ascent(), QString("%1 dBV").arg(db), - View::OutlinedText); + PaintAssistant::OutlinedText); int harmonic = 2; diff -r 5144d7185fb5 -r ee01a4062747 layer/TimeInstantLayer.cpp --- a/layer/TimeInstantLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/TimeInstantLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -20,7 +20,9 @@ #include "view/View.h" #include "base/Profiler.h" #include "base/Clipboard.h" + #include "ColourDatabase.h" +#include "PaintAssistant.h" #include "data/model/SparseOneDimensionalModel.h" @@ -456,7 +458,7 @@ } if (good) { - v->drawVisibleText(paint, x + iw + 2, textY, p.label, View::OutlinedText); + PaintAssistant::drawVisibleText(v, paint, x + iw + 2, textY, p.label, PaintAssistant::OutlinedText); // paint.drawText(x + iw + 2, textY, p.label); } } diff -r 5144d7185fb5 -r ee01a4062747 layer/TimeRulerLayer.cpp --- a/layer/TimeRulerLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/TimeRulerLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -19,8 +19,10 @@ #include "data/model/Model.h" #include "base/RealTime.h" +#include "view/View.h" + #include "ColourDatabase.h" -#include "view/View.h" +#include "PaintAssistant.h" #include @@ -324,7 +326,7 @@ // backmost layer, don't worry about outlining the text paint.drawText(x+2 - tw/2, y, text); } else { - v->drawVisibleText(paint, x+2 - tw/2, y, text, View::OutlinedText); + PaintAssistant::drawVisibleText(v, paint, x+2 - tw/2, y, text, PaintAssistant::OutlinedText); } } } diff -r 5144d7185fb5 -r ee01a4062747 layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/TimeValueLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -21,7 +21,6 @@ #include "base/LogRange.h" #include "base/RangeMapper.h" #include "base/Pitch.h" -#include "ColourDatabase.h" #include "view/View.h" #include "data/model/SparseTimeValueModel.h" @@ -31,12 +30,14 @@ #include "widgets/ListInputDialog.h" #include "widgets/TextAbbrev.h" +#include "ColourDatabase.h" #include "ColourMapper.h" #include "PianoScale.h" #include "LinearNumericalScale.h" #include "LogNumericalScale.h" #include "LinearColourScale.h" #include "LogColourScale.h" +#include "PaintAssistant.h" #include #include @@ -1214,10 +1215,10 @@ if (haveRoom || (!haveNext && (pointCount == 0 || !italic))) { - v->drawVisibleText(paint, x + 5, textY, label, + PaintAssistant::drawVisibleText(v, paint, x + 5, textY, label, italic ? - View::OutlinedItalicText : - View::OutlinedText); + PaintAssistant::OutlinedItalicText : + PaintAssistant::OutlinedText); } } } diff -r 5144d7185fb5 -r ee01a4062747 layer/WaveformLayer.cpp --- a/layer/WaveformLayer.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/layer/WaveformLayer.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -19,7 +19,9 @@ #include "view/View.h" #include "base/Profiler.h" #include "base/RangeMapper.h" + #include "ColourDatabase.h" +#include "PaintAssistant.h" #include #include diff -r 5144d7185fb5 -r ee01a4062747 view/Pane.cpp --- a/view/Pane.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/view/Pane.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -25,6 +25,7 @@ #include "base/Preferences.h" #include "layer/WaveformLayer.h" #include "layer/TimeRulerLayer.h" +#include "layer/PaintAssistant.h" // GF: added so we can propagate the mouse move event to the note layer for context handling. #include "layer/LayerFactory.h" @@ -777,14 +778,14 @@ int tw = paint.fontMetrics().width(text); int x = width()/2 - 4 - tw; - drawVisibleText(paint, x, y, text, OutlinedText); + PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); } QString text = QString("%1").arg(m_centreFrame); int x = width()/2 + 4; - drawVisibleText(paint, x, y, text, OutlinedText); + PaintAssistant::drawVisibleText(this, paint, x, y, text, PaintAssistant::OutlinedText); } } @@ -866,8 +867,8 @@ return; } - drawVisibleText(paint, m_scaleWidth + 5, - paint.fontMetrics().ascent() + y, text, OutlinedText); + PaintAssistant::drawVisibleText(this, paint, m_scaleWidth + 5, + paint.fontMetrics().ascent() + y, text, PaintAssistant::OutlinedText); paint.restore(); } @@ -905,8 +906,8 @@ return; } - drawVisibleText(paint, m_scaleWidth + 5, - paint.fontMetrics().ascent() + y, text, OutlinedText); + PaintAssistant::drawVisibleText(this, paint, m_scaleWidth + 5, + paint.fontMetrics().ascent() + y, text, PaintAssistant::OutlinedText); paint.restore(); } @@ -954,9 +955,9 @@ paint.setPen(getForeground()); } - drawVisibleText(paint, llx, + PaintAssistant::drawVisibleText(this, paint, llx, lly - fontHeight + fontAscent, - texts[i], OutlinedText); + texts[i], PaintAssistant::OutlinedText); if (!pixmaps[i].isNull()) { paint.drawPixmap(llx - fontAscent - 3, @@ -1018,10 +1019,10 @@ offsetText = tr("+%1").arg(offsetText); } } - drawVisibleText(paint, p0 + 2, fontAscent + fontHeight + 4, startText, OutlinedText); - drawVisibleText(paint, p1 + 2, fontAscent + fontHeight + 4, endText, OutlinedText); - drawVisibleText(paint, p0 + 2, fontAscent + fontHeight*2 + 4, offsetText, OutlinedText); - drawVisibleText(paint, p1 + 2, fontAscent + fontHeight*2 + 4, offsetText, OutlinedText); + PaintAssistant::drawVisibleText(this, paint, p0 + 2, fontAscent + fontHeight + 4, startText, PaintAssistant::OutlinedText); + PaintAssistant::drawVisibleText(this, paint, p1 + 2, fontAscent + fontHeight + 4, endText, PaintAssistant::OutlinedText); + PaintAssistant::drawVisibleText(this, paint, p0 + 2, fontAscent + fontHeight*2 + 4, offsetText, PaintAssistant::OutlinedText); + PaintAssistant::drawVisibleText(this, paint, p1 + 2, fontAscent + fontHeight*2 + 4, offsetText, PaintAssistant::OutlinedText); //!!! duplicating display policy with View::drawSelections @@ -1084,9 +1085,9 @@ if (x < pbw + 5) x = pbw + 5; if (r.x() < x + paint.fontMetrics().width(desc)) { - drawVisibleText(paint, x, + PaintAssistant::drawVisibleText(this, paint, x, height() - fontHeight + fontAscent - 6, - desc, OutlinedText); + desc, PaintAssistant::OutlinedText); } } diff -r 5144d7185fb5 -r ee01a4062747 view/View.cpp --- a/view/View.cpp Thu Jun 30 10:59:11 2016 +0100 +++ b/view/View.cpp Thu Jun 30 12:40:22 2016 +0100 @@ -24,6 +24,8 @@ #include "layer/TimeRulerLayer.h" #include "layer/SingleColourLayer.h" +#include "layer/PaintAssistant.h" + #include "data/model/PowerOfSqrtTwoZoomConstraint.h" #include "data/model/RangeSummarisableTimeValueModel.h" @@ -810,56 +812,6 @@ } void -View::drawVisibleText(QPainter &paint, int x, int y, QString text, TextStyle style) const -{ - if (style == OutlinedText || style == OutlinedItalicText) { - - paint.save(); - - if (style == OutlinedItalicText) { - QFont f(paint.font()); - f.setItalic(true); - paint.setFont(f); - } - - QColor penColour, surroundColour, boxColour; - - penColour = getForeground(); - surroundColour = getBackground(); - boxColour = surroundColour; - boxColour.setAlpha(127); - - paint.setPen(Qt::NoPen); - paint.setBrush(boxColour); - - QRect r = paint.fontMetrics().boundingRect(text); - r.translate(QPoint(x, y)); -// cerr << "drawVisibleText: r = " << r.x() << "," <shouldShowFeatureLabels(); } - virtual void drawVisibleText(QPainter &p, int x, int y, - QString text, TextStyle style) const { - m_view->drawVisibleText(p, x, y, text, style); - } - virtual void drawMeasurementRect(QPainter &p, const Layer *layer, QRect rect, bool focus) const { m_view->drawMeasurementRect(p, layer, rect, focus);