Mercurial > hg > svgui
annotate widgets/WidgetScale.h @ 1177:916b62baf7ac levelpanwidget
Add monitoring to level-pan widget (though not well, yet)
author | Chris Cannam |
---|---|
date | Mon, 05 Dec 2016 15:47:32 +0000 |
parents | 3f5c82034f9b |
children | be5e43e2180c |
rev | line source |
---|---|
Chris@1174 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
Chris@1174 | 2 |
Chris@1174 | 3 /* |
Chris@1174 | 4 Sonic Visualiser |
Chris@1174 | 5 An audio file viewer and annotation editor. |
Chris@1174 | 6 Centre for Digital Music, Queen Mary, University of London. |
Chris@1174 | 7 |
Chris@1174 | 8 This program is free software; you can redistribute it and/or |
Chris@1174 | 9 modify it under the terms of the GNU General Public License as |
Chris@1174 | 10 published by the Free Software Foundation; either version 2 of the |
Chris@1174 | 11 License, or (at your option) any later version. See the file |
Chris@1174 | 12 COPYING included with this distribution for more information. |
Chris@1174 | 13 */ |
Chris@1174 | 14 |
Chris@1174 | 15 #ifndef SV_WIDGET_SCALE_H |
Chris@1174 | 16 #define SV_WIDGET_SCALE_H |
Chris@1174 | 17 |
Chris@1174 | 18 #include <QFont> |
Chris@1174 | 19 #include <QFontMetrics> |
Chris@1174 | 20 |
Chris@1174 | 21 class WidgetScale |
Chris@1174 | 22 { |
Chris@1174 | 23 public: |
Chris@1174 | 24 /** |
Chris@1174 | 25 * Take a "design pixel" size and scale it for the actual |
Chris@1174 | 26 * display. This is relevant to hi-dpi systems that do not do |
Chris@1174 | 27 * pixel doubling (i.e. Windows and Linux rather than OS/X). |
Chris@1174 | 28 */ |
Chris@1174 | 29 static int scalePixelSize(int pixels) { |
Chris@1174 | 30 |
Chris@1174 | 31 static double ratio = 0.0; |
Chris@1174 | 32 if (ratio == 0.0) { |
Chris@1174 | 33 double baseEm; |
Chris@1174 | 34 #ifdef Q_OS_MAC |
Chris@1174 | 35 baseEm = 17.0; |
Chris@1174 | 36 #else |
Chris@1174 | 37 baseEm = 15.0; |
Chris@1174 | 38 #endif |
Chris@1174 | 39 double em = QFontMetrics(QFont()).height(); |
Chris@1174 | 40 ratio = em / baseEm; |
Chris@1174 | 41 } |
Chris@1174 | 42 |
Chris@1174 | 43 int scaled = int(pixels * ratio + 0.5); |
Chris@1174 | 44 if (pixels != 0 && scaled == 0) scaled = 1; |
Chris@1174 | 45 return scaled; |
Chris@1174 | 46 } |
Chris@1174 | 47 |
Chris@1174 | 48 static QSize scaleQSize(QSize size) { |
Chris@1174 | 49 return QSize(scalePixelSize(size.width()), |
Chris@1174 | 50 scalePixelSize(size.height())); |
Chris@1174 | 51 } |
Chris@1174 | 52 }; |
Chris@1174 | 53 |
Chris@1174 | 54 #endif |