From 0bc19b49975bc82185aa24857f2a921584c9684f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 22 Sep 2011 14:37:58 +0200 Subject: 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 Reviewed-by: Lars Knoll --- tests/auto/qwindow/tst_qwindow.cpp | 95 +++++++++++++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-) (limited to 'tests/auto/qwindow') 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 -#include + +#include + +#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 QTEST_MAIN(tst_QWindow); -- cgit v1.2.3