A MouseArea should not receive move or release events if the press was not accepted.
authorMichael Brasser <michael.brasser@live.com>
Wed, 13 Feb 2013 04:19:10 +0000 (22:19 -0600)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 14 Feb 2013 14:04:05 +0000 (15:04 +0100)
Change-Id: If70650d7150b224f4460697a953611dd37d57af1
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>

src/quick/items/qquickwindow.cpp
tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml [new file with mode: 0644]
tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp

index f433428..469ea42 100644 (file)
@@ -1218,7 +1218,7 @@ bool QQuickWindowPrivate::deliverInitialMousePressEvent(QQuickItem *item, QMouse
             event->setAccepted(me->isAccepted());
             if (me->isAccepted())
                 return true;
-            if (mouseGrabberItem && !event->buttons())
+            if (mouseGrabberItem)
                 mouseGrabberItem->ungrabMouse();
         }
     }
diff --git a/tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml b/tests/auto/quick/qquickmousearea/data/moveAndReleaseWithoutPress.qml
new file mode 100644 (file)
index 0000000..6c68f0c
--- /dev/null
@@ -0,0 +1,14 @@
+import QtQuick 2.0
+
+MouseArea {
+    width: 200
+    height: 200
+
+    property bool hadMove: false
+    property bool hadRelease: false
+
+    onPressed: mouse.accepted = false
+    onPositionChanged: hadMove = true
+    onReleased: hadRelease = true
+}
+
index ffe7b51..37ce0fd 100644 (file)
@@ -88,6 +88,7 @@ private slots:
 #ifndef QT_NO_CURSOR
     void cursorShape();
 #endif
+    void moveAndReleaseWithoutPress();
 
 private:
     void acceptedButton_data();
@@ -1402,6 +1403,29 @@ void tst_QQuickMouseArea::cursorShape()
 }
 #endif
 
+void tst_QQuickMouseArea::moveAndReleaseWithoutPress()
+{
+    QQuickView *window = createView();
+
+    window->setSource(testFileUrl("moveAndReleaseWithoutPress.qml"));
+    window->show();
+    window->requestActivate();
+    QVERIFY(QTest::qWaitForWindowExposed(window));
+
+    QObject *root = window->rootObject();
+    QVERIFY(root);
+
+    QTest::mousePress(window, Qt::LeftButton, 0, QPoint(100,100));
+
+    QTest::mouseMove(window, QPoint(110,110), 50);
+    QTRY_COMPARE(root->property("hadMove").toBool(), false);
+
+    QTest::mouseRelease(window, Qt::LeftButton, 0, QPoint(110,110));
+    QTRY_COMPARE(root->property("hadRelease").toBool(), false);
+
+    delete window;
+}
+
 QTEST_MAIN(tst_QQuickMouseArea)
 
 #include "tst_qquickmousearea.moc"