Mercurial > hg > svgui
comparison widgets/WidgetScale.h @ 1174:3f5c82034f9b more-hidpi
Scale the sizes of a few more UI elements
| author | Chris Cannam |
|---|---|
| date | Mon, 05 Dec 2016 12:04:23 +0000 |
| parents | |
| children | be5e43e2180c |
comparison
equal
deleted
inserted
replaced
| 1173:db90fee630bc | 1174:3f5c82034f9b |
|---|---|
| 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 class WidgetScale | |
| 22 { | |
| 23 public: | |
| 24 /** | |
| 25 * Take a "design pixel" size and scale it for the actual | |
| 26 * display. This is relevant to hi-dpi systems that do not do | |
| 27 * pixel doubling (i.e. Windows and Linux rather than OS/X). | |
| 28 */ | |
| 29 static int scalePixelSize(int pixels) { | |
| 30 | |
| 31 static double ratio = 0.0; | |
| 32 if (ratio == 0.0) { | |
| 33 double baseEm; | |
| 34 #ifdef Q_OS_MAC | |
| 35 baseEm = 17.0; | |
| 36 #else | |
| 37 baseEm = 15.0; | |
| 38 #endif | |
| 39 double em = QFontMetrics(QFont()).height(); | |
| 40 ratio = em / baseEm; | |
| 41 } | |
| 42 | |
| 43 int scaled = int(pixels * ratio + 0.5); | |
| 44 if (pixels != 0 && scaled == 0) scaled = 1; | |
| 45 return scaled; | |
| 46 } | |
| 47 | |
| 48 static QSize scaleQSize(QSize size) { | |
| 49 return QSize(scalePixelSize(size.width()), | |
| 50 scalePixelSize(size.height())); | |
| 51 } | |
| 52 }; | |
| 53 | |
| 54 #endif |
