Changeset View
Changeset View
Standalone View
Standalone View
3rdparty/ext_qt/0031-Compute-logical-DPI-on-a-per-screen-basis.patch
- This file was added.
1 | From 676320297d7e5654cbe66fe4bd86125824e05840 Mon Sep 17 00:00:00 2001 | ||||
---|---|---|---|---|---|
2 | From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= <morten.sorvig@qt.io> | ||||
3 | Date: Mon, 25 Apr 2016 09:27:48 +0200 | ||||
4 | Subject: [PATCH 31/36] Compute logical DPI on a per-screen basis | ||||
5 | | ||||
6 | The logical DPI reported to applications is the platform screen | ||||
7 | logical DPI divided by the platform screen scale factor. | ||||
8 | | ||||
9 | Use the screen in question when calculating the DPI instead of | ||||
10 | the values from the main screen. | ||||
11 | | ||||
12 | QHighDpiScaling::logicalDpi now takes a QScreen pointer. | ||||
13 | | ||||
14 | Done-with: Friedemann Kleint <Friedemann.Kleint@qt.io> | ||||
15 | Task-number: QTBUG-53022 | ||||
16 | Change-Id: I0f62b5878c37e3488e9a8cc48aef183ff822d0c4 | ||||
17 | --- | ||||
18 | src/gui/kernel/qhighdpiscaling.cpp | 20 +++++++++----------- | ||||
19 | src/gui/kernel/qhighdpiscaling_p.h | 2 +- | ||||
20 | src/gui/kernel/qscreen.cpp | 6 +++--- | ||||
21 | 3 files changed, 13 insertions(+), 15 deletions(-) | ||||
22 | | ||||
23 | diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp | ||||
24 | index 22e46e0851..541d4f12af 100644 | ||||
25 | --- a/src/gui/kernel/qhighdpiscaling.cpp | ||||
26 | +++ b/src/gui/kernel/qhighdpiscaling.cpp | ||||
27 | @@ -224,7 +224,6 @@ bool QHighDpiScaling::m_usePixelDensity = false; // use scale factor from platfo | ||||
28 | bool QHighDpiScaling::m_pixelDensityScalingActive = false; // pixel density scale factor > 1 | ||||
29 | bool QHighDpiScaling::m_globalScalingActive = false; // global scale factor is active | ||||
30 | bool QHighDpiScaling::m_screenFactorSet = false; // QHighDpiScaling::setScreenFactor has been used | ||||
31 | -QDpi QHighDpiScaling::m_logicalDpi = QDpi(-1,-1); // The scaled logical DPI of the primary screen | ||||
32 | | ||||
33 | /* | ||||
34 | Initializes the QHighDpiScaling global variables. Called before the | ||||
35 | @@ -312,14 +311,6 @@ void QHighDpiScaling::updateHighDpiScaling() | ||||
36 | } | ||||
37 | } | ||||
38 | m_active = m_globalScalingActive || m_screenFactorSet || m_pixelDensityScalingActive; | ||||
39 | - | ||||
40 | - QScreen *primaryScreen = QGuiApplication::primaryScreen(); | ||||
41 | - if (!primaryScreen) | ||||
42 | - return; | ||||
43 | - QPlatformScreen *platformScreen = primaryScreen->handle(); | ||||
44 | - qreal sf = screenSubfactor(platformScreen); | ||||
45 | - QDpi primaryDpi = platformScreen->logicalDpi(); | ||||
46 | - m_logicalDpi = QDpi(primaryDpi.first / sf, primaryDpi.second / sf); | ||||
47 | } | ||||
48 | | ||||
49 | /* | ||||
50 | @@ -405,9 +396,16 @@ qreal QHighDpiScaling::screenSubfactor(const QPlatformScreen *screen) | ||||
51 | return factor; | ||||
52 | } | ||||
53 | | ||||
54 | -QDpi QHighDpiScaling::logicalDpi() | ||||
55 | +QDpi QHighDpiScaling::logicalDpi(const QScreen *screen) | ||||
56 | { | ||||
57 | - return m_logicalDpi; | ||||
58 | + // (Note: m_active test is performed at call site.) | ||||
59 | + if (!screen) | ||||
60 | + return QDpi(96, 96); | ||||
61 | + | ||||
62 | + qreal platformScreenfactor = screenSubfactor(screen->handle()); | ||||
63 | + QDpi platformScreenDpi = screen->handle()->logicalDpi(); | ||||
64 | + return QDpi(platformScreenDpi.first / platformScreenfactor, | ||||
65 | + platformScreenDpi.second / platformScreenfactor); | ||||
66 | } | ||||
67 | | ||||
68 | qreal QHighDpiScaling::factor(const QScreen *screen) | ||||
69 | diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h | ||||
70 | index 83fc9452c5..ecd9ed6515 100644 | ||||
71 | --- a/src/gui/kernel/qhighdpiscaling_p.h | ||||
72 | +++ b/src/gui/kernel/qhighdpiscaling_p.h | ||||
73 | @@ -85,7 +85,7 @@ public: | ||||
74 | static QPoint origin(const QPlatformScreen *platformScreen); | ||||
75 | static QPoint mapPositionFromNative(const QPoint &pos, const QPlatformScreen *platformScreen); | ||||
76 | static QPoint mapPositionToNative(const QPoint &pos, const QPlatformScreen *platformScreen); | ||||
77 | - static QDpi logicalDpi(); | ||||
78 | + static QDpi logicalDpi(const QScreen *screen); | ||||
79 | | ||||
80 | private: | ||||
81 | static qreal screenSubfactor(const QPlatformScreen *screen); | ||||
82 | diff --git a/src/gui/kernel/qscreen.cpp b/src/gui/kernel/qscreen.cpp | ||||
83 | index f208eb02be..82ee62e6b4 100644 | ||||
84 | --- a/src/gui/kernel/qscreen.cpp | ||||
85 | +++ b/src/gui/kernel/qscreen.cpp | ||||
86 | @@ -279,7 +279,7 @@ qreal QScreen::logicalDotsPerInchX() const | ||||
87 | { | ||||
88 | Q_D(const QScreen); | ||||
89 | if (QHighDpiScaling::isActive()) | ||||
90 | - return QHighDpiScaling::logicalDpi().first; | ||||
91 | + return QHighDpiScaling::logicalDpi(this).first; | ||||
92 | return d->logicalDpi.first; | ||||
93 | } | ||||
94 | | ||||
95 | @@ -295,7 +295,7 @@ qreal QScreen::logicalDotsPerInchY() const | ||||
96 | { | ||||
97 | Q_D(const QScreen); | ||||
98 | if (QHighDpiScaling::isActive()) | ||||
99 | - return QHighDpiScaling::logicalDpi().second; | ||||
100 | + return QHighDpiScaling::logicalDpi(this).second; | ||||
101 | return d->logicalDpi.second; | ||||
102 | } | ||||
103 | | ||||
104 | @@ -314,7 +314,7 @@ qreal QScreen::logicalDotsPerInchY() const | ||||
105 | qreal QScreen::logicalDotsPerInch() const | ||||
106 | { | ||||
107 | Q_D(const QScreen); | ||||
108 | - QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi() : d->logicalDpi; | ||||
109 | + QDpi dpi = QHighDpiScaling::isActive() ? QHighDpiScaling::logicalDpi(this) : d->logicalDpi; | ||||
110 | return (dpi.first + dpi.second) * qreal(0.5); | ||||
111 | } | ||||
112 | | ||||
113 | -- | ||||
114 | 2.18.0.windows.1 | ||||
115 | |