diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-02-16 08:43:08 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2018-07-27 10:43:04 +0000 |
commit | f2ba3bd9792500b4d3fcfd23b03098a32641ef4f (patch) | |
tree | 5fdae298618ae42ae6e2d456bb719168377274db /tests/auto/quick/pointerhandlers | |
parent | 0e1f83dcade8cb6428513eea4452dcd500f9e486 (diff) |
PointHandler: stay active as long as acceptedButtons satisfied
Ignore buttons which do not fit the acceptedButtons filter, and
do not assume that it's all over when any release happens.
Task-number: QTBUG-66360
Change-Id: I871ea7fdd9b76f06fa0d73382617b287c04d35ab
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/quick/pointerhandlers')
4 files changed, 286 insertions, 0 deletions
diff --git a/tests/auto/quick/pointerhandlers/pointerhandlers.pro b/tests/auto/quick/pointerhandlers/pointerhandlers.pro index 2492924944..dc14bc1c27 100644 --- a/tests/auto/quick/pointerhandlers/pointerhandlers.pro +++ b/tests/auto/quick/pointerhandlers/pointerhandlers.pro @@ -5,6 +5,7 @@ qtConfig(private_tests) { flickableinterop \ multipointtoucharea_interop \ qquickpointerhandler \ + qquickpointhandler \ qquickdraghandler \ qquicktaphandler \ } diff --git a/tests/auto/quick/pointerhandlers/qquickpointhandler/data/pointTracker.qml b/tests/auto/quick/pointerhandlers/qquickpointhandler/data/pointTracker.qml new file mode 100644 index 0000000000..674bbda850 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickpointhandler/data/pointTracker.qml @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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:GPL-EXCEPT$ +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 + +Item { + width: 200 + height: 200 + Rectangle { + id: rect + objectName: "pointTracker" + width: 20 + height: 20 + radius: 10 + color: "green" + x: handler.point.position.x + y: handler.point.position.y + } + + Text { + id: text + anchors.top: rect.bottom + anchors.left: rect.right + text: "<" + handler.point.position.x + ", " + handler.point.position.y + "> " + handler.point.pressedButtons + " [" + handler.point.pressure + "]" + } + + PointHandler { + id: handler + objectName: "pointHandler" + acceptedButtons: Qt.LeftButton | Qt.RightButton + } +} diff --git a/tests/auto/quick/pointerhandlers/qquickpointhandler/qquickpointhandler.pro b/tests/auto/quick/pointerhandlers/qquickpointhandler/qquickpointhandler.pro new file mode 100644 index 0000000000..d64fc96d74 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickpointhandler/qquickpointhandler.pro @@ -0,0 +1,15 @@ +CONFIG += testcase + +TARGET = tst_qquickpointhandler +QT += core-private gui-private qml-private quick-private testlib + +macos:CONFIG -= app_bundle + +SOURCES += tst_qquickpointhandler.cpp + +include (../../../shared/util.pri) +include (../../shared/util.pri) + +TESTDATA = data/* + +OTHER_FILES += data/pointTracker.qml \ diff --git a/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp new file mode 100644 index 0000000000..4253937280 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp @@ -0,0 +1,213 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQml module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <QtQuick/qquickview.h> +#include <QtQuick/qquickitem.h> +#include <QtQuick/private/qquickpointhandler_p.h> +#include <qpa/qwindowsysteminterface.h> + +#include <private/qquickwindow_p.h> + +#include <QtQml/qqmlengine.h> +#include <QtQml/qqmlproperty.h> + +#include "../../../shared/util.h" +#include "../../shared/viewtestutil.h" + +Q_LOGGING_CATEGORY(lcPointerTests, "qt.quick.pointer.tests") + +class tst_PointHandler : public QQmlDataTest +{ + Q_OBJECT +public: + tst_PointHandler() + {} + +private slots: + void initTestCase(); + + void pressedMultipleButtons_data(); + void pressedMultipleButtons(); + +private: + void createView(QScopedPointer<QQuickView> &window, const char *fileName); +}; + +void tst_PointHandler::createView(QScopedPointer<QQuickView> &window, const char *fileName) +{ + window.reset(new QQuickView); + window->setSource(testFileUrl(fileName)); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickViewTestUtil::centerOnScreen(window.data()); + QQuickViewTestUtil::moveMouseAway(window.data()); + + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window.data())); + QVERIFY(window->rootObject() != nullptr); +} + +void tst_PointHandler::initTestCase() +{ + // This test assumes that we don't get synthesized mouse events from QGuiApplication + qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents, false); + + QQmlDataTest::initTestCase(); +} + +void tst_PointHandler::pressedMultipleButtons_data() +{ + QTest::addColumn<Qt::MouseButtons>("accepted"); + QTest::addColumn<QList<Qt::MouseButtons> >("buttons"); + QTest::addColumn<QList<bool> >("active"); + QTest::addColumn<QList<Qt::MouseButtons> >("pressedButtons"); + QTest::addColumn<int>("changeCount"); + + QList<Qt::MouseButtons> buttons; + QList<bool> active; + QList<Qt::MouseButtons> pressedButtons; + buttons << Qt::LeftButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::LeftButton + << Qt::NoButton; + active << true + << true + << true + << false; + pressedButtons << Qt::LeftButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::LeftButton + << Qt::NoButton; + QTest::newRow("Accept Left - Press left, Press Right, Release Right") + << Qt::MouseButtons(Qt::LeftButton) << buttons << active << pressedButtons << 4; + + buttons.clear(); + active.clear(); + pressedButtons.clear(); + buttons << Qt::LeftButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::RightButton + << Qt::NoButton; + active << true + << true + << false + << false; + pressedButtons << Qt::LeftButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::NoButton // Not the "truth" but filtered according to this handler's acceptedButtons + << Qt::NoButton; + QTest::newRow("Accept Left - Press left, Press Right, Release Left") + << Qt::MouseButtons(Qt::LeftButton) << buttons << active << pressedButtons << 3; + + buttons.clear(); + active.clear(); + pressedButtons.clear(); + buttons << Qt::LeftButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::LeftButton + << Qt::NoButton; + active << true + << true + << true + << false; + pressedButtons << Qt::LeftButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::LeftButton + << Qt::NoButton; + QTest::newRow("Accept Left|Right - Press left, Press Right, Release Right") + << (Qt::LeftButton | Qt::RightButton) << buttons << active << pressedButtons << 4; + + buttons.clear(); + active.clear(); + pressedButtons.clear(); + buttons << Qt::RightButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::LeftButton + << Qt::NoButton; + active << true + << true + << false + << false; + pressedButtons << Qt::RightButton + << (Qt::LeftButton | Qt::RightButton) + << Qt::NoButton // Not the "truth" but filtered according to this handler's acceptedButtons + << Qt::NoButton; + QTest::newRow("Accept Right - Press Right, Press Left, Release Right") + << Qt::MouseButtons(Qt::RightButton) << buttons << active << pressedButtons << 3; +} + +void tst_PointHandler::pressedMultipleButtons() +{ + QFETCH(Qt::MouseButtons, accepted); + QFETCH(QList<Qt::MouseButtons>, buttons); + QFETCH(QList<bool>, active); + QFETCH(QList<Qt::MouseButtons>, pressedButtons); + QFETCH(int, changeCount); + + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "pointTracker.qml"); + QQuickView * window = windowPtr.data(); + QQuickItem *tracker = window->rootObject()->findChild<QQuickItem *>("pointTracker"); + QVERIFY(tracker); + QQuickPointHandler *handler = window->rootObject()->findChild<QQuickPointHandler *>("pointHandler"); + QVERIFY(handler); + + QSignalSpy activeSpy(handler, SIGNAL(activeChanged())); + QSignalSpy pointSpy(handler, SIGNAL(pointChanged())); + handler->setAcceptedButtons(accepted); + + QPoint point(100,100); + + for (int i = 0; i < buttons.count(); ++i) { + int btns = int(buttons.at(i)); + int release = 0; + if (i > 0) { + int lastBtns = int(buttons.at(i - 1)); + release = lastBtns & ~btns; + } + if (release) + QTest::mouseRelease(windowPtr.data(), Qt::MouseButton(release), Qt::NoModifier, point); + else + QTest::mousePress(windowPtr.data(), Qt::MouseButton(btns), Qt::NoModifier, point); + + qCDebug(lcPointerTests) << i << ": acceptedButtons" << handler->acceptedButtons() + << "; comparing" << handler->point().pressedButtons() << pressedButtons.at(i); + QCOMPARE(handler->point().pressedButtons(), pressedButtons.at(i)); + QCOMPARE(handler->active(), active.at(i)); + } + + QTest::mousePress(windowPtr.data(), Qt::NoButton, Qt::NoModifier, point); + QCOMPARE(handler->active(), false); + QCOMPARE(activeSpy.count(), 2); + QCOMPARE(pointSpy.count(), changeCount); +} + +QTEST_MAIN(tst_PointHandler) + +#include "tst_qquickpointhandler.moc" |