comparison layer/LogNumericalScale.cpp @ 1276:b4cb11ca8233 horizontal-scale

Branch toward adding horizontal numerical scales to things
author Chris Cannam
date Tue, 01 May 2018 16:14:22 +0100
parents a34a2a25907c
children 82258db96244
comparison
equal deleted inserted replaced
1275:3ca1be2e2c91 1276:b4cb11ca8233
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "LogNumericalScale.h" 16 #include "LogNumericalScale.h"
17 #include "VerticalScaleLayer.h" 17 #include "VerticalScaleLayer.h"
18 #include "HorizontalScaleProvider.h"
19 #include "LayerGeometryProvider.h"
18 20
19 #include "base/LogRange.h" 21 #include "base/LogRange.h"
22 #include "base/ScaleTickIntervals.h"
20 23
21 #include <QPainter> 24 #include <QPainter>
22 25
23 #include <cmath> 26 #include <cmath>
24 27
25 #include "LayerGeometryProvider.h"
26
27 #include "base/ScaleTickIntervals.h"
28
29 int 28 int
30 LogNumericalScale::getWidth(LayerGeometryProvider *, 29 LogNumericalScale::getWidth(LayerGeometryProvider *,
31 QPainter &paint) 30 QPainter &paint,
31 bool horizontal)
32 { 32 {
33 return paint.fontMetrics().width("-000.00") + 10; 33 if (horizontal) {
34 return paint.fontMetrics().height() + 10;
35 } else {
36 return paint.fontMetrics().width("-000.00") + 10;
37 }
34 } 38 }
35 39
36 void 40 void
37 LogNumericalScale::paintVertical(LayerGeometryProvider *v, 41 LogNumericalScale::paintVertical(LayerGeometryProvider *v,
38 const VerticalScaleLayer *layer, 42 const VerticalScaleLayer *layer,
78 } 82 }
79 83
80 prevy = y; 84 prevy = y;
81 } 85 }
82 } 86 }
87
88 void
89 LogNumericalScale::paintHorizontal(LayerGeometryProvider *v,
90 const HorizontalScaleProvider *p,
91 QPainter &paint,
92 QRect r)
93 {
94 int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height();
95
96 paint.drawLine(x0, y0, x1, y0);
97
98 double f0 = p->getFrequencyForX(v, x0);
99 double f1 = p->getFrequencyForX(v, x1);
100
101 int n = 10;
102 auto ticks = ScaleTickIntervals::logarithmic({ f0, f1, n });
103 n = int(ticks.size());
104
105 // int prevx = -1;
106 (void)y1;
107
108 for (int i = 0; i < n; ++i) {
109
110 double val = ticks[i].value;
111 QString label = QString::fromStdString(ticks[i].label);
112 int tw = paint.fontMetrics().width(label);
113
114 cerr << "i = " << i << ", value = " << val << ", tw = " << tw << endl;
115
116 double x = p->getXForFrequency(v, val);
117
118 cerr << "x = " << x << endl;
119
120 }
121 }
122