comparison layer/PaintAssistant.cpp @ 1228:dc6457ac4d07

Add method to scale pen widths for hi-res screens
author Chris Cannam
date Thu, 26 Jan 2017 21:17:19 +0000
parents 1badacff7ab2
children a34a2a25907c
comparison
equal deleted inserted replaced
1227:a8e126fe6a53 1228:dc6457ac4d07
17 17
18 #include "LayerGeometryProvider.h" 18 #include "LayerGeometryProvider.h"
19 19
20 #include "base/AudioLevel.h" 20 #include "base/AudioLevel.h"
21 #include "base/Strings.h" 21 #include "base/Strings.h"
22 #include "base/Debug.h"
22 23
23 #include <QPaintDevice> 24 #include <QPaintDevice>
24 #include <QPainter> 25 #include <QPainter>
25 26
26 #include <iostream> 27 #include <iostream>
260 } else { 261 } else {
261 262
262 std::cerr << "ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl; 263 std::cerr << "ERROR: PaintAssistant::drawVisibleText: Boxed style not yet implemented!" << std::endl;
263 } 264 }
264 } 265 }
266
267 double
268 PaintAssistant::scalePenWidth(double width)
269 {
270 static double ratio = 0.0;
271 if (ratio == 0.0) {
272 double baseEm;
273 #ifdef Q_OS_MAC
274 baseEm = 17.0;
275 #else
276 baseEm = 15.0;
277 #endif
278 double em = QFontMetrics(QFont()).height();
279 ratio = em / baseEm;
280
281 SVDEBUG << "PaintAssistant::scalePenWidth: ratio is " << ratio
282 << " (em = " << em << ")" << endl;
283 }
284
285 if (ratio <= 1.0) {
286 // we only ever scale up in this method
287 return width;
288 }
289
290 if (width <= 0) {
291 // zero-width pen, produce a scaled one-pixel pen
292 return ratio;
293 }
294
295 return width * ratio;
296 }
297
298 QPen
299 PaintAssistant::scalePen(QPen pen)
300 {
301 return QPen(pen.color(), scalePenWidth(pen.width()));
302 }
303
304