comparison layer/PaintAssistant.cpp @ 1216:dc2af6616c83

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:50 +0000
parents 1badacff7ab2
children dc6457ac4d07
comparison
equal deleted inserted replaced
1048:e8102ff5573b 1216:dc2af6616c83
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "PaintAssistant.h" 16 #include "PaintAssistant.h"
17 17
18 #include "LayerGeometryProvider.h"
19
18 #include "base/AudioLevel.h" 20 #include "base/AudioLevel.h"
21 #include "base/Strings.h"
19 22
20 #include <QPaintDevice> 23 #include <QPaintDevice>
21 #include <QPainter> 24 #include <QPainter>
22 25
23 #include <iostream> 26 #include <iostream>
77 case MeterScale: // ... min, max 80 case MeterScale: // ... min, max
78 val = AudioLevel::dB_to_multiplier(meterdbs[i]); 81 val = AudioLevel::dB_to_multiplier(meterdbs[i]);
79 text = QString("%1").arg(meterdbs[i]); 82 text = QString("%1").arg(meterdbs[i]);
80 if (i == n) text = "0dB"; 83 if (i == n) text = "0dB";
81 if (i == 0) { 84 if (i == 0) {
82 text = "-Inf"; 85 text = Strings::minus_infinity;
83 val = 0.0; 86 val = 0.0;
84 } 87 }
85 break; 88 break;
86 89
87 case dBScale: // ... min, max 90 case dBScale: // ... min, max
88 val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10); 91 val = AudioLevel::dB_to_multiplier(-(10*n) + i * 10);
89 text = QString("%1").arg(-(10*n) + i * 10); 92 text = QString("%1").arg(-(10*n) + i * 10);
90 if (i == n) text = "0dB"; 93 if (i == n) text = "0dB";
91 if (i == 0) { 94 if (i == 0) {
92 text = "-Inf"; 95 text = Strings::minus_infinity;
93 val = 0.0; 96 val = 0.0;
94 } 97 }
95 break; 98 break;
96 } 99 }
97 100
205 break; 208 break;
206 } 209 }
207 210
208 return vy; 211 return vy;
209 } 212 }
213
214 void
215 PaintAssistant::drawVisibleText(const LayerGeometryProvider *v,
216 QPainter &paint, int x, int y,
217 QString text, TextStyle style)
218 {
219 if (style == OutlinedText || style == OutlinedItalicText) {
220
221 paint.save();
222
223 if (style == OutlinedItalicText) {
224 QFont f(paint.font());
225 f.setItalic(true);
226 paint.setFont(f);
227 }
228
229 QColor penColour, surroundColour, boxColour;
230
231 penColour = v->getForeground();
232 surroundColour = v->getBackground();
233 boxColour = surroundColour;
234 boxColour.setAlpha(127);
235
236 paint.setPen(Qt::NoPen);
237 paint.setBrush(boxColour);
238
239 QRect r = paint.fontMetrics().boundingRect(text);
240 r.translate(QPoint(x, y));
241 // cerr << "drawVisibleText: r = " << r.x() << "," <<r.y() << " " << r.width() << "x" << r.height() << endl;
242 paint.drawRect(r);
243 paint.setBrush(Qt::NoBrush);
244
245 paint.setPen(surroundColour);
246
247 for (int dx = -1; dx <= 1; ++dx) {
248 for (int dy = -1; dy <= 1; ++dy) {
249 if (!(dx || dy)) continue;
250 paint.drawText(x + dx, y + dy, text);
251 }
252 }
253
254 paint.setPen(penColour);
255
256 paint.drawText(x, y, text);
257
258 paint.restore();
259
260 } else {
261
262 std::cerr << "ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl;
263 }
264 }