diff options
author | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-10-16 17:36:20 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@theqtcompany.com> | 2015-10-26 19:01:32 +0000 |
commit | 2bebf640ccd3b1a50401a6da5f237c5fa968734a (patch) | |
tree | efdccf58fc7137be6f25742d762d7f251fff921a /tests/auto/gui | |
parent | 73c86fcb400cb91868b56ac05a3b82a3f7ba1a1b (diff) |
Add QWindow child window positioning test
Tests that window creation order doesn't affect the resulting geometry
of the parent and child windows.
Change-Id: Iff0cb5adf87107dfed4a633a67e1b4312b90e24a
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 82 |
1 files changed, 69 insertions, 13 deletions
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 0faace0c1a..a953a36559 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -67,6 +67,8 @@ private slots: void positioning_data(); void positioning(); void positioningDuringMinimized(); + void childWindowPositioning_data(); + void childWindowPositioning(); void platformSurface(); void isExposed(); void isActive(); @@ -320,6 +322,19 @@ private: QPlatformSurfaceEvent::SurfaceEventType m_surfaceventType; }; +class ColoredWindow : public QRasterWindow { +public: + explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {} + void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE + { + QPainter p(this); + p.fillRect(QRect(QPoint(0, 0), size()), m_color); + } + +private: + const QColor m_color; +}; + void tst_QWindow::eventOrderOnShow() { // Some platforms enforce minimum widths for windows, which can cause extra resize @@ -502,6 +517,60 @@ void tst_QWindow::positioningDuringMinimized() QTRY_COMPARE(window.geometry(), newGeometry); } +void tst_QWindow::childWindowPositioning_data() +{ + QTest::addColumn<bool>("showInsteadOfCreate"); + + QTest::newRow("create") << false; + QTest::newRow("show") << true; +} + +void tst_QWindow::childWindowPositioning() +{ + const QPoint topLeftOrigin(0, 0); + + ColoredWindow topLevelWindowFirst(Qt::green); + topLevelWindowFirst.setObjectName("topLevelWindowFirst"); + ColoredWindow childWindowAfter(Qt::yellow, &topLevelWindowFirst); + childWindowAfter.setObjectName("childWindowAfter"); + + topLevelWindowFirst.setFramePosition(m_availableTopLeft); + childWindowAfter.setFramePosition(topLeftOrigin); + + ColoredWindow topLevelWindowAfter(Qt::green); + topLevelWindowAfter.setObjectName("topLevelWindowAfter"); + ColoredWindow childWindowFirst(Qt::yellow, &topLevelWindowAfter); + childWindowFirst.setObjectName("childWindowFirst"); + + topLevelWindowAfter.setFramePosition(m_availableTopLeft); + childWindowFirst.setFramePosition(topLeftOrigin); + + QFETCH(bool, showInsteadOfCreate); + + QWindow* windows[] = { &topLevelWindowFirst, &childWindowAfter, &childWindowFirst, &topLevelWindowAfter, 0 }; + for (int i = 0; windows[i]; ++i) { + QWindow *window = windows[i]; + if (showInsteadOfCreate) { + window->showNormal(); + } else { + window->create(); + } + } + + if (showInsteadOfCreate) { + QVERIFY(QTest::qWaitForWindowExposed(&topLevelWindowFirst)); + QVERIFY(QTest::qWaitForWindowExposed(&topLevelWindowAfter)); + } + + // Creation order shouldn't affect the geometry + QCOMPARE(topLevelWindowFirst.geometry(), topLevelWindowAfter.geometry()); + QCOMPARE(childWindowAfter.geometry(), childWindowFirst.geometry()); + + // Creation order shouldn't affect the child ending up at 0,0 + QCOMPARE(childWindowFirst.framePosition(), topLeftOrigin); + QCOMPARE(childWindowAfter.framePosition(), topLeftOrigin); +} + class PlatformWindowFilter : public QObject { Q_OBJECT @@ -1773,19 +1842,6 @@ void tst_QWindow::modalWindowPosition() QCOMPARE(window.geometry(), origGeo); } -class ColoredWindow : public QRasterWindow { -public: - explicit ColoredWindow(const QColor &color, QWindow *parent = 0) : QRasterWindow(parent), m_color(color) {} - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE - { - QPainter p(this); - p.fillRect(QRect(QPoint(0, 0), size()), m_color); - } - -private: - const QColor m_color; -}; - static bool isNativeWindowVisible(const QWindow *window) { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) |