diff options
| author | Friedemann Kleint <[email protected]> | 2014-02-05 14:59:49 +0100 |
|---|---|---|
| committer | The Qt Project <[email protected]> | 2014-02-07 04:47:04 +0100 |
| commit | b9fe8e30cbd7564d9610e097e219212663e42165 (patch) | |
| tree | c01e98ba781b34741d743afecbefbbc8a551d44f | |
| parent | b2d5e7805abe569a926eb087a75bd903261b734f (diff) | |
QPA: Introduce QPlatformWindow::normalGeometry().
QWidgetWindow stores the normal geometry obtained from the widget when
transiting to other states. This does not work reliably on Windows,
where this geometry is already that of the new state. Instead,
introduce QPlatformWindow::normalGeometry(), add implementation
for Windows and use that in QWidgetWindow.
Task-number: QTBUG-21371
Change-Id: I3819ebaf55b4e7d2f7eef1affe6c20712ba45d7c
Reviewed-by: Joerg Bornemann <[email protected]>
| -rw-r--r-- | src/gui/kernel/qplatformwindow.cpp | 12 | ||||
| -rw-r--r-- | src/gui/kernel/qplatformwindow.h | 1 | ||||
| -rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 29 | ||||
| -rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.h | 1 | ||||
| -rw-r--r-- | src/widgets/kernel/qwidgetwindow.cpp | 29 | ||||
| -rw-r--r-- | src/widgets/kernel/qwidgetwindow_qpa_p.h | 1 |
6 files changed, 61 insertions, 12 deletions
diff --git a/src/gui/kernel/qplatformwindow.cpp b/src/gui/kernel/qplatformwindow.cpp index fe29627c5a9..2364f465b6c 100644 --- a/src/gui/kernel/qplatformwindow.cpp +++ b/src/gui/kernel/qplatformwindow.cpp @@ -127,6 +127,18 @@ QRect QPlatformWindow::geometry() const return d->rect; } +/*! + Returns the geometry of a window in 'normal' state + (neither maximized, fullscreen nor minimized) for saving geometries to + application settings. + + \since 5.3 +*/ +QRect QPlatformWindow::normalGeometry() const +{ + return QRect(); +} + QMargins QPlatformWindow::frameMargins() const { return QMargins(); diff --git a/src/gui/kernel/qplatformwindow.h b/src/gui/kernel/qplatformwindow.h index 7dfbae036fd..0adeb223f10 100644 --- a/src/gui/kernel/qplatformwindow.h +++ b/src/gui/kernel/qplatformwindow.h @@ -84,6 +84,7 @@ public: virtual void setGeometry(const QRect &rect); virtual QRect geometry() const; + virtual QRect normalGeometry() const; virtual QMargins frameMargins() const; diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 5b6fced031a..e9ab902966f 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1234,6 +1234,28 @@ void QWindowsWindow::handleCompositionSettingsChanged() applyBlurBehindWindow(handle()); } +static QRect normalFrameGeometry(HWND hwnd) +{ +#ifndef Q_OS_WINCE + WINDOWPLACEMENT wp; + wp.length = sizeof(WINDOWPLACEMENT); + if (GetWindowPlacement(hwnd, &wp)) + return qrectFromRECT(wp.rcNormalPosition); +#else + Q_UNUSED(hwnd) +#endif + return QRect(); +} + +QRect QWindowsWindow::normalGeometry() const +{ + // Check for fake 'fullscreen' mode. + const bool fakeFullScreen = m_savedFrameGeometry.isValid() && window()->windowState() == Qt::WindowFullScreen; + const QRect frame = fakeFullScreen ? m_savedFrameGeometry : normalFrameGeometry(m_data.hwnd); + const QMargins margins = fakeFullScreen ? QWindowsGeometryHint::frame(m_savedStyle, 0) : frameMargins(); + return frame.isValid() ? frame.marginsRemoved(margins) : frame; +} + void QWindowsWindow::setGeometry(const QRect &rectIn) { QRect rect = rectIn; @@ -1593,10 +1615,9 @@ void QWindowsWindow::setWindowState_sys(Qt::WindowState newState) m_savedStyle = style(); #ifndef Q_OS_WINCE if (oldState == Qt::WindowMinimized) { - WINDOWPLACEMENT wp; - wp.length = sizeof(WINDOWPLACEMENT); - if (GetWindowPlacement(m_data.hwnd, &wp)) - m_savedFrameGeometry = qrectFromRECT(wp.rcNormalPosition); + const QRect nf = normalFrameGeometry(m_data.hwnd); + if (nf.isValid()) + m_savedFrameGeometry = nf; } else { #endif m_savedFrameGeometry = frameGeometry_sys(); diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 3a9516e0e50..99c5761a653 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -162,6 +162,7 @@ public: virtual QSurfaceFormat format() const { return m_format; } virtual void setGeometry(const QRect &rect); virtual QRect geometry() const { return m_data.geometry; } + QRect normalGeometry() const Q_DECL_OVERRIDE; virtual void setVisible(bool visible); bool isVisible() const; diff --git a/src/widgets/kernel/qwidgetwindow.cpp b/src/widgets/kernel/qwidgetwindow.cpp index c7f8e181183..672c4156cdb 100644 --- a/src/widgets/kernel/qwidgetwindow.cpp +++ b/src/widgets/kernel/qwidgetwindow.cpp @@ -50,6 +50,7 @@ #include <private/qwidgetbackingstore_p.h> #include <qpa/qwindowsysteminterface_p.h> #include <qpa/qplatformtheme.h> +#include <qpa/qplatformwindow.h> #include <private/qgesturemanager_p.h> QT_BEGIN_NAMESPACE @@ -547,6 +548,24 @@ void QWidgetWindow::updateGeometry() m_widget->data->fstrut_dirty = false; } +Qt::WindowState effectiveState(Qt::WindowStates state); + +// Store normal geometry used for saving application settings. +void QWidgetWindow::updateNormalGeometry() +{ + QTLWExtra *tle = m_widget->d_func()->maybeTopData(); + if (!tle) + return; + // Ask platform window, default to widget geometry. + QRect normalGeometry; + if (const QPlatformWindow *pw = handle()) + normalGeometry = pw->normalGeometry(); + if (!normalGeometry.isValid() && effectiveState(m_widget->windowState()) == Qt::WindowNoState) + normalGeometry = m_widget->geometry(); + if (normalGeometry.isValid()) + tle->normalGeometry = normalGeometry; +} + void QWidgetWindow::handleMoveEvent(QMoveEvent *event) { updateGeometry(); @@ -692,8 +711,6 @@ void QWidgetWindow::handleExposeEvent(QExposeEvent *event) } } -Qt::WindowState effectiveState(Qt::WindowStates state); - void QWidgetWindow::handleWindowStateChangedEvent(QWindowStateChangeEvent *event) { // QWindow does currently not know 'active'. @@ -712,16 +729,12 @@ void QWidgetWindow::handleWindowStateChangedEvent(QWindowStateChangeEvent *event widgetState |= Qt::WindowMinimized; break; case Qt::WindowMaximized: - if (effectiveState(widgetState) == Qt::WindowNoState) - if (QTLWExtra *tle = m_widget->d_func()->maybeTopData()) - tle->normalGeometry = m_widget->geometry(); + updateNormalGeometry(); widgetState |= Qt::WindowMaximized; widgetState &= ~(Qt::WindowMinimized | Qt::WindowFullScreen); break; case Qt::WindowFullScreen: - if (effectiveState(widgetState) == Qt::WindowNoState) - if (QTLWExtra *tle = m_widget->d_func()->maybeTopData()) - tle->normalGeometry = m_widget->geometry(); + updateNormalGeometry(); widgetState |= Qt::WindowFullScreen; widgetState &= ~(Qt::WindowMinimized); break; diff --git a/src/widgets/kernel/qwidgetwindow_qpa_p.h b/src/widgets/kernel/qwidgetwindow_qpa_p.h index ffde44dd275..8d6f14a6696 100644 --- a/src/widgets/kernel/qwidgetwindow_qpa_p.h +++ b/src/widgets/kernel/qwidgetwindow_qpa_p.h @@ -104,6 +104,7 @@ private slots: private: void updateGeometry(); + void updateNormalGeometry(); enum FocusWidgets { FirstFocusWidget, |
