# HG changeset patch # User Chris Cannam # Date 1480939463 0 # Node ID 3f5c82034f9b8b0eb71ff7343f7fedcfd098530a # Parent db90fee630bc756c3c64a6f904b551acb13e000f Scale the sizes of a few more UI elements diff -r db90fee630bc -r 3f5c82034f9b files.pri --- a/files.pri Wed Nov 30 11:01:39 2016 +0000 +++ b/files.pri Mon Dec 05 12:04:23 2016 +0000 @@ -80,6 +80,7 @@ widgets/TipDialog.h \ widgets/TransformFinder.h \ widgets/UnitConverter.h \ + widgets/WidgetScale.h \ widgets/WindowShapePreview.h \ widgets/WindowTypeSelector.h diff -r db90fee630bc -r 3f5c82034f9b widgets/LEDButton.cpp --- a/widgets/LEDButton.cpp Wed Nov 30 11:01:39 2016 +0000 +++ b/widgets/LEDButton.cpp Mon Dec 05 12:04:23 2016 +0000 @@ -23,6 +23,7 @@ #include "LEDButton.h" +#include "WidgetScale.h" #include #include @@ -279,12 +280,12 @@ QSize LEDButton::sizeHint() const { - return QSize(17, 17); + return WidgetScale::scaleQSize(QSize(17, 17)); } QSize LEDButton::minimumSizeHint() const { - return QSize(17, 17); + return WidgetScale::scaleQSize(QSize(17, 17)); } diff -r db90fee630bc -r 3f5c82034f9b widgets/LEDButton.h --- a/widgets/LEDButton.h Wed Nov 30 11:01:39 2016 +0000 +++ b/widgets/LEDButton.h Mon Dec 05 12:04:23 2016 +0000 @@ -25,8 +25,8 @@ sunken variant. This version also implements a simple button API. */ -#ifndef _LED_BUTTON_H_ -#define _LED_BUTTON_H_ +#ifndef SV_LED_BUTTON_H +#define SV_LED_BUTTON_H #include #include "base/Debug.h" diff -r db90fee630bc -r 3f5c82034f9b widgets/PropertyBox.cpp --- a/widgets/PropertyBox.cpp Wed Nov 30 11:01:39 2016 +0000 +++ b/widgets/PropertyBox.cpp Mon Dec 05 12:04:23 2016 +0000 @@ -27,6 +27,7 @@ #include "AudioDial.h" #include "LEDButton.h" #include "IconLoader.h" +#include "WidgetScale.h" #include "NotifyingCheckBox.h" #include "NotifyingComboBox.h" @@ -196,8 +197,8 @@ if (params->getPlayClipId() != "") { QPushButton *playParamButton = new QPushButton(QIcon(":icons/faders.png"), ""); - playParamButton->setFixedWidth(24); - playParamButton->setFixedHeight(24); + playParamButton->setFixedWidth(WidgetScale::scalePixelSize(24)); + playParamButton->setFixedHeight(WidgetScale::scalePixelSize(24)); layout->addWidget(playParamButton); connect(playParamButton, SIGNAL(clicked()), this, SLOT(editPlayParameters())); @@ -209,8 +210,8 @@ gainDial->setMinimum(-50); gainDial->setMaximum(50); gainDial->setPageStep(1); - gainDial->setFixedWidth(24); - gainDial->setFixedHeight(24); + gainDial->setFixedWidth(WidgetScale::scalePixelSize(24)); + gainDial->setFixedHeight(WidgetScale::scalePixelSize(24)); gainDial->setNotchesVisible(false); gainDial->setObjectName(tr("Playback Gain")); gainDial->setRangeMapper(new LinearRangeMapper @@ -236,8 +237,8 @@ panDial->setMinimum(-50); panDial->setMaximum(50); panDial->setPageStep(1); - panDial->setFixedWidth(24); - panDial->setFixedHeight(24); + panDial->setFixedWidth(WidgetScale::scalePixelSize(24)); + panDial->setFixedHeight(WidgetScale::scalePixelSize(24)); panDial->setNotchesVisible(false); panDial->setToolTip(tr("Playback Pan / Balance")); panDial->setDefaultValue(0); @@ -330,7 +331,7 @@ QIcon icon(IconLoader().load(iconName)); button->setIcon(icon); button->setObjectName(name); - button->setFixedSize(QSize(18, 18)); + button->setFixedSize(WidgetScale::scaleQSize(QSize(18, 18))); } else { button = new NotifyingCheckBox(); button->setObjectName(name); @@ -397,13 +398,13 @@ this, SLOT(mouseLeftWidget())); if (inGroup) { - dial->setFixedWidth(24); - dial->setFixedHeight(24); + dial->setFixedWidth(WidgetScale::scalePixelSize(24)); + dial->setFixedHeight(WidgetScale::scalePixelSize(24)); m_groupLayouts[groupName]->addWidget (dial, 0, m_groupLayouts[groupName]->columnCount()); } else { - dial->setFixedWidth(32); - dial->setFixedHeight(32); + dial->setFixedWidth(WidgetScale::scalePixelSize(32)); + dial->setFixedHeight(WidgetScale::scalePixelSize(32)); m_layout->addWidget(dial, row, 1); QLabel *label = new QLabel(m_mainWidget); connect(dial, SIGNAL(valueChanged(int)), diff -r db90fee630bc -r 3f5c82034f9b widgets/PropertyStack.cpp --- a/widgets/PropertyStack.cpp Wed Nov 30 11:01:39 2016 +0000 +++ b/widgets/PropertyStack.cpp Mon Dec 05 12:04:23 2016 +0000 @@ -25,6 +25,8 @@ #include "widgets/CommandHistory.h" #include "layer/ShowLayerCommand.h" +#include "WidgetScale.h" + #include #include @@ -45,11 +47,9 @@ setTabBar(bar); -#if (QT_VERSION >= 0x0402) setElideMode(Qt::ElideNone); tabBar()->setUsesScrollButtons(true); - tabBar()->setIconSize(QSize(16, 16)); -#endif + tabBar()->setIconSize(WidgetScale::scaleQSize(QSize(16, 16))); repopulate(); diff -r db90fee630bc -r 3f5c82034f9b widgets/WidgetScale.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/WidgetScale.h Mon Dec 05 12:04:23 2016 +0000 @@ -0,0 +1,54 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef SV_WIDGET_SCALE_H +#define SV_WIDGET_SCALE_H + +#include +#include + +class WidgetScale +{ +public: + /** + * Take a "design pixel" size and scale it for the actual + * display. This is relevant to hi-dpi systems that do not do + * pixel doubling (i.e. Windows and Linux rather than OS/X). + */ + static int scalePixelSize(int pixels) { + + static double ratio = 0.0; + if (ratio == 0.0) { + double baseEm; +#ifdef Q_OS_MAC + baseEm = 17.0; +#else + baseEm = 15.0; +#endif + double em = QFontMetrics(QFont()).height(); + ratio = em / baseEm; + } + + int scaled = int(pixels * ratio + 0.5); + if (pixels != 0 && scaled == 0) scaled = 1; + return scaled; + } + + static QSize scaleQSize(QSize size) { + return QSize(scalePixelSize(size.width()), + scalePixelSize(size.height())); + } +}; + +#endif