From 3f60bd305ad3b094356750c21e253704bbe62681 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 4 Jul 2014 10:39:19 +0200 Subject: Add convenience function for checking screen changes to QPlatformWindow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add function returning the screen for a new geometry for geometry change events. This ensures that the checking is done in platform screen coordinates (which might differ from QScreen coordinates due to high-DPI changes) and also that no screen changes are emitted for child windows. Change-Id: I406750f59f006f834c386d09c0c85a804014924a Reviewed-by: Jørgen Lind Reviewed-by: Laszlo Agocs --- src/gui/kernel/qplatformwindow.cpp | 23 +++++++++++++++++++++++ src/gui/kernel/qplatformwindow.h | 1 + 2 files changed, 24 insertions(+) (limited to 'src/gui') diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index faaf418522..bb7b690992 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -473,6 +473,29 @@ QString QPlatformWindow::formatWindowTitle(const QString &title, const QString & return fullTitle; } +/*! + Helper function for finding the new screen for \a newGeometry in response to + a geometry changed event. Returns the new screen if the window was moved to + another virtual sibling. If the screen changes, the platform plugin should call + QWindowSystemInterface::handleWindowScreenChanged(). + \note: The current screen will always be returned for child windows since + they should never signal screen changes. + + \since 5.4 + \sa QWindowSystemInterface::handleWindowScreenChanged() +*/ +QPlatformScreen *QPlatformWindow::screenForGeometry(const QRect &newGeometry) const +{ + QPlatformScreen *currentScreen = screen(); + if (!parent() && !currentScreen->geometry().intersects(newGeometry)) { + Q_FOREACH (QPlatformScreen* screen, currentScreen->virtualSiblings()) { + if (screen->geometry().intersects(newGeometry)) + return screen; + } + } + return currentScreen; +} + /*! Reimplement this method to set whether the window demands attention (for example, by flashing the taskbar icon) depending on \a enabled. diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index 39bd8324a0..8f0e5ff352 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -139,6 +139,7 @@ public: protected: static QString formatWindowTitle(const QString &title, const QString &separator); + QPlatformScreen *screenForGeometry(const QRect &newGeometry) const; QScopedPointer d_ptr; private: -- cgit v1.2.3