annotate layer/LinearNumericalScale.cpp @ 1371:ca9a36a5ab76

Progressively increase sample-box size slightly
author Chris Cannam
date Fri, 02 Nov 2018 15:23:42 +0000
parents fc9d9f1103fa
children f2525e6cbdf1
rev   line source
Chris@696 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@696 2
Chris@696 3 /*
Chris@696 4 Sonic Visualiser
Chris@696 5 An audio file viewer and annotation editor.
Chris@696 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1281 7 This file copyright 2006-2018 Chris Cannam and QMUL.
Chris@696 8
Chris@696 9 This program is free software; you can redistribute it and/or
Chris@696 10 modify it under the terms of the GNU General Public License as
Chris@696 11 published by the Free Software Foundation; either version 2 of the
Chris@696 12 License, or (at your option) any later version. See the file
Chris@696 13 COPYING included with this distribution for more information.
Chris@696 14 */
Chris@696 15
Chris@696 16 #include "LinearNumericalScale.h"
Chris@696 17 #include "VerticalScaleLayer.h"
Chris@1281 18 #include "LayerGeometryProvider.h"
Chris@696 19
Chris@696 20 #include <QPainter>
Chris@696 21
Chris@696 22 #include <cmath>
Chris@696 23
Chris@1258 24 #include "base/ScaleTickIntervals.h"
Chris@1258 25
Chris@696 26 int
Chris@918 27 LinearNumericalScale::getWidth(LayerGeometryProvider *,
Chris@1281 28 QPainter &paint)
Chris@696 29 {
Chris@1281 30 return paint.fontMetrics().width("-000.00") + 10;
Chris@696 31 }
Chris@696 32
Chris@696 33 void
Chris@918 34 LinearNumericalScale::paintVertical(LayerGeometryProvider *v,
Chris@1266 35 const VerticalScaleLayer *layer,
Chris@1266 36 QPainter &paint,
Chris@1266 37 int x0,
Chris@1266 38 double minf,
Chris@1266 39 double maxf)
Chris@696 40 {
Chris@696 41 int n = 10;
Chris@1258 42 auto ticks = ScaleTickIntervals::linear({ minf, maxf, n });
Chris@1260 43 n = int(ticks.size());
Chris@696 44
Chris@696 45 int w = getWidth(v, paint) + x0;
Chris@696 46
Chris@696 47 int prevy = -1;
Chris@1260 48
Chris@1260 49 for (int i = 0; i < n; ++i) {
Chris@696 50
Chris@1266 51 int y, ty;
Chris@696 52 bool drawText = true;
Chris@696 53
Chris@1266 54 if (i == n-1 &&
Chris@1266 55 v->getPaintHeight() < paint.fontMetrics().height() * (n*2)) {
Chris@1266 56 if (layer->getScaleUnits() != "") drawText = false;
Chris@1266 57 }
Chris@696 58
Chris@1259 59 double val = ticks[i].value;
Chris@1259 60 QString label = QString::fromStdString(ticks[i].label);
Chris@1258 61
Chris@1266 62 y = layer->getYForValue(v, val);
Chris@696 63
Chris@1266 64 ty = y - paint.fontMetrics().height() + paint.fontMetrics().ascent() + 2;
Chris@1266 65
Chris@1266 66 if (prevy >= 0 && (prevy - y) < paint.fontMetrics().height()) {
Chris@1266 67 continue;
Chris@696 68 }
Chris@696 69
Chris@1266 70 paint.drawLine(w - 5, y, w, y);
Chris@696 71
Chris@696 72 if (drawText) {
Chris@1266 73 paint.drawText(w - paint.fontMetrics().width(label) - 6,
Chris@1266 74 ty, label);
Chris@696 75 }
Chris@696 76
Chris@696 77 prevy = y;
Chris@696 78 }
Chris@696 79 }