Mercurial > hg > svgui
comparison widgets/WidgetScale.h @ 1324:13d9b422f7fe zoom
Merge from default branch
| author | Chris Cannam |
|---|---|
| date | Mon, 17 Sep 2018 13:51:31 +0100 |
| parents | e7c9650e74a7 |
| children |
comparison
equal
deleted
inserted
replaced
| 1183:57d192e26331 | 1324:13d9b422f7fe |
|---|---|
| 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 if (ratio < 1.0) { | |
| 47 SVDEBUG << "WidgetScale::scalePixelSize: rounding up to 1.0" | |
| 48 << endl; | |
| 49 ratio = 1.0; | |
| 50 } | |
| 51 } | |
| 52 | |
| 53 int scaled = int(pixels * ratio + 0.5); | |
| 54 if (pixels != 0 && scaled == 0) scaled = 1; | |
| 55 return scaled; | |
| 56 } | |
| 57 | |
| 58 static QSize scaleQSize(QSize size) { | |
| 59 return QSize(scalePixelSize(size.width()), | |
| 60 scalePixelSize(size.height())); | |
| 61 } | |
| 62 }; | |
| 63 | |
| 64 #endif |
