From 7b2e2117162594a2d0234bb02408f5b5a446488b Mon Sep 17 00:00:00 2001 From: Frederik Gladhorn Date: Thu, 8 Nov 2012 17:43:46 +0100 Subject: Ungrab mouse upon leave event. 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 --- src/quick/items/qquickwindow.cpp | 2 ++ tests/auto/quick/touchmouse/tst_touchmouse.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp index 4ea31a0d6f..806766d00b 100644 --- a/src/quick/items/qquickwindow.cpp +++ b/src/quick/items/qquickwindow.cpp @@ -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: diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index 4a681e270e..0590bd89eb 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -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("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); -- cgit v1.2.3