Chris@1174: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1174: Chris@1174: /* Chris@1174: Sonic Visualiser Chris@1174: An audio file viewer and annotation editor. Chris@1174: Centre for Digital Music, Queen Mary, University of London. Chris@1174: Chris@1174: This program is free software; you can redistribute it and/or Chris@1174: modify it under the terms of the GNU General Public License as Chris@1174: published by the Free Software Foundation; either version 2 of the Chris@1174: License, or (at your option) any later version. See the file Chris@1174: COPYING included with this distribution for more information. Chris@1174: */ Chris@1174: Chris@1174: #ifndef SV_WIDGET_SCALE_H Chris@1174: #define SV_WIDGET_SCALE_H Chris@1174: Chris@1174: #include Chris@1174: #include Chris@1174: Chris@1174: class WidgetScale Chris@1174: { Chris@1174: public: Chris@1174: /** Chris@1174: * Take a "design pixel" size and scale it for the actual Chris@1174: * display. This is relevant to hi-dpi systems that do not do Chris@1174: * pixel doubling (i.e. Windows and Linux rather than OS/X). Chris@1174: */ Chris@1174: static int scalePixelSize(int pixels) { Chris@1174: Chris@1174: static double ratio = 0.0; Chris@1174: if (ratio == 0.0) { Chris@1174: double baseEm; Chris@1174: #ifdef Q_OS_MAC Chris@1174: baseEm = 17.0; Chris@1174: #else Chris@1174: baseEm = 15.0; Chris@1174: #endif Chris@1174: double em = QFontMetrics(QFont()).height(); Chris@1174: ratio = em / baseEm; Chris@1174: } Chris@1174: Chris@1174: int scaled = int(pixels * ratio + 0.5); Chris@1174: if (pixels != 0 && scaled == 0) scaled = 1; Chris@1174: return scaled; Chris@1174: } Chris@1174: Chris@1174: static QSize scaleQSize(QSize size) { Chris@1174: return QSize(scalePixelSize(size.width()), Chris@1174: scalePixelSize(size.height())); Chris@1174: } Chris@1174: }; Chris@1174: Chris@1174: #endif