From 4ab5b4de70a91e26c1736fa5757a4124b15bab3c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 2 May 2017 13:44:17 +0200 Subject: Drawer: fix drag-over-threshold calculation Don't steal a horizontal drag if a flickable has been dragged a long distance vertically, and then later the flick happens to exceed the horizontal drag threshold. Change-Id: Idf39997aa20cc41da561f182119199f30c63ba32 Task-number: QTBUG-60521 Reviewed-by: Mitch Curtis --- tests/auto/drawer/data/flickable.qml | 75 ++++++++++++++++++++++++++++++++++++ tests/auto/drawer/data/flicking.qml | 75 ------------------------------------ tests/auto/drawer/tst_drawer.cpp | 65 +++++++++++++++++++++---------- 3 files changed, 120 insertions(+), 95 deletions(-) create mode 100644 tests/auto/drawer/data/flickable.qml delete mode 100644 tests/auto/drawer/data/flicking.qml (limited to 'tests/auto') diff --git a/tests/auto/drawer/data/flickable.qml b/tests/auto/drawer/data/flickable.qml new file mode 100644 index 00000000..62256afd --- /dev/null +++ b/tests/auto/drawer/data/flickable.qml @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, 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 + property alias flickable: flickable + + Drawer { + id: drawer + width: 300 + height: 400 + + contentItem: ListView { + id: flickable + model: 100 + delegate: ItemDelegate { + width: parent.width + text: index + } + } + } +} diff --git a/tests/auto/drawer/data/flicking.qml b/tests/auto/drawer/data/flicking.qml deleted file mode 100644 index 62256afd..00000000 --- a/tests/auto/drawer/data/flicking.qml +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, 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 - property alias flickable: flickable - - Drawer { - id: drawer - width: 300 - height: 400 - - contentItem: ListView { - id: flickable - model: 100 - delegate: ItemDelegate { - width: parent.width - text: index - } - } - } -} diff --git a/tests/auto/drawer/tst_drawer.cpp b/tests/auto/drawer/tst_drawer.cpp index 37f00050..a7ebaa9e 100644 --- a/tests/auto/drawer/tst_drawer.cpp +++ b/tests/auto/drawer/tst_drawer.cpp @@ -91,7 +91,8 @@ private slots: void interactive_data(); void interactive(); - void flicking(); + void flickable_data(); + void flickable(); private: struct TouchDeviceDeleter @@ -889,9 +890,25 @@ void tst_Drawer::interactive() QCOMPARE(aboutToHideSpy.count(), 0); } -void tst_Drawer::flicking() +void tst_Drawer::flickable_data() { - QQuickApplicationHelper helper(this, QStringLiteral("flicking.qml")); + QTest::addColumn("mouse"); + QTest::addColumn("from"); + QTest::addColumn("to"); + + QTest::newRow("mouse,straight") << true << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("mouse,diagonal") << true << QPoint(200, 200) << QPoint(250, 100); + QTest::newRow("touch,straight") << false << QPoint(200, 200) << QPoint(200, 100); + QTest::newRow("touch,diagonal") << false << QPoint(200, 200) << QPoint(250, 100); +} + +void tst_Drawer::flickable() +{ + QFETCH(bool, mouse); + QFETCH(QPoint, from); + QFETCH(QPoint, to); + + QQuickApplicationHelper helper(this, QStringLiteral("flickable.qml")); QQuickWindow *window = helper.window; window->show(); QVERIFY(QTest::qWaitForWindowExposed(window)); @@ -908,23 +925,31 @@ void tst_Drawer::flicking() drawer->open(); QVERIFY(drawerOpenedSpy.wait()); - // mouse - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::mouseMove(window, QPoint(200, y), 1); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); - - // reset - flickable->setContentY(0); - QVERIFY(!flickable->isFlicking()); - - // touch - QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(200, 200)); - for (int y = 200; y > 100; y -= 10) - QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(200, y)); - QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(200, 100)); - QVERIFY(flickable->isFlicking()); + if (mouse) + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, from); + else + QTest::touchEvent(window, touchDevice.data()).press(0, from); + + static const int steps = 10; + for (int i = 0; i < steps; ++i) { + int x = i * qAbs(from.x() - to.x()) / steps; + int y = i * qAbs(from.y() - to.y()) / steps; + + if (mouse) + QTest::mouseMove(window, QPoint(x, y)); + else + QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(x, y)); + QTest::qWait(1); // avoid infinite velocity + } + + QVERIFY(flickable->isDragging()); + + if (mouse) + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, to); + else + QTest::touchEvent(window, touchDevice.data()).release(0, to); + + QVERIFY(!flickable->isDragging()); } QTEST_MAIN(tst_Drawer) -- cgit v1.2.3