aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@remarkable.com>2020-04-01 07:16:05 +0200
committerFrederik Gladhorn <frederik.gladhorn@remarkable.com>2020-04-01 07:16:05 +0200
commitd28792c46d2c0482d7e958308dfadfa05b0265f8 (patch)
tree01362bd358bbdcfafee76aa7519bfb8f4eff3bf0
parent8dfcc71953cd36370bcf19f537445e3766f39635 (diff)
parent8ace780b5aa298e3c01903bfd57f766a42209191 (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
-rw-r--r--src/quick/items/qquickmousearea.cpp6
-rw-r--r--tests/auto/quick/qquickmousearea/data/settingHiddenInPressUngrabs.qml36
-rw-r--r--tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp38
3 files changed, 80 insertions, 0 deletions
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index fd2458494c..f54858e4eb 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -1063,6 +1063,12 @@ void QQuickMouseArea::itemChange(ItemChange change, const ItemChangeData &value)
}
setHovered(!d->hovered);
}
+ if (d->pressed && (!isVisible())) {
+ // This happens when the mouse area sets itself disabled or hidden
+ // inside the press handler. In that case we should not keep the internal
+ // state as pressed, since we never became the mouse grabber.
+ ungrabMouse();
+ }
break;
default:
break;
diff --git a/tests/auto/quick/qquickmousearea/data/settingHiddenInPressUngrabs.qml b/tests/auto/quick/qquickmousearea/data/settingHiddenInPressUngrabs.qml
new file mode 100644
index 0000000000..4532dabfd8
--- /dev/null
+++ b/tests/auto/quick/qquickmousearea/data/settingHiddenInPressUngrabs.qml
@@ -0,0 +1,36 @@
+import QtQuick 2.11
+import QtQuick.Window 2.11
+
+Window {
+ id: window
+ visible: true
+ width: 200
+ height: 200
+
+ MouseArea {
+ objectName: "cat"
+ anchors.fill: parent
+ onPressed: visible = false
+ width: parent.width / 2
+ height: parent.height
+ Rectangle {
+ width: 10
+ height: 10
+ color: "blue"
+ }
+ }
+ MouseArea {
+ objectName: "mouse"
+ x: parent.width / 2
+ width: parent.width / 2
+ height: parent.height
+ onPressed: {
+ enabled = false
+ }
+ Rectangle {
+ width: 10
+ height: 10
+ color: "blue"
+ }
+ }
+}
diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
index 3503e8a9fd..5879fc6897 100644
--- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
+++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp
@@ -158,6 +158,7 @@ private slots:
void pressOneAndTapAnother();
void mask();
void nestedEventDelivery();
+ void settingHiddenInPressUngrabs();
private:
int startDragDistance() const {
@@ -2346,6 +2347,43 @@ void tst_QQuickMouseArea::nestedEventDelivery() // QTBUG-70898
QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(50,150));
}
+void tst_QQuickMouseArea::settingHiddenInPressUngrabs()
+{
+ // When an item sets itself hidden, while handling pressed, it doesn't receive the grab.
+ // But that in turn means it doesn't see any release events, so we need to make sure it
+ // receives an ungrab event.
+
+ QQmlEngine engine;
+ QQmlComponent c(&engine, testFileUrl("settingHiddenInPressUngrabs.qml"));
+ QScopedPointer<QQuickWindow> window(qmlobject_cast<QQuickWindow *>(c.create()));
+ QVERIFY(window.data());
+ window->show();
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QQuickMouseArea *catArea = window->findChild<QQuickMouseArea*>("cat");
+ QVERIFY(catArea != nullptr);
+ auto pointOnCatArea = catArea->mapToScene(QPointF(5.0, 5.0)).toPoint();
+ QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, pointOnCatArea);
+
+ QCoreApplication::processEvents();
+ // The click hides the cat area
+ QTRY_VERIFY(!catArea->isVisible());
+ // The cat area is not stuck in pressed state.
+ QVERIFY(!catArea->pressed());
+
+ QQuickMouseArea *mouseArea = window->findChild<QQuickMouseArea*>("mouse");
+ QVERIFY(mouseArea != nullptr);
+ auto pointOnMouseArea = mouseArea->mapToScene(QPointF(5.0, 5.0)).toPoint();
+ QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, pointOnMouseArea);
+
+ QCoreApplication::processEvents();
+ // The click disables the mouse area
+ QTRY_VERIFY(!mouseArea->isEnabled());
+ // The mouse area is not stuck in pressed state.
+ QVERIFY(!mouseArea->pressed());
+}
+
QTEST_MAIN(tst_QQuickMouseArea)
#include "tst_qquickmousearea.moc"