Patch toward fixing tst_QWidget::windowState().

In QWidget::setWindowState() there was some code to emulate window
states when they're not supported by the backend, by hiding the window
on minimize or using the screen geometry and the frameless window hint
to manually try to make a window fullscreen.

However, some of this code was being run even when the backend does
support setting window states, specifically calling setParent(0) to
force a re-creation of the platform window and calling show(). These led
to the window getting the wrong position after being minimized or
fullscreen and going back to the normal state.

Apart from storing the normal geometry of a widget when going away from
the normal state we shouldn't do any magic when the call to
QPlatformWindow::setWindowState() succeeds.

tst_QWidget::windowState() still fails due to calling move() to set the
position of the widget including the frame, when QWindow currently only
supports setting the position of the widget excluding the frame.

Change-Id: I1c1a337d3c15f14c1c842bd1e347f94e6b67d7eb
Reviewed-on: http://codereview.qt-project.org/5367
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Samuel Rødal 2011-09-22 09:05:11 +02:00 committed by Qt by Nokia
parent 5fb67c1dac
commit 294df24621
2 changed files with 40 additions and 12 deletions

View File

@ -526,21 +526,23 @@ void QWidget::setWindowState(Qt::WindowStates newstate)
Qt::WindowState oldEffectiveState = effectiveState(oldstate);
if (isWindow() && newEffectiveState != oldEffectiveState) {
d->createTLExtra();
if (oldEffectiveState == Qt::WindowNoState) { //normal
if (oldEffectiveState == Qt::WindowNoState)
d->topData()->normalGeometry = geometry();
} else if (oldEffectiveState == Qt::WindowFullScreen) {
setParent(0, d->topData()->savedFlags);
needShow = true;
} else if (oldEffectiveState == Qt::WindowMinimized) {
needShow = true;
}
Q_ASSERT(windowHandle());
windowHandle()->setWindowState(newEffectiveState);
bool supported = windowHandle()->windowState() == newEffectiveState;
if (!supported) {
// emulate the window state
// undo the effects of the old emulated state
if (oldEffectiveState == Qt::WindowFullScreen) {
setParent(0, d->topData()->savedFlags);
needShow = true;
} else if (oldEffectiveState == Qt::WindowMinimized) {
needShow = true;
}
// emulate the new window state
if (newEffectiveState == Qt::WindowMinimized) {
//### not ideal...
hide();

View File

@ -1829,67 +1829,93 @@ void tst_QWidget::windowState()
widget1.setWindowState(Qt::WindowMaximized);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowMaximized);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMaximized);
widget1.show();
QTest::qWait(100);
VERIFY_STATE(Qt::WindowMaximized);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMaximized);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized);
QTest::qWait(100);
QVERIFY(!(widget1.windowState() & Qt::WindowMaximized));
QCOMPARE(widget1.pos(), pos);
QTRY_COMPARE(widget1.pos(), pos);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState);
widget1.setWindowState(Qt::WindowMinimized);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowMinimized);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMinimized);
widget1.setWindowState(widget1.windowState() | Qt::WindowMaximized);
QTest::qWait(100);
VERIFY_STATE((Qt::WindowMinimized|Qt::WindowMaximized));
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMinimized);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowMaximized);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMaximized);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized);
QTest::qWait(100);
QVERIFY(!(widget1.windowState() & (Qt::WindowMinimized|Qt::WindowMaximized)));
QCOMPARE(widget1.pos(), pos);
QTRY_COMPARE(widget1.pos(), pos);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState);
widget1.setWindowState(Qt::WindowFullScreen);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowFullScreen);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowFullScreen);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized);
QTest::qWait(100);
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMinimized));
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMinimized);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowFullScreen);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowFullScreen);
widget1.setWindowState(Qt::WindowNoState);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowNoState);
QTRY_COMPARE(widget1.pos(), pos);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState);
widget1.setWindowState(Qt::WindowFullScreen);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowFullScreen);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowFullScreen);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized);
QTest::qWait(100);
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized));
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowFullScreen);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized);
QTest::qWait(100);
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized|Qt::WindowMinimized));
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMinimized);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMinimized);
QTest::qWait(100);
VERIFY_STATE((Qt::WindowFullScreen|Qt::WindowMaximized));
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowFullScreen);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowFullScreen);
QTest::qWait(100);
VERIFY_STATE(Qt::WindowMaximized);
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowMaximized);
widget1.setWindowState(widget1.windowState() ^ Qt::WindowMaximized);
QTest::qWait(100);
QVERIFY(!(widget1.windowState() & stateMask));
QCOMPARE(widget1.windowHandle()->windowState(), Qt::WindowNoState);
QCOMPARE(widget1.pos(), pos);
QCOMPARE(widget1.size(), size);
QTRY_COMPARE(widget1.pos(), pos);
QTRY_COMPARE(widget1.size(), size);
#endif
}