From b6ded193ee64ffe67df6d22e7a23aa1ea9e02ec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Tue, 5 Mar 2019 11:14:21 +0100 Subject: QHighDpi::fromNativePixels: use correct screen Calls like QHighDpi::fromNativePixels(point, window) would return device independent coordinates outside any screen in cases where the window is spanning multiple screens and the native point was not on the main screen. Correct this by looking up the correct screen and use its scale factor and origin when scaling coordinates. Task-number: QTBUG-73231 Change-Id: I01a3a42f42121b8d9f4ced2bb0fb023d6ae6bfe7 Reviewed-by: Friedemann Kleint --- src/gui/kernel/qhighdpiscaling.cpp | 50 +++++++++++--------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) (limited to 'src/gui/kernel/qhighdpiscaling.cpp') diff --git a/src/gui/kernel/qhighdpiscaling.cpp b/src/gui/kernel/qhighdpiscaling.cpp index 93fcb1a216..0fea416404 100644 --- a/src/gui/kernel/qhighdpiscaling.cpp +++ b/src/gui/kernel/qhighdpiscaling.cpp @@ -452,52 +452,30 @@ QDpi QHighDpiScaling::logicalDpi() return m_logicalDpi; } -qreal QHighDpiScaling::factor(const QScreen *screen) +QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QPlatformScreen *platformScreen, QPoint *nativePosition) { - // Fast path for when scaling in Qt is not used at all. if (!m_active) - return qreal(1.0); - - // The effective factor for a given screen is the product of the - // screen and global sub-factors - qreal factor = m_factor; - if (screen) - factor *= screenSubfactor(screen->handle()); - return factor; + return { qreal(1), QPoint() }; + const QPlatformScreen *actualScreen = nativePosition ? + platformScreen->screenForPosition(*nativePosition) : platformScreen; + return { m_factor * screenSubfactor(actualScreen), actualScreen->geometry().topLeft() }; } -qreal QHighDpiScaling::factor(const QPlatformScreen *platformScreen) +QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QScreen *screen, QPoint *nativePosition) { if (!m_active) - return qreal(1.0); - - return m_factor * screenSubfactor(platformScreen); + return { qreal(1), QPoint() }; + if (!screen) + return { m_factor, QPoint() }; // the global factor + return scaleAndOrigin(screen->handle(), nativePosition); } -qreal QHighDpiScaling::factor(const QWindow *window) +QHighDpiScaling::ScaleAndOrigin QHighDpiScaling::scaleAndOrigin(const QWindow *window, QPoint *nativePosition) { if (!m_active) - return qreal(1.0); - - return factor(window ? window->screen() : QGuiApplication::primaryScreen()); -} - -QPoint QHighDpiScaling::origin(const QScreen *screen) -{ - return screen->geometry().topLeft(); -} - -QPoint QHighDpiScaling::origin(const QPlatformScreen *platformScreen) -{ - return platformScreen->geometry().topLeft(); -} - -QPoint QHighDpiScaling::origin(const QWindow *window) -{ - if (window && window->isTopLevel() && window->screen()) - return window->screen()->geometry().topLeft(); - - return QPoint(0, 0); + return { qreal(1), QPoint() }; + QScreen *screen = window ? window->screen() : QGuiApplication::primaryScreen(); + return scaleAndOrigin(screen, nativePosition); } #endif //QT_NO_HIGHDPISCALING -- cgit v1.2.3