Provide convenience method to resize maximized windows

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>
This commit is contained in:
Kevin Ottens 2012-05-21 12:52:26 +02:00 committed by Qt by Nokia
parent 48e104aa1d
commit 600eee0481
2 changed files with 30 additions and 0 deletions

View File

@ -118,6 +118,8 @@ public:
virtual QPlatformCursor *cursor() const;
protected:
void resizeMaximizedWindows();
QScopedPointer<QPlatformScreenPrivate> d_ptr;
private:

View 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