Ungrab mouse upon leave event.
authorFrederik Gladhorn <frederik.gladhorn@digia.com>
Thu, 8 Nov 2012 16:43:46 +0000 (17:43 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 21 Nov 2012 10:58:16 +0000 (11:58 +0100)
The event signals that the mouse has left the window.
This happens also when a popup is shown (overlapping the original window).
Before a mouse area would still think it was in pressed state
when the popup (QWindow/QMenu) was shown and even after the popup was closed.

Change-Id: I6d32571f5a473610f60e9476850989ff665edb93
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
src/quick/items/qquickwindow.cpp
tests/auto/quick/touchmouse/tst_touchmouse.cpp

index 4ea31a0..806766d 100644 (file)
@@ -1131,6 +1131,8 @@ bool QQuickWindow::event(QEvent *e)
     case QEvent::Leave:
         d->clearHover();
         d->lastMousePosition = QPoint();
+        if (d->mouseGrabberItem)
+            d->mouseGrabberItem->ungrabMouse();
         break;
 #ifndef QT_NO_DRAGANDDROP
     case QEvent::DragEnter:
index 4a681e2..0590bd8 100644 (file)
@@ -823,7 +823,10 @@ void tst_TouchMouse::mouseOnFlickableOnPinch()
     window->setSource(testFileUrl("mouseonflickableonpinch.qml"));
     window->show();
     window->requestActivate();
+    QVERIFY(QTest::qWaitForWindowActive(window));
     QVERIFY(window->rootObject() != 0);
+    QRect windowRect = QRect(window->position(), window->size());
+    QCursor::setPos(windowRect.center());
 
     QQuickPinchArea *pinchArea = window->rootObject()->findChild<QQuickPinchArea*>("pincharea");
     QVERIFY(pinchArea);
@@ -841,14 +844,11 @@ void tst_TouchMouse::mouseOnFlickableOnPinch()
     QTest::touchEvent(window, device).move(0, p, window);
     p -= QPoint(10, 0);
     QTest::touchEvent(window, device).move(0, p, window);
-
-    QTest::qWait(1000);
-
+    QGuiApplication::processEvents();
     p -= QPoint(10, 0);
     QTest::touchEvent(window, device).move(0, p, window);
     QTest::touchEvent(window, device).release(0, p, window);
-
-    QTest::qWait(1000);
+    QGuiApplication::processEvents();
 
     //QVERIFY(flickable->isMovingHorizontally());
     qDebug() << "Pos: " << rect->pos();
@@ -890,13 +890,13 @@ void tst_TouchMouse::mouseOnFlickableOnPinch()
     pinchSequence.move(0, p, window).commit();
     p -= QPoint(10, 0);
     pinchSequence.move(0, p, window).commit();
-    QTest::qWait(1000);
+    QGuiApplication::processEvents();
     p -= QPoint(10, 0);
     pinchSequence.move(0, p, window).commit();
 
     QQuickWindowPrivate *windowPriv = QQuickWindowPrivate::get(window);
-    QCOMPARE(windowPriv->mouseGrabberItem, flickable);
     qDebug() << "Mouse Grabber: " << windowPriv->mouseGrabberItem << " itemForTouchPointId: " << windowPriv->itemForTouchPointId;
+    QCOMPARE(windowPriv->mouseGrabberItem, flickable);
 
     // Add a second finger, this should lead to stealing
     p1 = QPoint(40, 100);