From bc6dea891ea3bff991cf6a080aed46baebdb0cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Thu, 19 May 2022 22:23:36 +0200 Subject: [PATCH] High-dpi: Add test for setting the scale factor rounding policy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test setting both via QGuiApplication property and environment. Change-Id: Iaccc920adb6294d610b02d4c844aa5b15eb7eecd Reviewed-by: Tor Arne Vestbø --- .../auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index 5f0d226124c..f221c9db909 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -39,6 +39,8 @@ private slots: void environment_QT_SCREEN_SCALE_FACTORS_data(); void environment_QT_SCREEN_SCALE_FACTORS(); void environment_QT_USE_PHYSICAL_DPI(); + void environment_QT_SCALE_FACTOR_ROUNDING_POLICY(); + void application_setScaleFactorRoundingPolicy(); void screenAt_data(); void screenAt(); void screenGeometry_data(); @@ -187,6 +189,7 @@ void tst_QHighDpi::cleanup() qunsetenv("QT_SCALE_FACTOR"); qunsetenv("QT_SCREEN_SCALE_FACTORS"); qunsetenv("QT_USE_PHYSICAL_DPI"); + qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY"); } void tst_QHighDpi::qhighdpiscaling_data() @@ -351,6 +354,59 @@ void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI() } } +void tst_QHighDpi::environment_QT_SCALE_FACTOR_ROUNDING_POLICY() +{ + QList dpiValues { 96, 144, 192 }; + + qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough"); + { + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.count(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } + + qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "Round"); + { + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.count(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96))); + } + + qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY"); + { + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.count(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } +} + +void tst_QHighDpi::application_setScaleFactorRoundingPolicy() +{ + QList dpiValues { 96, 144, 192 }; + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); + { + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.count(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96))); + } + + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); + { + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.count(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } + + // Verify that environment overrides app setting + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); + qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough"); + { + std::unique_ptr app(createStandardOffscreenApp(dpiValues)); + for (int i = 0; i < dpiValues.count(); ++i) + QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); + } +} + void tst_QHighDpi::minimumDpr() { QList dpiValues { 40, 60, 95 };