Avoid losing mouse events when the event loop gets spinned
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Thu, 19 Apr 2012 08:31:14 +0000 (11:31 +0300)
committerQt by Nokia <qt-info@nokia.com>
Fri, 20 Apr 2012 07:46:02 +0000 (09:46 +0200)
The touchMouseId value has to be updated to its potential new value
before delivering the events.

Change-Id: I47ac5b3aad63293e19985b7b242b56db258fe786
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/quick/items/qquickcanvas.cpp

index 9110233..f59a89a 100644 (file)
@@ -395,15 +395,19 @@ void QQuickCanvasPrivate::translateTouchToMouse(QTouchEvent *event)
             bool doubleClick = event->timestamp() - touchMousePressTimestamp
                             < static_cast<ulong>(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)