diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-09-21 11:56:08 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-09-21 21:39:41 +0000 |
commit | 175d0ea3f80af0ca32baec489d8ea66dd4ee3418 (patch) | |
tree | 2e4d30797a32967195b9db1dccde0bb8b8f119e5 /tests/auto/drawer | |
parent | aae5b793666091a780e63b68b2a0426f8edd6174 (diff) |
Drawer: reparent to the overlay by default
Drawer is a special type of popup that always resides at one of the
window edges. Therefore it makes sense for drawers to operate on window
coordinates. Re-parenting drawers to the window overlay achieves that.
Now that the window overlay is guaranteed to always exist and the
ApplicationWindow.overlay attached property works even with plain QML
Window, we can reliably use it as a parent for Drawer.
Task-number: QTBUG-53168
Change-Id: I37c727001350217ea1d2d9c52d73b4cae44d7c8d
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/drawer')
-rw-r--r-- | tests/auto/drawer/data/header.qml | 57 | ||||
-rw-r--r-- | tests/auto/drawer/tst_drawer.cpp | 32 |
2 files changed, 89 insertions, 0 deletions
diff --git a/tests/auto/drawer/data/header.qml b/tests/auto/drawer/data/header.qml new file mode 100644 index 00000000..9a352ffc --- /dev/null +++ b/tests/auto/drawer/data/header.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Controls 2.0 + +ApplicationWindow { + width: 400 + height: 400 + + property alias drawer: drawer + + header: ToolBar { } + + Drawer { + id: drawer + width: 200 + height: parent.height + } +} diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index 3a02e9a9..f29abf21 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -69,6 +69,7 @@ private slots: void dragMargin(); void reposition(); + void header(); void hover_data(); void hover(); @@ -352,6 +353,37 @@ void tst_Drawer::reposition() QTRY_COMPARE(drawer->popupItem()->x(), static_cast<qreal>(window->width())); } +void tst_Drawer::header() +{ + QQuickApplicationHelper helper(this, QStringLiteral("header.qml")); + + QQuickApplicationWindow *window = helper.appWindow; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickItem *content = window->contentItem(); + QVERIFY(content); + + QQuickOverlay *overlay = QQuickOverlay::overlay(window); + QVERIFY(overlay); + + QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer*>(); + QVERIFY(drawer); + QQuickItem *popupItem = drawer->popupItem(); + + drawer->open(); + QVERIFY(drawer->isVisible()); + + QCOMPARE(drawer->parentItem(), overlay); + QCOMPARE(drawer->height(), overlay->height()); + QCOMPARE(popupItem->height(), overlay->height()); + + drawer->setParentItem(content); + QCOMPARE(drawer->parentItem(), content); + QCOMPARE(drawer->height(), content->height()); + QCOMPARE(popupItem->height(), content->height()); +} + void tst_Drawer::hover_data() { QTest::addColumn<QString>("source"); |