From 6f6e073815d5b05aba553b83809fb701541260c6 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Mon, 24 Oct 2016 13:41:17 +0200 Subject: Fix popups to close on click outside When a popup closes itself on press outside, it accepts the press event so that it doesn't propagate to other popups or the content below. We must make sure that such closing popup does not become the mouse grabber, because it doesn't make sense to route the subsequent mouse events to the popup that was just closed. Change-Id: I80c6e26a1d94aa1526a61862f00af2fd0778aa82 Task-number: QTBUG-56697 Reviewed-by: Mitch Curtis --- tests/auto/popup/data/grabber.qml | 70 +++++++++++++++++++++++++++++++++++++++ tests/auto/popup/tst_popup.cpp | 52 +++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/auto/popup/data/grabber.qml (limited to 'tests') diff --git a/tests/auto/popup/data/grabber.qml b/tests/auto/popup/data/grabber.qml new file mode 100644 index 00000000..6cd5f765 --- /dev/null +++ b/tests/auto/popup/data/grabber.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 menu: menu + property alias popup: popup + property alias combo: combo.popup + + Menu { + id: menu + MenuItem { + onTriggered: popup.open() + } + } + + Popup { + id: popup + modal: true + width: 200 + height: 200 + + ComboBox { + id: combo + model: 3 + } + } +} diff --git a/tests/auto/popup/tst_popup.cpp b/tests/auto/popup/tst_popup.cpp index af6ccf34..fbd0605b 100644 --- a/tests/auto/popup/tst_popup.cpp +++ b/tests/auto/popup/tst_popup.cpp @@ -71,6 +71,7 @@ private slots: void wheel(); void parentDestroyed(); void nested(); + void grabber(); }; void tst_popup::visible_data() @@ -669,6 +670,57 @@ void tst_popup::nested() QCOMPARE(modalPopup->isVisible(), true); } +// QTBUG-56697 +void tst_popup::grabber() +{ + QQuickApplicationHelper helper(this, QStringLiteral("grabber.qml")); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickPopup *menu = window->property("menu").value(); + QVERIFY(menu); + + QQuickPopup *popup = window->property("popup").value(); + QVERIFY(popup); + + QQuickPopup *combo = window->property("combo").value(); + QVERIFY(combo); + + menu->open(); + QCOMPARE(menu->isVisible(), true); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); + + // click a menu item to open the popup + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(menu->width() / 2, menu->height() / 2)); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), true); + QCOMPARE(combo->isVisible(), false); + + combo->open(); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), true); + QCOMPARE(combo->isVisible(), true); + + // click outside to close both the combo popup and the parent popup + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, window->height() - 1)); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); + + menu->open(); + QCOMPARE(menu->isVisible(), true); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); + + // click outside the menu to close it (QTBUG-56697) + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, window->height() - 1)); + QCOMPARE(menu->isVisible(), false); + QCOMPARE(popup->isVisible(), false); + QCOMPARE(combo->isVisible(), false); +} + QTEST_MAIN(tst_popup) #include "tst_popup.moc" -- cgit v1.2.3 From da0570d1ddf6c786b4bfdd0a1172b36ecc66f2a2 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 29 Nov 2016 13:04:10 +0100 Subject: Dial: add missing wheel handling [ChangeLog][Controls][Dial] Added support for wheel handling when wheelEnabled is set to true. Change-Id: If0bc2f0ea9d7cde7726739cdfdbd795c908981f0 Reviewed-by: Mitch Curtis --- tests/auto/controls/data/tst_dial.qml | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_dial.qml b/tests/auto/controls/data/tst_dial.qml index e6446d3e..d0129755 100644 --- a/tests/auto/controls/data/tst_dial.qml +++ b/tests/auto/controls/data/tst_dial.qml @@ -356,4 +356,51 @@ TestCase { fuzzyCompare(dial.value, data.values[2], fuzz); fuzzyCompare(dial.position, data.positions[2], fuzz); } + + function test_wheel_data() { + return [ + { tag: "horizontal", orientation: Qt.Horizontal, dx: 120, dy: 0 }, + { tag: "vertical", orientation: Qt.Vertical, dx: 0, dy: 120 } + ] + } + + function test_wheel(data) { + var control = dialComponent.createObject(testCase, {wheelEnabled: true, orientation: data.orientation}) + verify(control) + + compare(control.value, 0.0) + + mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(control.value, 0.1) + compare(control.position, 0.1) + + control.stepSize = 0.2 + + mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(control.value, 0.3) + compare(control.position, 0.3) + + control.stepSize = 10.0 + + mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(control.value, 0.0) + compare(control.position, 0.0) + + control.to = 10.0 + control.stepSize = 5.0 + + mouseWheel(control, control.width / 2, control.height / 2, data.dx, data.dy) + compare(control.value, 5.0) + compare(control.position, 0.5) + + mouseWheel(control, control.width / 2, control.height / 2, 0.5 * data.dx, 0.5 * data.dy) + compare(control.value, 7.5) + compare(control.position, 0.75) + + mouseWheel(control, control.width / 2, control.height / 2, -data.dx, -data.dy) + compare(control.value, 2.5) + compare(control.position, 0.25) + + control.destroy() + } } -- cgit v1.2.3 From 838fd79152957f457a47cd30970961a27f086848 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 29 Nov 2016 10:28:33 +0100 Subject: SwipeDelegate: fix animations when releasing from a drag 9812a9c changed the order in which the pressed and position state is set. Before, when releasing after swiping, it would be: set pressed to false => set position After 9812a9c, it became: set position => set pressed to false The original order is necessary to ensure that animations can rely on being enabled *before* position changes, as their enabled expression typically looks something like this: enabled: !control.down This patch duplicates the contents of QQuickAbstractButton::mouseUngrabEvent() for now, with a TODO comment to ensure that it's moved into a private helper that we can call later on. Task-number: QTBUG-57350 Change-Id: I31af7a665fb2d0e37548df31560ed7bbb0c3cadb Reviewed-by: Mitch Curtis Reviewed-by: J-P Nurmi --- tests/auto/controls/data/tst_swipedelegate.qml | 50 ++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests') diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml index 0404fd86..6d017dc8 100644 --- a/tests/auto/controls/data/tst_swipedelegate.qml +++ b/tests/auto/controls/data/tst_swipedelegate.qml @@ -1073,4 +1073,54 @@ TestCase { mouseRelease(control, control.width + 10, control.height / 2, Qt.LeftButton); verify(mouseSignalSequenceSpy.success); } + + + Component { + id: animationSwipeDelegateComponent + + SwipeDelegate { + id: control + text: "SwipeDelegate" + width: 150 + swipe.left: greenLeftComponent + swipe.right: redRightComponent + + property alias behavior: xBehavior + property alias animation: numberAnimation + + background: Rectangle { + color: control.down ? "#ccc" : "#fff" + + Behavior on x { + id: xBehavior + enabled: !control.down + + NumberAnimation { + id: numberAnimation + easing.type: Easing.InOutCubic + duration: 400 + } + } + } + } + } + + function test_animations() { + // Test that animations are run when releasing from a drag. + var control = animationSwipeDelegateComponent.createObject(testCase); + verify(control); + + mousePress(control, control.width / 2, control.height / 2, Qt.LeftButton); + mouseMove(control, control.width - 1, control.height / 2, Qt.LeftButton); + verify(control.down); + verify(!control.behavior.enabled); + verify(!control.animation.running); + + mouseRelease(control, control.width - 1, control.height / 2, Qt.LeftButton); + verify(!control.down); + verify(control.behavior.enabled); + verify(control.animation.running); + + control.destroy(); + } } -- cgit v1.2.3