Fix position of mouse events generated from touch events.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Thu, 26 Jul 2012 04:25:30 +0000 (14:25 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 26 Jul 2012 13:13:24 +0000 (15:13 +0200)
In touch event terminology the global position is the screenPos,
scenePos is the windowPos.

Fixes a tst_qdeclarativepincharea test failure in qtquick1.

Change-Id: Ie98fe12be8cbedc9b019913b066e7c4bce75278d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com>
src/widgets/kernel/qapplication.cpp
tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp

index 3fdc3e4..dc09155 100644 (file)
@@ -4424,7 +4424,7 @@ bool QApplicationPrivate::translateTouchToMouse(QWidget *widget, QTouchEvent *ev
         if (eventType == QEvent::None)
             continue;
 
-        const QPoint pos = widget->mapFromGlobal(p.scenePos().toPoint());
+        const QPoint pos = widget->mapFromGlobal(p.screenPos().toPoint());
 
         QMouseEvent mouseEvent(eventType, pos,
                                Qt::LeftButton, Qt::LeftButton,
index 1b4cacf..708e8c1 100644 (file)
@@ -9326,6 +9326,7 @@ protected:
         case QEvent::MouseMove:
         case QEvent::MouseButtonRelease:
             ++m_mouseEventCount;
+            m_lastMouseEventPos = static_cast<QMouseEvent *>(e)->localPos();
             if (m_acceptMouse)
                 e->accept();
             else
@@ -9342,6 +9343,7 @@ public:
     bool m_acceptTouch;
     int m_mouseEventCount;
     bool m_acceptMouse;
+    QPointF m_lastMouseEventPos;
 };
 
 void tst_QWidget::touchEventSynthesizedMouseEvent()
@@ -9361,12 +9363,15 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
         QTest::touchEvent(&widget, device).press(0, QPoint(10, 10), &widget);
         QCOMPARE(widget.m_touchEventCount, 0);
         QCOMPARE(widget.m_mouseEventCount, 1);
+        QCOMPARE(widget.m_lastMouseEventPos, QPointF(10, 10));
         QTest::touchEvent(&widget, device).move(0, QPoint(15, 15), &widget);
         QCOMPARE(widget.m_touchEventCount, 0);
         QCOMPARE(widget.m_mouseEventCount, 2);
+        QCOMPARE(widget.m_lastMouseEventPos, QPointF(15, 15));
         QTest::touchEvent(&widget, device).release(0, QPoint(20, 20), &widget);
         QCOMPARE(widget.m_touchEventCount, 0);
         QCOMPARE(widget.m_mouseEventCount, 3);
+        QCOMPARE(widget.m_lastMouseEventPos, QPointF(20, 20));
     }
 
     {
@@ -9403,6 +9408,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
         TouchMouseWidget parent;
         parent.setAcceptTouch(true);
         TouchMouseWidget child(&parent);
+        child.move(5, 5);
         child.setAcceptMouse(false);
         parent.show();
         QVERIFY(QTest::qWaitForWindowExposed(parent.windowHandle()));
@@ -9416,6 +9422,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
         QCOMPARE(parent.m_mouseEventCount, 0);
         QCOMPARE(child.m_touchEventCount, 0);
         QCOMPARE(child.m_mouseEventCount, 1); // Attempt at mouse event before propagation
+        QCOMPARE(child.m_lastMouseEventPos, QPointF(10, 10));
     }
 
     {
@@ -9427,6 +9434,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
 
         TouchMouseWidget parent;
         TouchMouseWidget child(&parent);
+        child.move(5, 5);
         child.setAcceptMouse(false);
         parent.show();
         QVERIFY(QTest::qWaitForWindowExposed(parent.windowHandle()));
@@ -9438,8 +9446,10 @@ void tst_QWidget::touchEventSynthesizedMouseEvent()
         QTest::touchEvent(parent.window(), device).press(0, QPoint(10, 10), &child);
         QCOMPARE(parent.m_touchEventCount, 0);
         QCOMPARE(parent.m_mouseEventCount, 1);
+        QCOMPARE(parent.m_lastMouseEventPos, QPointF(15, 15));
         QCOMPARE(child.m_touchEventCount, 0);
         QCOMPARE(child.m_mouseEventCount, 1); // Attempt at mouse event before propagation
+        QCOMPARE(child.m_lastMouseEventPos, QPointF(10, 10));
     }
 }