Provide convenience method to resize maximized windows
authorKevin Ottens <kevin.ottens.qnx@kdab.com>
Mon, 21 May 2012 10:52:26 +0000 (12:52 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 24 May 2012 12:46:48 +0000 (14:46 +0200)
Maximized/fullscreen windows geometry should follow screen geometry,
so provide a convenience method implementing this behavior. It is
meant to be used in platform plugins where the platform doesn't
automatically resize said windows on screen geometry changes.

Change-Id: Id9128fee1ddf587a7d96aa294d2d1e6eb6d6d11b
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
src/gui/kernel/qplatformscreen.h
src/gui/kernel/qplatformscreen_qpa.cpp

index 5628fe7..d0c4a16 100644 (file)
@@ -118,6 +118,8 @@ public:
     virtual QPlatformCursor *cursor() const;
 
 protected:
+    void resizeMaximizedWindows();
+
     QScopedPointer<QPlatformScreenPrivate> d_ptr;
 
 private:
index 1fd96a8..e40550a 100644 (file)
@@ -272,4 +272,32 @@ QPlatformCursor *QPlatformScreen::cursor() const
     return 0;
 }
 
+/*!
+  Convenience method to resize all the maximized and fullscreen windows
+  of this platform screen.
+*/
+void QPlatformScreen::resizeMaximizedWindows()
+{
+    QList<QWindow*> windows = QGuiApplication::allWindows();
+
+    // 'screen()' still has the old geometry info while 'this' has the new geometry info
+    const QRect oldGeometry = screen()->geometry();
+    const QRect oldAvailableGeometry = screen()->availableGeometry();
+    const QRect newGeometry = geometry();
+    const QRect newAvailableGeometry = availableGeometry();
+
+    // make sure maximized and fullscreen windows are updated
+    for (int i = 0; i < windows.size(); ++i) {
+        QWindow *w = windows.at(i);
+
+        if (platformScreenForWindow(w) != this)
+            continue;
+
+        if (w->windowState() & Qt::WindowFullScreen || w->geometry() == oldGeometry)
+            w->setGeometry(newGeometry);
+        else if (w->windowState() & Qt::WindowMaximized || w->geometry() == oldAvailableGeometry)
+            w->setGeometry(newAvailableGeometry);
+    }
+}
+
 QT_END_NAMESPACE