Mercurial > hg > svgui
comparison layer/HorizontalFrequencyScale.cpp @ 1281:fc9d9f1103fa horizontal-scale
Provide linear horizontal scale in spectrum as well as log; fix bin positioning and colour scale property box updating; ensure proper background colour and visibility of peak lines
author | Chris Cannam |
---|---|
date | Thu, 03 May 2018 15:15:15 +0100 |
parents | |
children | f2525e6cbdf1 |
comparison
equal
deleted
inserted
replaced
1280:34394e8c2942 | 1281:fc9d9f1103fa |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006-2018 Chris Cannam and QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "HorizontalFrequencyScale.h" | |
17 #include "HorizontalScaleProvider.h" | |
18 #include "LayerGeometryProvider.h" | |
19 | |
20 #include "base/ScaleTickIntervals.h" | |
21 | |
22 #include <QPainter> | |
23 | |
24 #include <cmath> | |
25 | |
26 int | |
27 HorizontalFrequencyScale::getHeight(LayerGeometryProvider *, | |
28 QPainter &paint) | |
29 { | |
30 return paint.fontMetrics().height() + 10; | |
31 } | |
32 | |
33 void | |
34 HorizontalFrequencyScale::paintScale(LayerGeometryProvider *v, | |
35 const HorizontalScaleProvider *p, | |
36 QPainter &paint, | |
37 QRect r, | |
38 bool logarithmic) | |
39 { | |
40 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); | |
41 | |
42 paint.drawLine(x0, y0, x1, y0); | |
43 | |
44 double f0 = p->getFrequencyForX(v, x0 ? x0 : 1); | |
45 double f1 = p->getFrequencyForX(v, x1); | |
46 | |
47 int n = 20; | |
48 | |
49 auto ticks = | |
50 logarithmic ? | |
51 ScaleTickIntervals::logarithmic({ f0, f1, n }) : | |
52 ScaleTickIntervals::linear({ f0, f1, n }); | |
53 | |
54 n = int(ticks.size()); | |
55 | |
56 int marginx = -1; | |
57 | |
58 for (int i = 0; i < n; ++i) { | |
59 | |
60 double val = ticks[i].value; | |
61 QString label = QString::fromStdString(ticks[i].label); | |
62 int tw = paint.fontMetrics().width(label); | |
63 | |
64 int x = int(round(p->getXForFrequency(v, val))); | |
65 | |
66 if (x < marginx) continue; | |
67 | |
68 //!!! todo: pixel scaling (here & elsewhere in these classes) | |
69 | |
70 paint.drawLine(x, y0, x, y1); | |
71 | |
72 paint.drawText(x + 5, y0 + paint.fontMetrics().ascent() + 5, label); | |
73 | |
74 marginx = x + tw + 10; | |
75 } | |
76 } | |
77 |