summaryrefslogtreecommitdiffstats
path: root/tests/manual/highdpi
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2015-04-14 11:05:22 +0200
committerMorten Johan Sørvig <morten.sorvig@digia.com>2015-04-14 11:05:22 +0200
commit7c77febbde4a7e2ebe73579f06baf018cbd192c3 (patch)
tree2684bf2c24b5ec1147f10ed10f7903f05252c587 /tests/manual/highdpi
parentc0fdcaa92eef9b2f8a584f2610d07fb076b28f95 (diff)
Per window scale factor setting
./highdpi --window-scale-factor --mainwindow Also fix a couple of scaling logic bugs.
Diffstat (limited to 'tests/manual/highdpi')
-rw-r--r--tests/manual/highdpi/highdpi.pro2
-rw-r--r--tests/manual/highdpi/main.cpp78
2 files changed, 78 insertions, 2 deletions
diff --git a/tests/manual/highdpi/highdpi.pro b/tests/manual/highdpi/highdpi.pro
index dc1be7888d..f6d49033ce 100644
--- a/tests/manual/highdpi/highdpi.pro
+++ b/tests/manual/highdpi/highdpi.pro
@@ -1,7 +1,7 @@
TEMPLATE = app
TARGET = highdpi
INCLUDEPATH += .
-QT += widgets
+QT += widgets gui-private
CONFIG+=console
CONFIG -= app_bundle
# Input
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index 4be0049fc5..b6305ba1d4 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -53,7 +53,74 @@
#include <QTemporaryDir>
#include <QCommandLineParser>
#include <QCommandLineOption>
+#include <QDebug>
+#include <private/qhighdpiscaling_p.h>
+class ScaleFactorSetter : public QWidget
+{
+Q_OBJECT
+public:
+ ScaleFactorSetter();
+ QLabel *label;
+ QSlider *slider;
+ QLabel *scaleFactorLabel;
+ QHBoxLayout *layout;
+private Q_SLOTS:
+ void scaleFactorChanged(int scaleFactor);
+};
+
+// Shows a slider which sets the scale factor for all windows.
+ScaleFactorSetter::ScaleFactorSetter()
+{
+ label = new QLabel("Scale Factor");
+ slider = new QSlider();
+ slider->setOrientation(Qt::Horizontal);
+ slider->setMinimum(1);
+ slider->setMaximum(40);
+ slider->setValue(10);
+ slider->setTracking(true);
+ slider->setTickInterval(5);
+ slider->setTickPosition(QSlider::TicksBelow);
+ scaleFactorLabel = new QLabel("1.0");
+
+ layout = new QHBoxLayout();
+ layout->addWidget(label);
+ layout->addWidget(slider);
+ layout->addWidget(scaleFactorLabel);
+ setLayout(layout);
+
+ connect(slider, SIGNAL(valueChanged(int)), this, SLOT(scaleFactorChanged(int)));
+}
+
+void ScaleFactorSetter::scaleFactorChanged(int scaleFactor)
+{
+ // slider value is scale factor times ten;
+ qreal scalefactorF = qreal(scaleFactor) / 10.0;
+
+ // update label, add ".0" if needed.
+ QString number = QString::number(scalefactorF);
+ if (!number.contains("."))
+ number.append(".0");
+ scaleFactorLabel->setText(number);
+
+ // set scale factor on all top-level windows
+ QWindowList windows = QGuiApplication::topLevelWindows();
+ foreach (QWindow *window, windows) {
+
+ // skip this controller window
+ if (window == this->windowHandle())
+ continue;
+
+ qDebug() << "set scale factor on" << window;
+ qreal oldFactor = QHighDpiScaling::factor(window);
+ QHighDpiScaling::setWindowFactor(window, scalefactorF);
+ qreal newFactor = QHighDpiScaling::factor(window);
+ qDebug() << "factor was / is" << oldFactor << newFactor;
+
+ // resize window to keep showing the same amount of content.
+ window->resize(window->size() / oldFactor * newFactor);
+ }
+}
class PixmapPainter : public QWidget
{
@@ -70,7 +137,6 @@ public:
QIcon qtIcon;
};
-
PixmapPainter::PixmapPainter()
{
pixmap1X = QPixmap(":/qticon32.png");
@@ -544,6 +610,8 @@ int main(int argc, char **argv)
parser.setApplicationDescription("High DPI tester");
parser.addHelpOption();
parser.addVersionOption();
+ QCommandLineOption scaleFactorOption("window-scale-factor", "Show Scale Factor Slider");
+ parser.addOption(scaleFactorOption);
QCommandLineOption pixmapPainterOption("pixmap", "Test pixmap painter");
parser.addOption(pixmapPainterOption);
QCommandLineOption labelOption("label", "Test Labels");
@@ -568,6 +636,12 @@ int main(int argc, char **argv)
parser.process(app);
+ QScopedPointer<ScaleFactorSetter> scaleFactorSetter;
+ if (parser.isSet(scaleFactorOption)) {
+ scaleFactorSetter.reset(new ScaleFactorSetter);
+ scaleFactorSetter->show();
+ }
+
QScopedPointer<PixmapPainter> pixmapPainter;
if (parser.isSet(pixmapPainterOption)) {
pixmapPainter.reset(new PixmapPainter);
@@ -636,3 +710,5 @@ int main(int argc, char **argv)
return app.exec();
}
+
+#include "main.moc"