From: Laszlo Agocs Date: Thu, 19 Apr 2012 08:31:14 +0000 (+0300) Subject: Avoid losing mouse events when the event loop gets spinned X-Git-Tag: 071012131707~576 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=051eb16536305f1a1b4c8b0eb17bab7599a11b00;p=profile%2Fivi%2Fqtdeclarative.git Avoid losing mouse events when the event loop gets spinned The touchMouseId value has to be updated to its potential new value before delivering the events. Change-Id: I47ac5b3aad63293e19985b7b242b56db258fe786 Reviewed-by: Martin Jones --- diff --git a/src/quick/items/qquickcanvas.cpp b/src/quick/items/qquickcanvas.cpp index 9110233..f59a89a 100644 --- a/src/quick/items/qquickcanvas.cpp +++ b/src/quick/items/qquickcanvas.cpp @@ -395,15 +395,19 @@ void QQuickCanvasPrivate::translateTouchToMouse(QTouchEvent *event) bool doubleClick = event->timestamp() - touchMousePressTimestamp < static_cast(qApp->styleHints()->mouseDoubleClickInterval()); touchMousePressTimestamp = event->timestamp(); + // Store the id already here and restore it to -1 if the event does not get + // accepted. Cannot defer setting the new value because otherwise if the event + // handler spins the event loop all subsequent moves and releases get lost. + touchMouseId = p.id(); QQuickMouseEventEx me = touchToMouseEvent(QEvent::MouseButtonPress, p); me.setTimestamp(event->timestamp()); me.setAccepted(false); me.setCapabilities(event->device()->capabilities()); deliverMouseEvent(&me); - if (me.isAccepted()) { - touchMouseId = p.id(); + if (me.isAccepted()) event->setAccepted(true); - } + else + touchMouseId = -1; if (doubleClick) { touchMousePressTimestamp = 0; QQuickMouseEventEx me = touchToMouseEvent(QEvent::MouseButtonDblClick, p); @@ -411,16 +415,16 @@ void QQuickCanvasPrivate::translateTouchToMouse(QTouchEvent *event) me.setAccepted(false); me.setCapabilities(event->device()->capabilities()); if (!mouseGrabberItem) { - if (deliverInitialMousePressEvent(rootItem, &me)) { - touchMouseId = p.id(); + if (deliverInitialMousePressEvent(rootItem, &me)) event->setAccepted(true); - } + else + touchMouseId = -1; } else { deliverMouseEvent(&me); - if (me.isAccepted()) { - touchMouseId = p.id(); + if (me.isAccepted()) event->setAccepted(true); - } + else + touchMouseId = -1; } } if (touchMouseId != -1)