diff options
author | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-01-28 17:20:42 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@theqtcompany.com> | 2016-01-28 17:22:53 +0100 |
commit | 8318deb165047d592523ec0b2fd10510d4953b37 (patch) | |
tree | e80c082fbe6918e489f61d4f06deb29bbc12fa32 /tests | |
parent | 85dc3eb5d0e19d024083a9776d1ac8cf31d708ca (diff) | |
parent | 135b5cdecaeaecb1f3afe01103eac5970399efa7 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts:
src/imports/controls/material/qtlabsmaterialstyleplugin.cpp
src/templates/qquickapplicationwindow_p.h
src/templates/qquickcombobox.cpp
src/templates/qquickcombobox_p.h
src/templates/qquickpopup.cpp
Change-Id: Ibd87e907bc8abf1f675147761ea8bb0b40722478
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/applicationwindow/applicationwindow.pro | 2 | ||||
-rw-r--r-- | tests/auto/applicationwindow/tst_applicationwindow.cpp | 33 | ||||
-rw-r--r-- | tests/auto/auto.pro | 1 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_button.qml | 76 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 49 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_frame.qml | 26 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_groupbox.qml | 22 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_pane.qml | 26 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_toolbar.qml | 34 | ||||
-rw-r--r-- | tests/auto/menu/tst_menu.cpp | 2 | ||||
-rw-r--r-- | tests/auto/popup/data/applicationwindow.qml | 72 | ||||
-rw-r--r-- | tests/auto/popup/popup.pro | 14 | ||||
-rw-r--r-- | tests/auto/popup/tst_popup.cpp | 228 | ||||
-rw-r--r-- | tests/manual/manual.pro | 2 | ||||
-rw-r--r-- | tests/manual/viewinqwidget/main.cpp | 89 | ||||
-rw-r--r-- | tests/manual/viewinqwidget/main.qml | 49 | ||||
-rw-r--r-- | tests/manual/viewinqwidget/viewinqwidget.pro | 6 | ||||
-rw-r--r-- | tests/manual/viewinqwidget/viewinqwidget.qrc | 5 |
18 files changed, 645 insertions, 91 deletions
diff --git a/tests/auto/applicationwindow/applicationwindow.pro b/tests/auto/applicationwindow/applicationwindow.pro index 5a664b63..eabe81bf 100644 --- a/tests/auto/applicationwindow/applicationwindow.pro +++ b/tests/auto/applicationwindow/applicationwindow.pro @@ -4,7 +4,7 @@ SOURCES += tst_applicationwindow.cpp osx:CONFIG -= app_bundle -QT += core-private gui-private qml-private quick-private labstemplates-private testlib +QT += core-private gui-private qml-private quick-private labstemplates-private labscontrols-private testlib include (../shared/util.pri) diff --git a/tests/auto/applicationwindow/tst_applicationwindow.cpp b/tests/auto/applicationwindow/tst_applicationwindow.cpp index 11d45182..4b392e99 100644 --- a/tests/auto/applicationwindow/tst_applicationwindow.cpp +++ b/tests/auto/applicationwindow/tst_applicationwindow.cpp @@ -41,12 +41,14 @@ #include <QtQml/qqmlcontext.h> #include <QtQuick/qquickview.h> #include <QtQuick/private/qquickitem_p.h> +#include <QtGui/private/qguiapplication_p.h> #include <QtLabsTemplates/private/qquickapplicationwindow_p.h> #include <QtLabsTemplates/private/qquickoverlay_p.h> #include <QtLabsTemplates/private/qquickcontrol_p.h> #include <QtLabsTemplates/private/qquicklabel_p.h> #include <QtLabsTemplates/private/qquicktextarea_p.h> #include <QtLabsTemplates/private/qquicktextfield_p.h> +#include <QtLabsControls/private/qquickproxytheme_p.h> #include "../shared/util.h" #include "../shared/visualtestutil.h" @@ -65,6 +67,7 @@ private slots: void implicitFill(); void attachedProperties(); void font(); + void defaultFont(); void locale(); void activeFocusControl_data(); void activeFocusControl(); @@ -492,6 +495,36 @@ void tst_applicationwindow::font() QCOMPARE(item6->font(), font); } +class TestTheme : public QQuickProxyTheme +{ +public: + TestTheme(QPlatformTheme *theme) : QQuickProxyTheme(theme), m_font("Courier") + { QGuiApplicationPrivate::platform_theme = this; } + ~TestTheme() { QGuiApplicationPrivate::platform_theme = theme(); } + + const QFont *font(Font type = SystemFont) const override + { + Q_UNUSED(type); + return &m_font; + } + + QFont m_font; +}; + +void tst_applicationwindow::defaultFont() +{ + TestTheme theme(QGuiApplicationPrivate::platform_theme); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData("import Qt.labs.controls 1.0; ApplicationWindow { }", QUrl()); + + QScopedPointer<QQuickApplicationWindow> window; + window.reset(static_cast<QQuickApplicationWindow *>(component.create())); + QVERIFY(!window.isNull()); + QCOMPARE(window->font(), *theme.font()); +} + void tst_applicationwindow::locale() { QQmlEngine engine; diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 3b3ee04a..ec9d4111 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -7,6 +7,7 @@ SUBDIRS += \ controls \ material \ menu \ + popup \ pressandhold \ sanity \ snippets \ diff --git a/tests/auto/controls/data/tst_button.qml b/tests/auto/controls/data/tst_button.qml index 1faf1956..45fad8cb 100644 --- a/tests/auto/controls/data/tst_button.qml +++ b/tests/auto/controls/data/tst_button.qml @@ -163,86 +163,10 @@ TestCase { control.destroy() } - Component { - id: eventButton - Button { - property var lastPress - property var lastRelease - property var lastClick - property var lastDoubleClick - - function reset() { - lastPress = undefined - lastRelease = undefined - lastClick = undefined - lastDoubleClick = undefined - } - - onPressed: { lastPress = { x: mouse.x, y: mouse.y, button: mouse.button, buttons: mouse.buttons, modifiers: mouse.modifiers, wasHeld: mouse.wasHeld, isClick: mouse.isClick } } - onReleased: { lastRelease = { x: mouse.x, y: mouse.y, button: mouse.button, buttons: mouse.buttons, modifiers: mouse.modifiers, wasHeld: mouse.wasHeld, isClick: mouse.isClick } } - onClicked: { lastClick = { x: mouse.x, y: mouse.y, button: mouse.button, buttons: mouse.buttons, modifiers: mouse.modifiers, wasHeld: mouse.wasHeld, isClick: mouse.isClick } } - onDoubleClicked: { lastDoubleClick = { x: mouse.x, y: mouse.y, button: mouse.button, buttons: mouse.buttons, modifiers: mouse.modifiers, wasHeld: mouse.wasHeld, isClick: mouse.isClick } } - } - } - function eventErrorMessage(actual, expected) { return "actual event:" + JSON.stringify(actual) + ", expected event:" + JSON.stringify(expected) } - function test_events() { - var control = eventButton.createObject(testCase) - verify(control) - - control.forceActiveFocus() - verify(control.activeFocus) - - mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton) - var expected = { x: Math.round(control.width / 2), y: Math.round(control.height / 2), button: Qt.LeftButton, buttons: Qt.LeftButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false } - compare(control.lastPress, expected, eventErrorMessage(control.lastPress, expected)) - compare(control.lastRelease, undefined) - compare(control.lastClick, undefined) - compare(control.lastDoubleClick, undefined) - - control.reset() - - mouseMove(control, control.width / 3, control.height / 3, Qt.LeftButton) - compare(control.lastPress, undefined) - compare(control.lastRelease, undefined) - compare(control.lastClick, undefined) - compare(control.lastDoubleClick, undefined) - - control.reset() - - mouseRelease(control, control.width / 4, control.height / 4, Qt.LeftButton) - compare(control.lastPress, undefined) - expected = { x: Math.round(control.width / 4), y: Math.round(control.height / 4), button: Qt.LeftButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false } - compare(control.lastRelease, expected, eventErrorMessage(control.lastRelease, expected)) - expected = { x: Math.round(control.width / 4), y: Math.round(control.height / 4), button: Qt.LeftButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: true } - compare(control.lastClick, expected, eventErrorMessage(control.lastClick, expected)) - compare(control.lastDoubleClick, undefined) - - control.reset() - - keyPress(Qt.Key_Space) - expected = { x: Math.round(control.width / 2), y: Math.round(control.height / 2), button: Qt.NoButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false } - compare(control.lastPress, expected, eventErrorMessage(control.lastPress, expected)) - compare(control.lastRelease, undefined) - compare(control.lastClick, undefined) - compare(control.lastDoubleClick, undefined) - - control.reset() - - keyRelease(Qt.Key_Space) - compare(control.lastPress, undefined) - expected = { x: Math.round(control.width / 2), y: Math.round(control.height / 2), button: Qt.NoButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: false } - compare(control.lastRelease, expected, eventErrorMessage(control.lastRelease, expected)) - expected = { x: Math.round(control.width / 2), y: Math.round(control.height / 2), button: Qt.NoButton, buttons: Qt.NoButton, modifiers: Qt.NoModifier, wasHeld: false, isClick: true } - compare(control.lastClick, expected, eventErrorMessage(control.lastClick, expected)) - compare(control.lastDoubleClick, undefined) - - control.destroy() - } - SignalSpy { id: clickSpy; signalName: "clicked" } function test_autoRepeat() { diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index d74c52aa..55ac3e8d 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -69,7 +69,7 @@ TestCase { id: comboBox ComboBox { delegate: ItemDelegate { - width: parent.width + width: popup.width } } } @@ -137,6 +137,36 @@ TestCase { control.destroy() } + function test_objects() { + var control = comboBox.createObject(window.contentItem) + verify(control) + + var items = [ + { text: "Apple" }, + { text: "Orange" }, + { text: "Banana" } + ] + + control.model = items + compare(control.model, items) + + compare(control.count, 3) + compare(control.currentIndex, 0) + compare(control.currentText, "Apple") + + control.currentIndex = 2 + compare(control.currentIndex, 2) + compare(control.currentText, "Banana") + + control.model = null + compare(control.model, null) + compare(control.count, 0) + compare(control.currentIndex, -1) + compare(control.currentText, "") + + control.destroy() + } + function test_number() { var control = comboBox.createObject(window.contentItem) verify(control) @@ -201,11 +231,24 @@ TestCase { ListElement { name: "Banana"; color: "yellow" } } - function test_textRole() { + property var fruitarray: [ + { name: "Apple", color: "red" }, + { name: "Orange", color: "orange" }, + { name: "Banana", color: "yellow" } + ] + + function test_textRole_data() { + return [ + { tag: "ListModel", model: fruitmodel }, + { tag: "ObjectArray", model: fruitarray } + ] + } + + function test_textRole(data) { var control = comboBox.createObject(window.contentItem) verify(control) - control.model = fruitmodel + control.model = data.model compare(control.count, 3) compare(control.currentIndex, 0) compare(control.currentText, "") diff --git a/tests/auto/controls/data/tst_frame.qml b/tests/auto/controls/data/tst_frame.qml index feb6cf11..d50a0dfc 100644 --- a/tests/auto/controls/data/tst_frame.qml +++ b/tests/auto/controls/data/tst_frame.qml @@ -57,7 +57,7 @@ TestCase { Component { id: oneChildFrame - GroupBox { + Frame { Item { implicitWidth: 100 implicitHeight: 30 @@ -67,7 +67,7 @@ TestCase { Component { id: twoChildrenFrame - GroupBox { + Frame { Item { implicitWidth: 100 implicitHeight: 30 @@ -79,6 +79,16 @@ TestCase { } } + Component { + id: contentFrame + Frame { + contentItem: Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + function test_empty() { var control = frame.createObject(testCase) verify(control) @@ -113,4 +123,16 @@ TestCase { control.destroy() } + + function test_contentItem() { + var control = contentFrame.createObject(testCase) + verify(control) + + compare(control.contentWidth, 100) + compare(control.contentHeight, 30) + verify(control.implicitWidth > 100) + verify(control.implicitHeight > 30) + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_groupbox.qml b/tests/auto/controls/data/tst_groupbox.qml index 55568923..0f0e33fb 100644 --- a/tests/auto/controls/data/tst_groupbox.qml +++ b/tests/auto/controls/data/tst_groupbox.qml @@ -79,6 +79,16 @@ TestCase { } } + Component { + id: contentBox + GroupBox { + contentItem: Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + function test_empty() { var control = groupBox.createObject(testCase) verify(control) @@ -113,4 +123,16 @@ TestCase { control.destroy() } + + function test_contentItem() { + var control = contentBox.createObject(testCase) + verify(control) + + compare(control.contentWidth, 100) + compare(control.contentHeight, 30) + verify(control.implicitWidth > 100) + verify(control.implicitHeight > 30) + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_pane.qml b/tests/auto/controls/data/tst_pane.qml index 18fd1cf0..1fdec049 100644 --- a/tests/auto/controls/data/tst_pane.qml +++ b/tests/auto/controls/data/tst_pane.qml @@ -57,7 +57,7 @@ TestCase { Component { id: oneChildPane - GroupBox { + Pane { Item { implicitWidth: 100 implicitHeight: 30 @@ -67,7 +67,7 @@ TestCase { Component { id: twoChildrenPane - GroupBox { + Pane { Item { implicitWidth: 100 implicitHeight: 30 @@ -80,6 +80,16 @@ TestCase { } Component { + id: contentPane + Pane { + contentItem: Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + + Component { id: pressPane MouseArea { width: 200 @@ -127,6 +137,18 @@ TestCase { control.destroy() } + function test_contentItem() { + var control = contentPane.createObject(testCase) + verify(control) + + compare(control.contentWidth, 100) + compare(control.contentHeight, 30) + verify(control.implicitWidth > 100) + verify(control.implicitHeight > 30) + + control.destroy() + } + function test_press() { var control = pressPane.createObject(testCase) verify(control) diff --git a/tests/auto/controls/data/tst_toolbar.qml b/tests/auto/controls/data/tst_toolbar.qml index ac116a86..128aa403 100644 --- a/tests/auto/controls/data/tst_toolbar.qml +++ b/tests/auto/controls/data/tst_toolbar.qml @@ -57,7 +57,7 @@ TestCase { Component { id: oneChildBar - GroupBox { + ToolBar { Item { implicitWidth: 100 implicitHeight: 30 @@ -67,7 +67,7 @@ TestCase { Component { id: twoChildrenBar - GroupBox { + ToolBar { Item { implicitWidth: 100 implicitHeight: 30 @@ -79,6 +79,16 @@ TestCase { } } + Component { + id: contentBar + ToolBar { + contentItem: Item { + implicitWidth: 100 + implicitHeight: 30 + } + } + } + function test_empty() { var control = toolBar.createObject(testCase) verify(control) @@ -96,8 +106,8 @@ TestCase { compare(control.contentWidth, 100) compare(control.contentHeight, 30) - verify(control.implicitWidth > 100) - verify(control.implicitHeight > 30) + verify(control.implicitWidth >= 100) + verify(control.implicitHeight >= 30) control.destroy() } @@ -108,8 +118,20 @@ TestCase { compare(control.contentWidth, 0) compare(control.contentHeight, 0) - verify(control.implicitWidth > 0) - verify(control.implicitHeight > 0) + verify(control.implicitWidth >= 0) + verify(control.implicitHeight >= 0) + + control.destroy() + } + + function test_contentItem() { + var control = contentBar.createObject(testCase) + verify(control) + + compare(control.contentWidth, 100) + compare(control.contentHeight, 30) + verify(control.implicitWidth >= 100) + verify(control.implicitHeight >= 30) control.destroy() } diff --git a/tests/auto/menu/tst_menu.cpp b/tests/auto/menu/tst_menu.cpp index d072af4b..825867cf 100644 --- a/tests/auto/menu/tst_menu.cpp +++ b/tests/auto/menu/tst_menu.cpp @@ -89,7 +89,7 @@ void tst_menu::mouse() QVERIFY(window->overlay()->childItems().contains(menu->contentItem()->parentItem())); QQuickItem *firstItem = menu->itemAt(0); - QSignalSpy clickedSpy(firstItem, SIGNAL(clicked(QQuickMouseEvent*))); + QSignalSpy clickedSpy(firstItem, SIGNAL(clicked())); QSignalSpy triggeredSpy(firstItem, SIGNAL(triggered())); QSignalSpy visibleSpy(menu, SIGNAL(visibleChanged())); diff --git a/tests/auto/popup/data/applicationwindow.qml b/tests/auto/popup/data/applicationwindow.qml new file mode 100644 index 00000000..34dbe7e8 --- /dev/null +++ b/tests/auto/popup/data/applicationwindow.qml @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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 Qt.labs.controls 1.0 + +ApplicationWindow { + width: 400 + height: 400 + + property alias popup: popup + property alias button: button + + Button { + id: button + text: "Open" + anchors.centerIn: parent + anchors.verticalCenterOffset: -height + + Popup { + id: popup + y: parent.height + + Text { + color: "white" + text: "Hello, world!" + + MouseArea { + anchors.fill: parent + onClicked: popup.close() + } + } + } + } +} diff --git a/tests/auto/popup/popup.pro b/tests/auto/popup/popup.pro new file mode 100644 index 00000000..87aca3b3 --- /dev/null +++ b/tests/auto/popup/popup.pro @@ -0,0 +1,14 @@ +CONFIG += testcase +TARGET = tst_popup +SOURCES += tst_popup.cpp + +osx:CONFIG -= app_bundle + +QT += core-private gui-private qml-private quick-private testlib labstemplates-private + +include (../shared/util.pri) + +TESTDATA = data/* + +OTHER_FILES += \ + data/* diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp new file mode 100644 index 00000000..61bf999c --- /dev/null +++ b/tests/auto/popup/tst_popup.cpp @@ -0,0 +1,228 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/qtest.h> +#include <QtTest/qsignalspy.h> +#include "../shared/util.h" +#include "../shared/visualtestutil.h" + +#include <QtLabsTemplates/private/qquickapplicationwindow_p.h> +#include <QtLabsTemplates/private/qquickoverlay_p.h> +#include <QtLabsTemplates/private/qquickpopup_p.h> +#include <QtLabsTemplates/private/qquickbutton_p.h> + +using namespace QQuickVisualTestUtil; + +class tst_popup : public QQmlDataTest +{ + Q_OBJECT + +private slots: + void visible(); + void overlay(); + void closePolicy_data(); + void closePolicy(); +}; + +void tst_popup::visible() +{ + QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml")); + + QQuickApplicationWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>(); + QVERIFY(popup); + QQuickItem *popupItem = popup->popupItem(); + + popup->open(); + QVERIFY(popup->isVisible()); + QVERIFY(window->overlay()->childItems().contains(popupItem)); + + popup->close(); + QVERIFY(!popup->isVisible()); + QVERIFY(!window->overlay()->childItems().contains(popupItem)); + + popup->setVisible(true); + QVERIFY(popup->isVisible()); + QVERIFY(window->overlay()->childItems().contains(popupItem)); + + popup->setVisible(false); + QVERIFY(!popup->isVisible()); + QVERIFY(!window->overlay()->childItems().contains(popupItem)); +} + +void tst_popup::overlay() +{ + QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml")); + + QQuickApplicationWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickItem *overlay = window->overlay(); + QSignalSpy overlayPressedSignal(overlay, SIGNAL(pressed())); + QSignalSpy overlayReleasedSignal(overlay, SIGNAL(released())); + QVERIFY(overlayPressedSignal.isValid()); + QVERIFY(overlayReleasedSignal.isValid()); + + QTest::mousePress(window, Qt::LeftButton); + QCOMPARE(overlayPressedSignal.count(), 1); + QCOMPARE(overlayReleasedSignal.count(), 0); + + QTest::mouseRelease(window, Qt::LeftButton); + QCOMPARE(overlayPressedSignal.count(), 1); + QCOMPARE(overlayReleasedSignal.count(), 0); // no modal popups open + + QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>(); + QVERIFY(popup); + + QQuickButton *button = helper.window->property("button").value<QQuickButton*>(); + QVERIFY(button); + + popup->setModal(true); + + popup->open(); + QVERIFY(popup->isVisible()); + + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + QCOMPARE(overlayPressedSignal.count(), 2); + QCOMPARE(overlayReleasedSignal.count(), 0); + + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + QCOMPARE(overlayPressedSignal.count(), 2); + QCOMPARE(overlayReleasedSignal.count(), 1); + + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + popup->x() + popup->width() / 2, + button->y() + popup->y() + popup->height() / 2)); + QCOMPARE(overlayPressedSignal.count(), 2); + QCOMPARE(overlayReleasedSignal.count(), 1); + + QVERIFY(!popup->isVisible()); +} + +Q_DECLARE_METATYPE(QQuickPopup::ClosePolicy) + +void tst_popup::closePolicy_data() +{ + qRegisterMetaType<QQuickPopup::ClosePolicy>(); + + QTest::addColumn<QQuickPopup::ClosePolicy>("closePolicy"); + + QTest::newRow("NoAutoClose") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose); + QTest::newRow("OnPressOutside") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnPressOutside); + QTest::newRow("OnPressOutsideParent") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnPressOutsideParent); + QTest::newRow("OnPressOutside|Parent") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnPressOutside | QQuickPopup::OnPressOutsideParent); + QTest::newRow("OnReleaseOutside") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnReleaseOutside); + QTest::newRow("OnReleaseOutside|Parent") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnReleaseOutside | QQuickPopup::OnReleaseOutsideParent); + QTest::newRow("OnEscape") << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::OnEscape); +} + +void tst_popup::closePolicy() +{ + QFETCH(QQuickPopup::ClosePolicy, closePolicy); + + QQuickApplicationHelper helper(this, QStringLiteral("applicationwindow.qml")); + + QQuickApplicationWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + + QQuickPopup *popup = helper.window->property("popup").value<QQuickPopup*>(); + QVERIFY(popup); + + QQuickButton *button = helper.window->property("button").value<QQuickButton*>(); + QVERIFY(button); + + popup->setModal(true); + popup->setFocus(true); + popup->setClosePolicy(closePolicy); + + popup->open(); + QVERIFY(popup->isVisible()); + + // press outside popup and its parent + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + if (closePolicy.testFlag(QQuickPopup::OnPressOutside) || closePolicy.testFlag(QQuickPopup::OnPressOutsideParent)) + QVERIFY(!popup->isVisible()); + else + QVERIFY(popup->isVisible()); + + popup->open(); + QVERIFY(popup->isVisible()); + + // release outside popup and its parent + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); + if (closePolicy.testFlag(QQuickPopup::OnReleaseOutside)) + QVERIFY(!popup->isVisible()); + else + QVERIFY(popup->isVisible()); + + popup->open(); + QVERIFY(popup->isVisible()); + + // press outside popup but inside its parent + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x(), button->y())); + if (closePolicy.testFlag(QQuickPopup::OnPressOutside) && !closePolicy.testFlag(QQuickPopup::OnPressOutsideParent)) + QVERIFY(!popup->isVisible()); + else + QVERIFY(popup->isVisible()); + + popup->open(); + QVERIFY(popup->isVisible()); + + // release outside popup but inside its parent + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x(), button->y())); + if (closePolicy.testFlag(QQuickPopup::OnReleaseOutside) && !closePolicy.testFlag(QQuickPopup::OnReleaseOutsideParent)) + QVERIFY(!popup->isVisible()); + else + QVERIFY(popup->isVisible()); + + popup->open(); + QVERIFY(popup->isVisible()); + + // escape + QTest::keyClick(window, Qt::Key_Escape); + if (closePolicy.testFlag(QQuickPopup::OnEscape)) + QVERIFY(!popup->isVisible()); + else + QVERIFY(popup->isVisible()); +} + +QTEST_MAIN(tst_popup) + +#include "tst_popup.moc" diff --git a/tests/manual/manual.pro b/tests/manual/manual.pro index b974ae29..a85fd870 100644 --- a/tests/manual/manual.pro +++ b/tests/manual/manual.pro @@ -3,3 +3,5 @@ SUBDIRS += \ gifs \ fonts \ testbench + +qtHaveModule(widgets): SUBDIRS += viewinqwidget diff --git a/tests/manual/viewinqwidget/main.cpp b/tests/manual/viewinqwidget/main.cpp new file mode 100644 index 00000000..3611e071 --- /dev/null +++ b/tests/manual/viewinqwidget/main.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QHBoxLayout> +#include <QVBoxLayout> +#include <QDebug> +#include <QDesktopWidget> +#include <QGroupBox> +#include <QQmlApplicationEngine> +#include <QQmlError> +#include <QQuickView> +#include <QQuickWidget> + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + QWidget widget; + widget.setWindowTitle(QT_VERSION_STR); + + QHBoxLayout *hLayout = new QHBoxLayout(&widget); + QGroupBox *groupBox = new QGroupBox("QuickWidget", &widget); + QVBoxLayout *vLayout = new QVBoxLayout(groupBox); + QQuickWidget *quickWidget = new QQuickWidget(groupBox); + quickWidget->setMinimumSize(360, 520); + vLayout->addWidget(quickWidget); + quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView); + quickWidget->setSource(QUrl(QLatin1String("qrc:/main.qml"))); + if (quickWidget->status() == QQuickWidget::Error) { + qWarning() << quickWidget->errors(); + return 1; + } + hLayout->addWidget(groupBox); + + const QUrl gallerySource(QLatin1String("qrc:/gallery.qml")); + QQmlApplicationEngine engine(gallerySource); + QObject *root = engine.rootObjects().value(0, nullptr); + if (!root || !root->isWindowType()) { + qWarning() << "Load error" << gallerySource; + return 1; + } + groupBox = new QGroupBox("QQuickView/createWindowContainer", &widget); + vLayout = new QVBoxLayout(groupBox); + QWidget *container = QWidget::createWindowContainer(qobject_cast<QWindow *>(root), groupBox); + container->setMinimumSize(360, 520); + vLayout->addWidget(container); + hLayout->addWidget(groupBox); + + const QRect availableGeometry = QApplication::desktop()->availableGeometry(&widget); + widget.move(availableGeometry.center() - QPoint(widget.sizeHint().width() / 2, widget.sizeHint().height() / 2)); + + widget.show(); + + return app.exec(); +} diff --git a/tests/manual/viewinqwidget/main.qml b/tests/manual/viewinqwidget/main.qml new file mode 100644 index 00000000..36a0b133 --- /dev/null +++ b/tests/manual/viewinqwidget/main.qml @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.6 +import Qt.labs.controls 1.0 + +Item { + visible: true + width: 360 + height: 520 + + ComboBox { + model: ["First", "Second", "Third"] + anchors.centerIn: parent + } +} diff --git a/tests/manual/viewinqwidget/viewinqwidget.pro b/tests/manual/viewinqwidget/viewinqwidget.pro new file mode 100644 index 00000000..9b7cba00 --- /dev/null +++ b/tests/manual/viewinqwidget/viewinqwidget.pro @@ -0,0 +1,6 @@ +QT += qml quick widgets quickwidgets +TARGET = viewinqwidget +SOURCES += $$PWD/main.cpp +OTHER_FILES += main.qml +RESOURCES += viewinqwidget.qrc \ + ../../../examples/controls/gallery/gallery.qrc diff --git a/tests/manual/viewinqwidget/viewinqwidget.qrc b/tests/manual/viewinqwidget/viewinqwidget.qrc new file mode 100644 index 00000000..5f6483ac --- /dev/null +++ b/tests/manual/viewinqwidget/viewinqwidget.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>main.qml</file> + </qresource> +</RCC> |