Mercurial > hg > svgui
comparison widgets/WidgetScale.h @ 1216:dc2af6616c83
Merge from branch 3.0-integration
author | Chris Cannam |
---|---|
date | Fri, 13 Jan 2017 10:29:50 +0000 |
parents | be5e43e2180c |
children | e7c9650e74a7 |
comparison
equal
deleted
inserted
replaced
1048:e8102ff5573b | 1216:dc2af6616c83 |
---|---|
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 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #ifndef SV_WIDGET_SCALE_H | |
16 #define SV_WIDGET_SCALE_H | |
17 | |
18 #include <QFont> | |
19 #include <QFontMetrics> | |
20 | |
21 #include "base/Debug.h" | |
22 | |
23 class WidgetScale | |
24 { | |
25 public: | |
26 /** | |
27 * Take a "design pixel" size and scale it for the actual | |
28 * display. This is relevant to hi-dpi systems that do not do | |
29 * pixel doubling (i.e. Windows and Linux rather than OS/X). | |
30 */ | |
31 static int scalePixelSize(int pixels) { | |
32 | |
33 static double ratio = 0.0; | |
34 if (ratio == 0.0) { | |
35 double baseEm; | |
36 #ifdef Q_OS_MAC | |
37 baseEm = 17.0; | |
38 #else | |
39 baseEm = 15.0; | |
40 #endif | |
41 double em = QFontMetrics(QFont()).height(); | |
42 ratio = em / baseEm; | |
43 SVDEBUG << "WidgetScale::scalePixelSize: baseEm = " << baseEm | |
44 << ", platform default font height = " << em | |
45 << ", resulting scale factor = " << ratio << endl; | |
46 } | |
47 | |
48 int scaled = int(pixels * ratio + 0.5); | |
49 if (pixels != 0 && scaled == 0) scaled = 1; | |
50 return scaled; | |
51 } | |
52 | |
53 static QSize scaleQSize(QSize size) { | |
54 return QSize(scalePixelSize(size.width()), | |
55 scalePixelSize(size.height())); | |
56 } | |
57 }; | |
58 | |
59 #endif |