summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2016-06-02 09:52:21 +0200
committerMorten Johan Sørvig <morten.sorvig@qt.io>2019-08-23 03:40:53 +0200
commit70a893e9bee7c1b8994a1218038a302e406d0aa3 (patch)
tree11e7aa5b4eca9178fb2e6370a36291eb07ce84cb /src/gui
parent3e5362bfa123cfc0b56c77d5e34ad63ea6e9f89a (diff)
Move QT_FONT_DPI to cross-platform code
This makes it possible to test the effects of setting Qt::AA_HighDpiScaling/QT_AUTO_SCREEN_SCALE_FACTOR, with different DPI values on all platforms. This also makes it possible to access the actual DPI values reported by the OS/WS via the QPlatformScreen API. A drawback is that there is no single place to check the environment variable; currently done in three places. This may be further simplified later on. Done-with: Friedemann Kleint <Friedemann.Kleint@qt.io> Task-number: QTBUG-53022 Change-Id: Idd6463219d3ae58fe0ab72c17686cce2eb9dbadd Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qhighdpiscaling.cpp4
-rw-r--r--src/gui/kernel/qplatformscreen.cpp8
-rw-r--r--src/gui/kernel/qplatformscreen.h2
-rw-r--r--src/gui/kernel/qscreen.cpp7
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp4
5 files changed, 19 insertions, 6 deletions
diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp
index 7ffbfbe1e5..c8a2634929 100644
--- a/src/gui/kernel/qhighdpiscaling.cpp
+++ b/src/gui/kernel/qhighdpiscaling.cpp
@@ -276,7 +276,7 @@ qreal QHighDpiScaling::rawScaleFactor(const QPlatformScreen *screen)
qreal platformPhysicalDpi = screen->screen()->physicalDotsPerInch();
factor = qreal(platformPhysicalDpi) / qreal(platformBaseDpi.first);
} else {
- QDpi platformLogicalDpi = screen->logicalDpi();
+ const QDpi platformLogicalDpi = QPlatformScreen::overrideDpi(screen->logicalDpi());
factor = qreal(platformLogicalDpi.first) / qreal(platformBaseDpi.first);
}
@@ -629,7 +629,7 @@ QDpi QHighDpiScaling::logicalDpi(const QScreen *screen)
return QDpi(96, 96);
if (!m_usePixelDensity)
- return screen->handle()->logicalDpi();
+ return QPlatformScreen::overrideDpi(screen->handle()->logicalDpi());
const qreal scaleFactor = rawScaleFactor(screen->handle());
const qreal roundedScaleFactor = roundScaleFactor(scaleFactor);
diff --git a/src/gui/kernel/qplatformscreen.cpp b/src/gui/kernel/qplatformscreen.cpp
index fc405dee00..f3213bf5ea 100644
--- a/src/gui/kernel/qplatformscreen.cpp
+++ b/src/gui/kernel/qplatformscreen.cpp
@@ -193,6 +193,14 @@ QDpi QPlatformScreen::logicalDpi() const
25.4 * s.height() / ps.height());
}
+// Helper function for accessing the platform screen logical dpi
+// which accounts for QT_FONT_DPI.
+QPair<qreal, qreal> QPlatformScreen::overrideDpi(const QPair<qreal, qreal> &in)
+{
+ static const int overrideDpi = qEnvironmentVariableIntValue("QT_FONT_DPI");
+ return overrideDpi > 0 ? QDpi(overrideDpi, overrideDpi) : in;
+}
+
/*!
Reimplement to return the base logical DPI for the platform. This
DPI value should correspond to a standard-DPI (1x) display. The
diff --git a/src/gui/kernel/qplatformscreen.h b/src/gui/kernel/qplatformscreen.h
index 1012d97324..d7378aed51 100644
--- a/src/gui/kernel/qplatformscreen.h
+++ b/src/gui/kernel/qplatformscreen.h
@@ -161,6 +161,8 @@ public:
// The platform screen's geometry in device independent coordinates
QRect deviceIndependentGeometry() const;
+ static QDpi overrideDpi(const QDpi &in);
+
protected:
void resizeMaximizedWindows();
diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp
index e437678221..7adf3db1b8 100644
--- a/src/gui/kernel/qscreen.cpp
+++ b/src/gui/kernel/qscreen.cpp
@@ -84,8 +84,11 @@ void QScreenPrivate::setPlatformScreen(QPlatformScreen *screen)
platformScreen->d_func()->screen = q;
orientation = platformScreen->orientation();
geometry = platformScreen->deviceIndependentGeometry();
- availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(), QHighDpiScaling::factor(platformScreen), geometry.topLeft());
- logicalDpi = platformScreen->logicalDpi();
+ availableGeometry = QHighDpi::fromNative(platformScreen->availableGeometry(),
+ QHighDpiScaling::factor(platformScreen), geometry.topLeft());
+
+ logicalDpi = QPlatformScreen::overrideDpi(platformScreen->logicalDpi());
+
refreshRate = platformScreen->refreshRate();
// safeguard ourselves against buggy platform behavior...
if (refreshRate < 1.0)
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 4b8cb3646a..40a298226a 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -857,8 +857,8 @@ void QWindowSystemInterface::handleScreenGeometryChange(QScreen *screen, const Q
void QWindowSystemInterface::handleScreenLogicalDotsPerInchChange(QScreen *screen, qreal dpiX, qreal dpiY)
{
- QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent *e =
- new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, dpiX, dpiY); // ### tja
+ const QDpi effectiveDpi = QPlatformScreen::overrideDpi(QDpi{dpiX, dpiY});
+ auto e = new QWindowSystemInterfacePrivate::ScreenLogicalDotsPerInchEvent(screen, effectiveDpi.first, effectiveDpi.second);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}