diff options
Diffstat (limited to 'tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp')
-rw-r--r-- | tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp | 107 |
1 files changed, 96 insertions, 11 deletions
diff --git a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp index 2196724f41..6fe4faec03 100644 --- a/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp +++ b/tests/auto/gui/kernel/qhighdpi/tst_qhighdpi.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <private/qhighdpiscaling_p.h> #include <qpa/qplatformscreen.h> @@ -10,6 +10,7 @@ #include <QJsonObject> #include <QJsonDocument> #include <QStringView> +#include <QSignalSpy> Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests") @@ -35,6 +36,7 @@ private slots: void screenDpiAndDpr_data(); void screenDpiAndDpr(); void screenDpiChange(); + void screenDpiChangeWithWindow(); void environment_QT_SCALE_FACTOR(); void environment_QT_SCREEN_SCALE_FACTORS_data(); void environment_QT_SCREEN_SCALE_FACTORS(); @@ -55,6 +57,8 @@ private slots: void mouseVelocity_data(); void setCursor(); void setCursor_data(); + void setGlobalFactorEmits(); + void setScreenFactorEmits(); }; /// Offscreen platform plugin test setup @@ -65,7 +69,7 @@ const int standardScreenCount = 3; QJsonArray tst_QHighDpi::createStandardScreens(const QList<qreal> &dpiValues) { - Q_ASSERT(dpiValues.count() == standardScreenCount); + Q_ASSERT(dpiValues.size() == standardScreenCount); // Create row of three screens: screen#0 screen#1 screen#2 return QJsonArray { @@ -235,6 +239,9 @@ void tst_QHighDpi::screenDpiAndDpr() QWindow window(screen); QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); + window.setGeometry(QRect(screen->geometry().center(), QSize(10, 10))); + window.create(); + QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); } } @@ -261,12 +268,48 @@ void tst_QHighDpi::screenDpiChange() for (QScreen *screen : app->screens()) { QCOMPARE(screen->devicePixelRatio(), newDpi / standardBaseDpi); QCOMPARE(screen->logicalDotsPerInch(), newDpi / screen->devicePixelRatio()); + QWindow window(screen); QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); + window.create(); + QCOMPARE(window.devicePixelRatio(), screen->devicePixelRatio()); } QCOMPARE(app->devicePixelRatio(), newDpi / standardBaseDpi); } +void tst_QHighDpi::screenDpiChangeWithWindow() +{ + QList<qreal> dpiValues = { 96, 192, 288 }; + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + + // Create windows for screens + QList<QScreen *> screens = app->screens(); + QList<QWindow *> windows; + for (int i = 0; i < screens.count(); ++i) { + QScreen *screen = screens[i]; + QWindow *window = new QWindow(); + windows.append(window); + window->setGeometry(QRect(screen->geometry().center(), QSize(10, 10))); + window->create(); + QCOMPARE(window->devicePixelRatio(), dpiValues[i] / standardBaseDpi); + } + + // Change screen DPI + QList<qreal> newDpiValues = { 288, 192, 96 }; + QJsonValue config = offscreenConfiguration(); + QCborMap map = QCborMap::fromJsonObject(config.toObject()); + for (int i = 0; i < screens.count(); ++i) { + map[QLatin1String("screens")][i][QLatin1String("logicalDpi")] = newDpiValues[i]; + } + setOffscreenConfiguration(map.toJsonObject()); + + // Verify that window DPR changes on Screen DPI change. + for (int i = 0; i < screens.count(); ++i) { + QWindow *window = windows[i]; + QCOMPARE(window->devicePixelRatio(), newDpiValues[i] / standardBaseDpi); + } +} + void tst_QHighDpi::environment_QT_SCALE_FACTOR() { qreal factor = 3.1415; @@ -313,9 +356,10 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() QFETCH(QByteArray, environment); QFETCH(QList<qreal>, expectedDprValues); + qputenv("QT_SCREEN_SCALE_FACTORS", environment); + // Verify that setting QT_SCREEN_SCALE_FACTORS overrides the from-platform-screen-DPI DPR. { - qputenv("QT_SCREEN_SCALE_FACTORS", environment); std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(platformScreenDpi)); int i = 0; for (QScreen *screen : app->screens()) { @@ -327,6 +371,18 @@ void tst_QHighDpi::environment_QT_SCREEN_SCALE_FACTORS() QCOMPARE(window.devicePixelRatio(), expextedDpr); } } + + // Verify that setHighDpiScaleFactorRoundingPolicy applies to QT_SCREEN_SCALE_FACTORS as well + QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); + { + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(platformScreenDpi)); + int i = 0; + for (QScreen *screen : app->screens()) { + qreal expectedRounderDpr = qRound(expectedDprValues[i++]); + qreal windowDpr = QWindow(screen).devicePixelRatio(); + QCOMPARE(windowDpr, expectedRounderDpr); + } + } } void tst_QHighDpi::environment_QT_USE_PHYSICAL_DPI() @@ -361,21 +417,21 @@ void tst_QHighDpi::environment_QT_SCALE_FACTOR_ROUNDING_POLICY() qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough"); { std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - for (int i = 0; i < dpiValues.count(); ++i) + for (int i = 0; i < dpiValues.size(); ++i) QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); } qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "Round"); { std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - for (int i = 0; i < dpiValues.count(); ++i) + for (int i = 0; i < dpiValues.size(); ++i) QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96))); } qunsetenv("QT_SCALE_FACTOR_ROUNDING_POLICY"); { std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - for (int i = 0; i < dpiValues.count(); ++i) + for (int i = 0; i < dpiValues.size(); ++i) QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); } } @@ -386,14 +442,14 @@ void tst_QHighDpi::application_setScaleFactorRoundingPolicy() QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round); { std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - for (int i = 0; i < dpiValues.count(); ++i) + for (int i = 0; i < dpiValues.size(); ++i) QCOMPARE(app->screens()[i]->devicePixelRatio(), qRound(dpiValues[i] / qreal(96))); } QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough); { std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - for (int i = 0; i < dpiValues.count(); ++i) + for (int i = 0; i < dpiValues.size(); ++i) QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); } @@ -402,7 +458,7 @@ void tst_QHighDpi::application_setScaleFactorRoundingPolicy() qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough"); { std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - for (int i = 0; i < dpiValues.count(); ++i) + for (int i = 0; i < dpiValues.size(); ++i) QCOMPARE(app->screens()[i]->devicePixelRatio(), dpiValues[i] / qreal(96)); } } @@ -450,7 +506,7 @@ void tst_QHighDpi::screenAt() QFETCH(QList<qreal>, dpiValues); std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); - QCOMPARE(app->screens().count(), standardScreenCount); // standard setup + QCOMPARE(app->screens().size(), standardScreenCount); // standard setup // Verify that screenAt() returns the correct or no screen for various points, // for all screens. @@ -459,7 +515,7 @@ void tst_QHighDpi::screenAt() qreal dpi = dpiValues[i++]; // veryfy virtualSiblings and that AA_EnableHighDpiScaling is active - QCOMPARE(screen->virtualSiblings().count(), standardScreenCount); + QCOMPARE(screen->virtualSiblings().size(), standardScreenCount); QCOMPARE(screen->geometry().size(), QSize(standardScreenWidth, standardScreenHeight) * (96.0 / dpi)); // test points on screen @@ -798,5 +854,34 @@ void tst_QHighDpi::setCursor() } } +void tst_QHighDpi::setGlobalFactorEmits() +{ + QList<qreal> dpiValues { 96, 96, 96 }; + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + + std::vector<std::unique_ptr<QSignalSpy>> spies; + for (QScreen *screen : app->screens()) + spies.push_back(std::make_unique<QSignalSpy>(screen, &QScreen::geometryChanged)); + + QHighDpiScaling::setGlobalFactor(2); + + for (const auto &spy : spies) + QCOMPARE(spy->count(), 1); + + QHighDpiScaling::setGlobalFactor(1); +} + +void tst_QHighDpi::setScreenFactorEmits() +{ + QList<qreal> dpiValues { 96, 96, 96 }; + std::unique_ptr<QGuiApplication> app(createStandardOffscreenApp(dpiValues)); + + for (QScreen *screen : app->screens()) { + QSignalSpy spy(screen, &QScreen::geometryChanged); + QHighDpiScaling::setScreenFactor(screen, 2); + QCOMPARE(spy.count(), 1); + } +} + #include "tst_qhighdpi.moc" QTEST_APPLESS_MAIN(tst_QHighDpi); |