Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:thiagomacieira:branches:openSUSE:Factory
libqt5-qtbase
3005-QHighDpi-window-geometry-scaling-functions...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 3005-QHighDpi-window-geometry-scaling-functions.patch of Package libqt5-qtbase
From 098bbab2101d8fc458df08ed1d0b6fa072442ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= <morten.sorvig@qt.io> Date: Wed, 27 May 2020 10:57:08 +0200 Subject: [PATCH 3005/3009] QHighDpi: window geometry scaling functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add functions which scales window geometry: framNativeWindowGeometry() toNativeWindowGeometry() These correctly handles top-level and child windows, where top-level window positions scale around the screen origin while child window positions scale around (0, 0). Modify call cites to use the new functions. We no longer need the isTopLevel checks at the call site. Change-Id: I0158672d46a3f52dfc7d37d021fc5cebd7859200 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> (cherry picked from commit 95bce5b185ddc736405a952b9132e5c8f51275aa) --- src/gui/kernel/qhighdpiscaling_p.h | 16 ++++++++++++++++ src/gui/kernel/qplatformwindow.cpp | 8 ++++---- src/gui/kernel/qwindow.cpp | 10 ++++------ src/gui/kernel/qwindowsysteminterface.cpp | 8 ++------ .../input/evdevtouch/qevdevtouchhandler.cpp | 2 +- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/gui/kernel/qhighdpiscaling_p.h b/src/gui/kernel/qhighdpiscaling_p.h index 2797ad590e..82d424183c 100644 --- a/src/gui/kernel/qhighdpiscaling_p.h +++ b/src/gui/kernel/qhighdpiscaling_p.h @@ -279,6 +279,22 @@ T toNativeGlobalPosition(const T &value, const C *context) return scale(value, so.factor, so.origin); } +template <typename T, typename C> +T fromNativeWindowGeometry(const T &value, const C *context) +{ + QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context); + QPoint effectiveOrigin = (context && context->isTopLevel()) ? so.origin : QPoint(0,0); + return scale(value, qreal(1) / so.factor, effectiveOrigin); +} + +template <typename T, typename C> +T toNativeWindowGeometry(const T &value, const C *context) +{ + QHighDpiScaling::ScaleAndOrigin so = QHighDpiScaling::scaleAndOrigin(context); + QPoint effectiveOrigin = (context && context->isTopLevel()) ? so.origin : QPoint(0,0); + return scale(value, so.factor, effectiveOrigin); +} + template <typename T> inline T fromNative(const T &value, qreal scaleFactor, QPoint origin = QPoint(0, 0)) { diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index fc736033c2..cb9bb0eb4e 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -835,7 +835,7 @@ QSize QPlatformWindow::windowSizeIncrement() const */ QRect QPlatformWindow::windowGeometry() const { - return QHighDpi::toNativePixels(window()->geometry(), window()); + return QHighDpi::toNativeWindowGeometry(window()->geometry(), window()); } /*! @@ -843,7 +843,7 @@ QRect QPlatformWindow::windowGeometry() const */ QRect QPlatformWindow::windowFrameGeometry() const { - return QHighDpi::toNativePixels(window()->frameGeometry(), window()); + return QHighDpi::toNativeWindowGeometry(window()->frameGeometry(), window()); } /*! @@ -854,10 +854,10 @@ QRect QPlatformWindow::windowFrameGeometry() const QRectF QPlatformWindow::closestAcceptableGeometry(const QWindow *qWindow, const QRectF &nativeRect) { - const QRectF rectF = QHighDpi::fromNativePixels(nativeRect, qWindow); + const QRectF rectF = QHighDpi::fromNativeWindowGeometry(nativeRect, qWindow); const QRectF correctedGeometryF = qt_window_private(const_cast<QWindow *>(qWindow))->closestAcceptableGeometry(rectF); return !correctedGeometryF.isEmpty() && rectF != correctedGeometryF - ? QHighDpi::toNativePixels(correctedGeometryF, qWindow) : nativeRect; + ? QHighDpi::toNativeWindowGeometry(correctedGeometryF, qWindow) : nativeRect; } QRectF QPlatformWindow::windowClosestAcceptableGeometry(const QRectF &nativeRect) const diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp index fd89e479b8..e79ac2d6de 100644 --- a/src/gui/kernel/qwindow.cpp +++ b/src/gui/kernel/qwindow.cpp @@ -1789,9 +1789,7 @@ QRect QWindow::geometry() const Q_D(const QWindow); if (d->platformWindow) { const auto nativeGeometry = d->platformWindow->geometry(); - return isTopLevel() - ? QHighDpi::fromNativePixels(nativeGeometry, this) - : QHighDpi::fromNativeLocalPosition(nativeGeometry, this); + return QHighDpi::fromNativeWindowGeometry(nativeGeometry, this); } return d->geometry; } @@ -1821,7 +1819,7 @@ QRect QWindow::frameGeometry() const Q_D(const QWindow); if (d->platformWindow) { QMargins m = frameMargins(); - return QHighDpi::fromNativePixels(d->platformWindow->geometry(), this).adjusted(-m.left(), -m.top(), m.right(), m.bottom()); + return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry(), this).adjusted(-m.left(), -m.top(), m.right(), m.bottom()); } return d->geometry; } @@ -1838,7 +1836,7 @@ QPoint QWindow::framePosition() const Q_D(const QWindow); if (d->platformWindow) { QMargins margins = frameMargins(); - return QHighDpi::fromNativePixels(d->platformWindow->geometry().topLeft(), this) - QPoint(margins.left(), margins.top()); + return QHighDpi::fromNativeWindowGeometry(d->platformWindow->geometry().topLeft(), this) - QPoint(margins.left(), margins.top()); } return d->geometry.topLeft(); } @@ -1856,7 +1854,7 @@ void QWindow::setFramePosition(const QPoint &point) d->positionPolicy = QWindowPrivate::WindowFrameInclusive; d->positionAutomatic = false; if (d->platformWindow) { - d->platformWindow->setGeometry(QHighDpi::toNativePixels(QRect(point, size()), this)); + d->platformWindow->setGeometry(QHighDpi::toNativeWindowGeometry(QRect(point, size()), this)); } else { d->geometry.moveTopLeft(point); } diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index de0a199b87..e05ecece62 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -299,18 +299,14 @@ QWindowSystemInterfacePrivate::GeometryChangeEvent::GeometryChangeEvent(QWindow { if (const QPlatformWindow *pw = window->handle()) { const auto nativeGeometry = pw->QPlatformWindow::geometry(); - requestedGeometry = window->isTopLevel() - ? QHighDpi::fromNativePixels(nativeGeometry, window) - : QHighDpi::fromNativeLocalPosition(nativeGeometry, window); + requestedGeometry = QHighDpi::fromNativeWindowGeometry(nativeGeometry, window); } } QT_DEFINE_QPA_EVENT_HANDLER(void, handleGeometryChange, QWindow *window, const QRect &newRect) { Q_ASSERT(window); - const auto newRectDi = window->isTopLevel() - ? QHighDpi::fromNativePixels(newRect, window) - : QHighDpi::fromNativeLocalPosition(newRect, window); + const auto newRectDi = QHighDpi::fromNativeWindowGeometry(newRect, window); auto e = new QWindowSystemInterfacePrivate::GeometryChangeEvent(window, newRectDi); if (window->handle()) { // Persist the new geometry so that QWindow::geometry() can be queried in the resize event diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index f57e1540e0..0db46f8b35 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -729,7 +729,7 @@ QRect QEvdevTouchScreenData::screenGeometry() const { if (m_forceToActiveWindow) { QWindow *win = QGuiApplication::focusWindow(); - return win ? QHighDpi::toNativePixels(win->geometry(), win) : QRect(); + return win ? QHighDpi::toNativeWindowGeometry(win->geometry(), win) : QRect(); } // Now it becomes tricky. Traditionally we picked the primaryScreen() -- 2.29.2
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor