Mercurial > hg > svgui
comparison layer/PaintAssistant.cpp @ 220:8dc50f57d480
* Make the vertical scale a bit less thtoopid for many linear scale spectra
* Don't forget to reload slice layer properties when loading a session, as well
as spectrum layer (i.e. subclass) properties
author | Chris Cannam |
---|---|
date | Mon, 05 Mar 2007 13:04:52 +0000 |
parents | c2ed5014d4ff |
children | e52ed907cc42 |
comparison
equal
deleted
inserted
replaced
219:1fff998ae4a9 | 220:8dc50f57d480 |
---|---|
23 #include <iostream> | 23 #include <iostream> |
24 | 24 |
25 void | 25 void |
26 PaintAssistant::paintVerticalLevelScale(QPainter &paint, QRect rect, | 26 PaintAssistant::paintVerticalLevelScale(QPainter &paint, QRect rect, |
27 float minVal, float maxVal, | 27 float minVal, float maxVal, |
28 Scale scale, std::vector<int> *vy) | 28 Scale scale, int &mult, |
29 std::vector<int> *vy) | |
29 { | 30 { |
30 static float meterdbs[] = { -40, -30, -20, -15, -10, | 31 static float meterdbs[] = { -40, -30, -20, -15, -10, |
31 -5, -3, -2, -1, -0.5, 0 }; | 32 -5, -3, -2, -1, -0.5, 0 }; |
32 | 33 |
33 int h = rect.height(), w = rect.width(); | 34 int h = rect.height(), w = rect.width(); |
36 | 37 |
37 int lastLabelledY = -1; | 38 int lastLabelledY = -1; |
38 | 39 |
39 int n = 10; | 40 int n = 10; |
40 if (vy) vy->clear(); | 41 if (vy) vy->clear(); |
42 | |
43 float step = 0; | |
44 mult = 1; | |
45 if (scale == LinearScale) { | |
46 step = (maxVal - minVal) / n; | |
47 int round = 0, limit = 10000000; | |
48 do { | |
49 round = int(minVal + step * mult); | |
50 mult *= 10; | |
51 } while (!round && mult < limit); | |
52 if (round) { | |
53 mult /= 10; | |
54 // std::cerr << "\n\nstep goes from " << step; | |
55 step = float(round) / mult; | |
56 n = lrintf((maxVal - minVal) / step); | |
57 if (mult > 1) { | |
58 mult /= 10; | |
59 } | |
60 // std::cerr << " to " << step << " (n = " << n << ")" << std::endl; | |
61 } | |
62 } | |
41 | 63 |
42 for (int i = 0; i <= n; ++i) { | 64 for (int i = 0; i <= n; ++i) { |
43 | 65 |
44 float val = 0.0, nval = 0.0; | 66 float val = 0.0, nval = 0.0; |
45 QString text = ""; | 67 QString text = ""; |
46 | 68 |
47 switch (scale) { | 69 switch (scale) { |
48 | 70 |
49 case LinearScale: | 71 case LinearScale: |
50 val = minVal + ((maxVal - minVal) * i) / n; | 72 val = (minVal + (i * step)); |
51 text = QString("%1").arg(val);//float(i) / n); // ... val | 73 text = QString("%1").arg(mult * val); |
52 /* | |
53 if (i == 0) text = "0.0"; | |
54 else { | |
55 nval = -val; | |
56 if (i == n) text = "1.0"; | |
57 } | |
58 */ | |
59 break; | 74 break; |
60 | 75 |
61 case MeterScale: // ... min, max | 76 case MeterScale: // ... min, max |
62 val = AudioLevel::dB_to_multiplier(meterdbs[i]); | 77 val = AudioLevel::dB_to_multiplier(meterdbs[i]); |
63 text = QString("%1").arg(meterdbs[i]); | 78 text = QString("%1").arg(meterdbs[i]); |
95 abs(y - lastLabelledY) >= textHeight - 1); | 110 abs(y - lastLabelledY) >= textHeight - 1); |
96 | 111 |
97 if (spaceForLabel) { | 112 if (spaceForLabel) { |
98 | 113 |
99 int tx = 3; | 114 int tx = 3; |
100 if (scale != LinearScale) { | 115 // if (scale != LinearScale) { |
116 if (paint.fontMetrics().width(text) < w - 10) { | |
101 tx = w - 10 - paint.fontMetrics().width(text); | 117 tx = w - 10 - paint.fontMetrics().width(text); |
102 } | 118 } |
103 | 119 |
104 int ty = y; | 120 int ty = y; |
105 | 121 |