diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-09-22 14:37:58 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-09-23 11:31:21 +0200 |
commit | 0bc19b49975bc82185aa24857f2a921584c9684f (patch) | |
tree | 7c4dbb914ebc0e40588d083171bba3de2fc65970 /tests/auto/qwindow/tst_qwindow.cpp | |
parent | 294df24621ddd4e08ca792cd8e541dcc84409acb (diff) |
Implemented QWidget's move() vs setGeometry() distinction in QWindow.
QWidget's move() sets the position of the window including the window
frame, unlike setGeometry(). There was no equivalent for this in
QWindow, so several QWidget auto-tests were failing. Now we add
setFramePos() to achieve the same purpose in QWindow.
This fixes tst_QWidget::windowState(), which uses move().
Change-Id: I9a3e558bd615a8f0234cc3dd94fbb2bf5ecbc148
Reviewed-on: http://codereview.qt-project.org/5405
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/qwindow/tst_qwindow.cpp')
-rw-r--r-- | tests/auto/qwindow/tst_qwindow.cpp | 95 |
1 files changed, 94 insertions, 1 deletions
diff --git a/tests/auto/qwindow/tst_qwindow.cpp b/tests/auto/qwindow/tst_qwindow.cpp index 77e3d5f88c..3eedd7cf6f 100644 --- a/tests/auto/qwindow/tst_qwindow.cpp +++ b/tests/auto/qwindow/tst_qwindow.cpp @@ -40,7 +40,10 @@ ****************************************************************************/ #include <qwindow.h> -#include <qtest.h> + +#include <QtTest/QtTest> + +#include "../../shared/util.h" class tst_QWindow: public QObject { @@ -48,6 +51,7 @@ class tst_QWindow: public QObject private slots: void mapGlobal(); + void positioning(); }; @@ -70,5 +74,94 @@ void tst_QWindow::mapGlobal() QCOMPARE(c.mapFromGlobal(QPoint(100, 100)), QPoint(30, 30)); } +class Window : public QWindow +{ +public: + Window() + : gotResizeEvent(false) + , gotMapEvent(false) + , gotMoveEvent(false) + { + setWindowFlags(Qt::Window | Qt::WindowTitleHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint); + } + + bool event(QEvent *event) + { + switch (event->type()) { + case QEvent::Map: + gotMapEvent = true; + break; + case QEvent::Resize: + gotResizeEvent = true; + break; + case QEvent::Move: + gotMoveEvent = true; + break; + default: + break; + } + + return QWindow::event(event); + } + + bool gotResizeEvent; + bool gotMapEvent; + bool gotMoveEvent; +}; + +void tst_QWindow::positioning() +{ + QRect geometry(80, 80, 40, 40); + + Window window; + window.setGeometry(geometry); + QCOMPARE(window.geometry(), geometry); + window.show(); + + QTRY_VERIFY(window.gotResizeEvent && window.gotMapEvent); + + QMargins originalMargins = window.frameMargins(); + + QCOMPARE(window.pos(), window.framePos() + QPoint(originalMargins.left(), originalMargins.top())); + QVERIFY(window.frameGeometry().contains(window.geometry())); + + QPoint originalPos = window.pos(); + QPoint originalFramePos = window.framePos(); + + window.gotResizeEvent = false; + + window.setWindowState(Qt::WindowFullScreen); + QTRY_VERIFY(window.gotResizeEvent); + + window.gotResizeEvent = false; + window.setWindowState(Qt::WindowNoState); + QTRY_VERIFY(window.gotResizeEvent); + + QTRY_COMPARE(originalPos, window.pos()); + QTRY_COMPARE(originalFramePos, window.framePos()); + QTRY_COMPARE(originalMargins, window.frameMargins()); + + // if our positioning is actually fully respected by the window manager + // test whether it correctly handles frame positioning as well + if (originalPos == geometry.topLeft() && (originalMargins.top() != 0 || originalMargins.left() != 0)) { + QPoint framePos(40, 40); + + window.gotMoveEvent = false; + window.setFramePos(framePos); + + QTRY_VERIFY(window.gotMoveEvent); + QTRY_COMPARE(framePos, window.framePos()); + QTRY_COMPARE(originalMargins, window.frameMargins()); + QCOMPARE(window.pos(), window.framePos() + QPoint(originalMargins.left(), originalMargins.top())); + + // and back to regular positioning + + window.gotMoveEvent = false; + window.setPos(originalPos); + QTRY_VERIFY(window.gotMoveEvent); + QTRY_COMPARE(originalPos, window.pos()); + } +} + #include <tst_qwindow.moc> QTEST_MAIN(tst_QWindow); |