aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickmousearea
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/quick/qquickmousearea')
-rw-r--r--tests/auto/quick/qquickmousearea/CMakeLists.txt6
-rw-r--r--tests/auto/quick/qquickmousearea/data/clickThrough2.qml6
-rw-r--r--tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml15
-rw-r--r--tests/auto/quick/qquickmousearea/data/cursorUpdating.qml71
-rw-r--r--tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml2
-rw-r--r--tests/auto/quick/qquickmousearea/data/ignoreBySource.qml2
-rw-r--r--tests/auto/quick/qquickmousearea/data/mask.qml2
-rw-r--r--tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml2
-rw-r--r--tests/auto/quick/qquickmousearea/data/qtbug34368.qml4
-rw-r--r--tests/auto/quick/qquickmousearea/data/qtbug49100.qml2
-rw-r--r--tests/auto/quick/qquickmousearea/data/rejectEvent.qml2
-rw-r--r--tests/auto/quick/qquickmousearea/data/updateMousePosOnResize.qml6
-rw-r--r--tests/auto/quick/qquickmousearea/data/wheel.qml2
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp125
14 files changed, 224 insertions, 23 deletions
diff --git a/tests/auto/quick/qquickmousearea/CMakeLists.txt b/tests/auto/quick/qquickmousearea/CMakeLists.txt
index d358dfb0e8..48262229fc 100644
--- a/tests/auto/quick/qquickmousearea/CMakeLists.txt
+++ b/tests/auto/quick/qquickmousearea/CMakeLists.txt
@@ -7,6 +7,12 @@
## tst_qquickmousearea Test:
#####################################################################
+if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qquickmousearea LANGUAGES CXX)
+ find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST)
+endif()
+
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
diff --git a/tests/auto/quick/qquickmousearea/data/clickThrough2.qml b/tests/auto/quick/qquickmousearea/data/clickThrough2.qml
index 2624108225..4e87b4eeb5 100644
--- a/tests/auto/quick/qquickmousearea/data/clickThrough2.qml
+++ b/tests/auto/quick/qquickmousearea/data/clickThrough2.qml
@@ -28,8 +28,8 @@ Item{
enabled: true
anchors.fill: parent
propagateComposedEvents: !noPropagation
- onClicked: mouse.accepted = !letThrough;
- onDoubleClicked: mouse.accepted = !letThrough;
- onPressAndHold: mouse.accepted = !letThrough;
+ onClicked: function (mouse) { mouse.accepted = !letThrough; }
+ onDoubleClicked: function (mouse) { mouse.accepted = !letThrough; }
+ onPressAndHold: function (mouse) { mouse.accepted = !letThrough; }
}
}
diff --git a/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml b/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml
new file mode 100644
index 0000000000..d98ef85c55
--- /dev/null
+++ b/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml
@@ -0,0 +1,15 @@
+import QtQuick
+
+Rectangle {
+ width: 200
+ height: 200
+ visible: true
+ MouseArea {
+ id: mouseArea
+ objectName: "mouseArea"
+ anchors.fill: parent
+ hoverEnabled: false
+ onPressed: function(mouse) { mouse.accepted = false }
+ }
+}
+
diff --git a/tests/auto/quick/qquickmousearea/data/cursorUpdating.qml b/tests/auto/quick/qquickmousearea/data/cursorUpdating.qml
new file mode 100644
index 0000000000..2d06543c78
--- /dev/null
+++ b/tests/auto/quick/qquickmousearea/data/cursorUpdating.qml
@@ -0,0 +1,71 @@
+import QtQuick
+
+Item {
+ width: 600
+ height: 600
+
+ ListModel {
+ id: cursorsModel
+ ListElement { cursorShape: Qt.ArrowCursor; text: "Arrow" }
+ ListElement { cursorShape: Qt.UpArrowCursor; text: "UpArrow" }
+ ListElement { cursorShape: Qt.CrossCursor; text: "Cross" }
+ ListElement { cursorShape: Qt.WaitCursor; text: "Wait" }
+ ListElement { cursorShape: Qt.IBeamCursor; text: "IBeam" }
+ ListElement { cursorShape: Qt.SizeVerCursor; text: "SizeVer" }
+ ListElement { cursorShape: Qt.SizeHorCursor; text: "SizeHor" }
+ ListElement { cursorShape: Qt.SizeBDiagCursor; text: "SizeBDiag" }
+ ListElement { cursorShape: Qt.SizeFDiagCursor; text: "SizeFDiag" }
+ ListElement { cursorShape: Qt.SizeAllCursor; text: "SizeAll" }
+ ListElement { cursorShape: Qt.BlankCursor; text: "Blank" }
+ ListElement { cursorShape: Qt.SplitVCursor; text: "SplitV" }
+ ListElement { cursorShape: Qt.SplitHCursor; text: "SplitH" }
+ ListElement { cursorShape: Qt.PointingHandCursor; text: "PointingHand" }
+ ListElement { cursorShape: Qt.ForbiddenCursor; text: "Forbidden" }
+ ListElement { cursorShape: Qt.WhatsThisCursor; text: "WhatsThis" }
+ ListElement { cursorShape: Qt.BusyCursor; text: "Busy" }
+ ListElement { cursorShape: Qt.OpenHandCursor; text: "OpenHand" }
+ ListElement { cursorShape: Qt.ClosedHandCursor; text: "ClosedHand" }
+ ListElement { cursorShape: Qt.DragCopyCursor; text: "DragCopy" }
+ ListElement { cursorShape: Qt.DragMoveCursor; text: "DragMove" }
+ ListElement { cursorShape: Qt.DragLinkCursor; text: "DragLink" }
+ }
+
+ Flickable {
+ anchors.fill: parent
+ contentHeight: flow.height
+ Flow {
+ id: flow
+ width: parent.width
+ Repeater {
+ model: cursorsModel
+ Rectangle {
+ id: root
+ color: "white"
+ border.width: 5
+ border.color: "black"
+
+ width: 200
+ height: 200
+
+ Text {
+ id: textItem
+ anchors.fill: parent
+ anchors.margins: parent.width * 0.1
+ text: model.text
+ fontSizeMode: Text.Fit
+ minimumPixelSize: 10; font.pixelSize: height
+ verticalAlignment: Text.AlignVCenter
+ horizontalAlignment: Text.AlignHCenter
+ }
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ hoverEnabled: true
+ cursorShape: model.cursorShape
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml b/tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml
index 69ec8fbd47..97512d1106 100644
--- a/tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml
+++ b/tests/auto/quick/qquickmousearea/data/hoverAfterPress.qml
@@ -16,7 +16,7 @@ Item {
objectName: "mouseArea"
anchors.fill: parent
hoverEnabled: true
- onPressed: mouse.accepted = false
+ onPressed: function (mouse) { mouse.accepted = false }
//onContainsMouseChanged: print("containsMouse changed =", containsMouse)
Rectangle {
diff --git a/tests/auto/quick/qquickmousearea/data/ignoreBySource.qml b/tests/auto/quick/qquickmousearea/data/ignoreBySource.qml
index a53cbf7b1d..bb20a317f7 100644
--- a/tests/auto/quick/qquickmousearea/data/ignoreBySource.qml
+++ b/tests/auto/quick/qquickmousearea/data/ignoreBySource.qml
@@ -21,7 +21,7 @@ Item {
MouseArea {
id: ma
objectName: "mousearea"
- onPressed: {
+ onPressed: function (mouse) {
root.lastEventSource = mouse.source
if (mouse.source !== root.allowedSource)
mouse.accepted = false
diff --git a/tests/auto/quick/qquickmousearea/data/mask.qml b/tests/auto/quick/qquickmousearea/data/mask.qml
index 1e8ae7c98a..ab8ecbf32d 100644
--- a/tests/auto/quick/qquickmousearea/data/mask.qml
+++ b/tests/auto/quick/qquickmousearea/data/mask.qml
@@ -1,5 +1,5 @@
// Copyright (C) 2017 Ford Motor Company
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick 2.11
import Test 1.0
diff --git a/tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml b/tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml
index 6c68f0c7c8..4b7324a98a 100644
--- a/tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml
+++ b/tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml
@@ -7,7 +7,7 @@ MouseArea {
property bool hadMove: false
property bool hadRelease: false
- onPressed: mouse.accepted = false
+ onPressed: function (mouse) { mouse.accepted = false }
onPositionChanged: hadMove = true
onReleased: hadRelease = true
}
diff --git a/tests/auto/quick/qquickmousearea/data/qtbug34368.qml b/tests/auto/quick/qquickmousearea/data/qtbug34368.qml
index 42d8ddd3b6..96e72a8edc 100644
--- a/tests/auto/quick/qquickmousearea/data/qtbug34368.qml
+++ b/tests/auto/quick/qquickmousearea/data/qtbug34368.qml
@@ -12,7 +12,7 @@ Rectangle {
anchors.fill: parent
propagateComposedEvents: true
z: 1
- onClicked: {
+ onClicked: function (mouse) {
mouse.accepted = false;
clicksEnabled += 1;
//console.log("Upper click");
@@ -23,7 +23,7 @@ Rectangle {
propagateComposedEvents: true
z: 0
enabled: !disableLower
- onClicked: {
+ onClicked: function (mouse) {
mouse.accepted = false;
clicksDisabled += 1;
//console.log("Lower click");
diff --git a/tests/auto/quick/qquickmousearea/data/qtbug49100.qml b/tests/auto/quick/qquickmousearea/data/qtbug49100.qml
index 39b293c8fa..d3dfe64d94 100644
--- a/tests/auto/quick/qquickmousearea/data/qtbug49100.qml
+++ b/tests/auto/quick/qquickmousearea/data/qtbug49100.qml
@@ -8,7 +8,7 @@ ListView {
delegate: Text {
text: index + 1
height: 30
- width: parent.width
+ width: ListView.view.width
MouseArea {
anchors.fill: parent
}
diff --git a/tests/auto/quick/qquickmousearea/data/rejectEvent.qml b/tests/auto/quick/qquickmousearea/data/rejectEvent.qml
index 48b68ee845..03a075300a 100644
--- a/tests/auto/quick/qquickmousearea/data/rejectEvent.qml
+++ b/tests/auto/quick/qquickmousearea/data/rejectEvent.qml
@@ -23,7 +23,7 @@ Rectangle {
id: mouseRegion2
objectName: "mouseRegion2"
width: 120; height: 120
- onPressed: { root.mr2_pressed = true; mouse.accepted = false }
+ onPressed: function (mouse) { root.mr2_pressed = true; mouse.accepted = false }
onReleased: { root.mr2_released = true }
onCanceled: { root.mr2_canceled = true }
}
diff --git a/tests/auto/quick/qquickmousearea/data/updateMousePosOnResize.qml b/tests/auto/quick/qquickmousearea/data/updateMousePosOnResize.qml
index 55af864060..a20f752864 100644
--- a/tests/auto/quick/qquickmousearea/data/updateMousePosOnResize.qml
+++ b/tests/auto/quick/qquickmousearea/data/updateMousePosOnResize.qml
@@ -22,19 +22,19 @@ Rectangle {
property bool mouseMatchesPos: true
anchors.fill: brother
- onPressed: {
+ onPressed: function (mouse) {
if (mouse.x != mouseX || mouse.y != mouseY)
mouseMatchesPos = false
x1 = mouseX; y1 = mouseY
anchors.fill = parent
}
onPositionChanged: { emitPositionChanged = true }
- onMouseXChanged: {
+ onMouseXChanged: function (mouse) {
if (mouse.x != mouseX || mouse.y != mouseY)
mouseMatchesPos = false
x2 = mouseX; y2 = mouseY
}
- onMouseYChanged: {
+ onMouseYChanged: function (mouse) {
if (mouse.x != mouseX || mouse.y != mouseY)
mouseMatchesPos = false
x2 = mouseX; y2 = mouseY
diff --git a/tests/auto/quick/qquickmousearea/data/wheel.qml b/tests/auto/quick/qquickmousearea/data/wheel.qml
index 3e0c0c2a48..6cd367b22f 100644
--- a/tests/auto/quick/qquickmousearea/data/wheel.qml
+++ b/tests/auto/quick/qquickmousearea/data/wheel.qml
@@ -14,7 +14,7 @@ Rectangle {
MouseArea {
anchors.fill: parent
- onWheel: {
+ onWheel: function (wheel) {
root.angleDeltaY = wheel.angleDelta.y;
root.mouseX = wheel.x;
root.mouseY = wheel.y;
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index fd2b442a63..37d8c910f5 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -1,5 +1,5 @@
// Copyright (C) 2020 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QtTest>
#include <QtTest/QSignalSpy>
@@ -23,6 +23,11 @@
Q_LOGGING_CATEGORY(lcTests, "qt.quick.tests")
+static bool isPlatformWayland()
+{
+ return !QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive);
+}
+
class CircleMask : public QObject
{
Q_OBJECT
@@ -95,6 +100,7 @@ private slots:
void pressedCanceledOnWindowDeactivate();
void doubleClick_data() { acceptedButton_data(); }
void doubleClick();
+ void doubleTap();
void clickTwice_data() { acceptedButton_data(); }
void clickTwice();
void invalidClick_data() { rejectedButton_data(); }
@@ -120,6 +126,7 @@ private slots:
void changeAxis();
#if QT_CONFIG(cursor)
void cursorShape();
+ void cursorUpdating();
#endif
void moveAndReleaseWithoutPress();
void nestedStopAtBounds();
@@ -139,6 +146,7 @@ private slots:
void negativeZStackingOrder();
void containsMouseAndVisibility();
void containsMouseAndVisibilityMasked();
+ void containsMouseAndHoverDisabled();
void doubleClickToHide();
void releaseFirstTouchAfterSecond();
#if QT_CONFIG(tabletevent)
@@ -933,6 +941,61 @@ void tst_QQuickMouseArea::doubleClick()
QCOMPARE(window.rootObject()->property("released").toInt(), 2);
}
+void tst_QQuickMouseArea::doubleTap() // QTBUG-112434
+{
+ QQuickView window;
+ QVERIFY(QQuickTest::showView(window, testFileUrl("doubleclick.qml")));
+
+ QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mousearea");
+ QVERIFY(mouseArea);
+ QPoint p1 = mouseArea->mapToScene(mouseArea->boundingRect().center()).toPoint();
+
+ QTest::touchEvent(&window, device).press(0, p1);
+ QQuickTouchUtils::flush(&window);
+ QTest::touchEvent(&window, device).release(0, p1);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(window.rootObject()->property("released").toInt(), 1);
+ QCOMPARE(window.rootObject()->property("clicked").toInt(), 1);
+
+ p1 += QPoint(1, -1); // movement less than QPlatformTheme::TouchDoubleTapDistance
+ QTest::touchEvent(&window, device).press(1, p1); // touchpoint ID is different the second time
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(mouseArea->isPressed(), true);
+ // at this time QQuickDeliveryAgentPrivate::deliverTouchAsMouse() synthesizes the double-click event
+ QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 1);
+
+ QTest::touchEvent(&window, device).release(1, p1);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(window.rootObject()->property("released").toInt(), 2);
+ QCOMPARE(mouseArea->isPressed(), false);
+ QCOMPARE(window.rootObject()->property("clicked").toInt(), 1);
+
+ // now tap with two fingers simultaneously: only one of them generates synth-mouse
+ QPoint p2 = p1 + QPoint(50, 5);
+ QTest::touchEvent(&window, device).press(2, p1).press(3, p2);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(mouseArea->isPressed(), true);
+ QTest::touchEvent(&window, device).release(2, p1).release(3, p2);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(window.rootObject()->property("released").toInt(), 3);
+ QCOMPARE(window.rootObject()->property("clicked").toInt(), 2);
+ QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 1);
+ QCOMPARE(mouseArea->isPressed(), false);
+
+ // tap with two fingers simultaneously again: get another double-click from one point
+ p1 -= QPoint(1, -1);
+ p2 += QPoint(1, -1);
+ QTest::touchEvent(&window, device).press(4, p1).press(5, p2);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(mouseArea->isPressed(), true);
+ QTest::touchEvent(&window, device).release(4, p1).release(5, p2);
+ QQuickTouchUtils::flush(&window);
+ QCOMPARE(window.rootObject()->property("released").toInt(), 4);
+ QCOMPARE(window.rootObject()->property("clicked").toInt(), 2);
+ QCOMPARE(window.rootObject()->property("doubleClicked").toInt(), 2);
+ QCOMPARE(mouseArea->isPressed(), false); // make sure it doesn't get stuck
+}
+
// QTBUG-14832
void tst_QQuickMouseArea::clickTwice()
{
@@ -1563,11 +1626,11 @@ void tst_QQuickMouseArea::disableParentOnPress() // QTBUG-39806 and QTBUG-103788
QQuickTest::pointerPress(device, &window, 0, p);
QTRY_COMPARE(parentEnabledSpy.size(), 1);
- QCOMPARE(root->isEnabled(), false);
- QCOMPARE(mouseArea->isEnabled(), true); // enabled is independent, unfortunately (inverse of QTBUG-38364)
- QCOMPARE(QQuickItemPrivate::get(mouseArea)->effectiveEnable, false);
+ QVERIFY(!root->isEnabled());
+ QVERIFY(mouseArea->isEnabled()); // enabled is independent, unfortunately (inverse of QTBUG-38364)
+ QVERIFY(!QQuickItemPrivate::get(mouseArea)->effectiveEnable);
// bug fix: it knows it got effectively disabled, so now it's no longer pressed
- QCOMPARE(mouseArea->isPressed(), false);
+ QVERIFY(!mouseArea->isPressed());
QCOMPARE(canceledSpy.size(), 1); // ...because the press was canceled
QCOMPARE(pressedChangedSpy.size(), 2); // kerchunk
QQuickTest::pointerRelease(device, &window, 0, p);
@@ -1575,9 +1638,9 @@ void tst_QQuickMouseArea::disableParentOnPress() // QTBUG-39806 and QTBUG-103788
// now re-enable it and try again
root->setEnabled(true);
QQuickTest::pointerPress(device, &window, 0, p);
- QTRY_COMPARE(root->isEnabled(), false);
- QCOMPARE(QQuickItemPrivate::get(mouseArea)->effectiveEnable, false);
- QCOMPARE(mouseArea->isPressed(), false);
+ QTRY_VERIFY(!root->isEnabled());
+ QVERIFY(!QQuickItemPrivate::get(mouseArea)->effectiveEnable);
+ QVERIFY(!mouseArea->isPressed());
QCOMPARE(canceledSpy.size(), 2);
QCOMPARE(pressedChangedSpy.size(), 4);
QQuickTest::pointerRelease(device, &window, 0, p);
@@ -1844,6 +1907,38 @@ void tst_QQuickMouseArea::cursorShape()
QCOMPARE(mouseArea->cursor().shape(), Qt::WaitCursor);
QCOMPARE(spy.size(), 2);
}
+
+void tst_QQuickMouseArea::cursorUpdating()
+{
+ QQuickView window;
+ QVERIFY(QQuickTest::showView(window, testFileUrl("cursorUpdating.qml")));
+ QQuickItem *root = window.rootObject();
+ QVERIFY(root);
+ QQuickFlickable *flickable = root->findChild<QQuickFlickable*>();
+ QVERIFY(flickable);
+ QQuickItemPrivate *rootPrivate = QQuickItemPrivate::get(root);
+ QVERIFY(rootPrivate->subtreeCursorEnabled);
+
+ QTest::mouseMove(&window, QPoint(40, 40));
+ QCOMPARE(window.cursor().shape(), Qt::ArrowCursor);
+
+ QTest::mouseMove(&window, QPoint(240, 40));
+ QCOMPARE(window.cursor().shape(), Qt::UpArrowCursor);
+
+ if (isPlatformWayland())
+ QSKIP("Wayland: QCursor::setPos() doesn't work.");
+
+ // QTBUG-53987: with the cursor physically hovering, use wheel to
+ // position a different item that requests a different cursor
+ const QPoint p(240, 40);
+ const QPoint pg = window.mapToGlobal(p);
+ QCursor::setPos(pg);
+ QWheelEvent wheelEvent(p, pg, QPoint(60, -400), QPoint(0, -600),
+ Qt::NoButton, Qt::ControlModifier, Qt::NoScrollPhase, false);
+ QGuiApplication::sendEvent(&window, &wheelEvent);
+ QTRY_VERIFY(flickable->contentY() > 300);
+ QCOMPARE(window.cursor().shape(), Qt::IBeamCursor);
+}
#endif
void tst_QQuickMouseArea::moveAndReleaseWithoutPress()
@@ -2508,6 +2603,20 @@ void tst_QQuickMouseArea::containsMouseAndVisibilityMasked()
QTRY_VERIFY(!mouseArea2->hovered());
}
+// QTBUG-110594
+void tst_QQuickMouseArea::containsMouseAndHoverDisabled()
+{
+ QQuickView window;
+ QVERIFY(QQuickTest::showView(window, testFileUrl("containsMouseAndHoverDisabled.qml")));
+
+ QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea");
+ QVERIFY(mouseArea != nullptr);
+ QVERIFY(!mouseArea->hoverEnabled());
+
+ QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100));
+ QTRY_VERIFY(!mouseArea->hovered());
+}
+
// QTBUG-35995 and QTBUG-102158
void tst_QQuickMouseArea::doubleClickToHide()
{