High-dpi: Add test for setting the scale factor rounding policy
Test setting both via QGuiApplication property and environment. Change-Id: Iaccc920adb6294d610b02d4c844aa5b15eb7eecd Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
parent
e1c8ad359d
commit
bc6dea891e
@ -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<qreal> dpiValues { 96, 144, 192 };
|
||||
|
||||
qputenv("QT_SCALE_FACTOR_ROUNDING_POLICY", "PassThrough");
|
||||
{
|
||||
std::unique_ptr<QGuiApplication> 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<QGuiApplication> 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<QGuiApplication> 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<qreal> dpiValues { 96, 144, 192 };
|
||||
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::Round);
|
||||
{
|
||||
std::unique_ptr<QGuiApplication> 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<QGuiApplication> 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<QGuiApplication> 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<qreal> dpiValues { 40, 60, 95 };
|
||||
|
Loading…
Reference in New Issue
Block a user