Add hint for touch -> mouse event synthesizing
authorMorten Johan Sorvig <morten.sorvig@nokia.com>
Wed, 8 Aug 2012 09:44:39 +0000 (11:44 +0200)
committerQt by Nokia <qt-info@nokia.com>
Wed, 22 Aug 2012 05:01:17 +0000 (07:01 +0200)
Commit 7808ec79 changes QApplication to synthesize
mouse events from (unhandled) touch events.

On Mac OS X this creates a conflict for two-finger
scroll swipes, which generates both touch events and
mouse wheel events: scrolling in QTextEdit will also
select the text.

Add a SynthesizeMouseFromTouchEvents platform style
hint that enables the event synthesising. Set to true
by default and false in Cocoa.

Change-Id: I1ffa5a141476aa38b81ce92a87eff676c7ec2276
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
src/gui/kernel/qplatformintegration.cpp
src/gui/kernel/qplatformintegration.h
src/plugins/platforms/cocoa/qcocoaintegration.mm
src/widgets/kernel/qapplication.cpp
tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp

index b713b71..85933de 100644 (file)
@@ -301,6 +301,8 @@ QVariant QPlatformIntegration::styleHint(StyleHint hint) const
         return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragVelocity);
     case UseRtlExtensions:
         return QVariant(false);
+    case SynthesizeMouseFromTouchEvents:
+        return true;
     }
 
     return 0;
index 8ed48b2..49dce3e 100644 (file)
@@ -134,7 +134,8 @@ public:
         PasswordMaskDelay,
         FontSmoothingGamma,
         StartDragVelocity,
-        UseRtlExtensions
+        UseRtlExtensions,
+        SynthesizeMouseFromTouchEvents
     };
 
     virtual QVariant styleHint(StyleHint hint) const;
index 95155f3..65ee03d 100644 (file)
@@ -313,6 +313,9 @@ QVariant QCocoaIntegration::styleHint(StyleHint hint) const
 {
     if (hint == QPlatformIntegration::FontSmoothingGamma)
         return 2.0;
+    if (hint == QPlatformIntegration::SynthesizeMouseFromTouchEvents)
+        return false;
+
     return QPlatformIntegration::styleHint(hint);
 }
 
index 1fcd7b1..d26804f 100644 (file)
@@ -4105,6 +4105,10 @@ bool QApplicationPrivate::translateTouchToMouse(QWidget *widget, QTouchEvent *ev
 {
     Q_Q(QApplication);
 
+    // Check if the platform wants synthesized mouse events.
+    if (!QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SynthesizeMouseFromTouchEvents).toBool())
+        return false;
+
     Q_FOREACH (const QTouchEvent::TouchPoint &p, event->touchPoints()) {
         const QEvent::Type eventType = (p.state() & Qt::TouchPointPressed) ? QEvent::MouseButtonPress
                                      : (p.state() & Qt::TouchPointReleased) ? QEvent::MouseButtonRelease
index fc91ba2..929b587 100644 (file)
@@ -1926,6 +1926,9 @@ void tst_QApplication::touchEventPropagation()
     int argc = 1;
     QApplication app(argc, &argv0, QApplication::GuiServer);
 
+    const bool mouseEventSynthesizing = QGuiApplicationPrivate::platformIntegration()
+        ->styleHint(QPlatformIntegration::SynthesizeMouseFromTouchEvents).toBool();
+
     QList<QTouchEvent::TouchPoint> pressedTouchPoints;
     QTouchEvent::TouchPoint press(0);
     press.setState(Qt::TouchPointPressed);
@@ -1963,7 +1966,7 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(!window.seenTouchEvent);
-        QVERIFY(window.seenMouseEvent); // Since QApplication transforms ignored touch events in mouse events
+        QCOMPARE(window.seenMouseEvent, mouseEventSynthesizing); // QApplication may transform ignored touch events in mouse events
 
         window.reset();
         window.setAttribute(Qt::WA_AcceptTouchEvents);
@@ -1977,7 +1980,7 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(window.seenTouchEvent);
-        QVERIFY(window.seenMouseEvent);
+        QCOMPARE(window.seenMouseEvent, mouseEventSynthesizing);
 
         window.reset();
         window.acceptTouchEvent = true;
@@ -2015,9 +2018,9 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(!widget.seenTouchEvent);
-        QVERIFY(widget.seenMouseEvent);
+        QCOMPARE(widget.seenMouseEvent, mouseEventSynthesizing);
         QVERIFY(!window.seenTouchEvent);
-        QVERIFY(window.seenMouseEvent);
+        QCOMPARE(window.seenMouseEvent, mouseEventSynthesizing);
 
         window.reset();
         widget.reset();
@@ -2032,9 +2035,9 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(widget.seenTouchEvent);
-        QVERIFY(widget.seenMouseEvent);
+        QCOMPARE(widget.seenMouseEvent, mouseEventSynthesizing);
         QVERIFY(!window.seenTouchEvent);
-        QVERIFY(window.seenMouseEvent);
+        QCOMPARE(window.seenMouseEvent, mouseEventSynthesizing);
 
         window.reset();
         widget.reset();
@@ -2049,7 +2052,7 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(widget.seenTouchEvent);
-        QVERIFY(widget.seenMouseEvent);
+        QCOMPARE(widget.seenMouseEvent, mouseEventSynthesizing);
         QVERIFY(!window.seenTouchEvent);
         QVERIFY(!window.seenMouseEvent);
 
@@ -2084,9 +2087,9 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(!widget.seenTouchEvent);
-        QVERIFY(widget.seenMouseEvent);
+        QCOMPARE(widget.seenMouseEvent, mouseEventSynthesizing);
         QVERIFY(window.seenTouchEvent);
-        QVERIFY(window.seenMouseEvent);
+        QCOMPARE(window.seenMouseEvent, mouseEventSynthesizing);
 
         window.reset();
         widget.reset();
@@ -2101,7 +2104,7 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(!widget.seenTouchEvent);
-        QVERIFY(widget.seenMouseEvent);
+        QCOMPARE(widget.seenMouseEvent, mouseEventSynthesizing);
         QVERIFY(window.seenTouchEvent);
         QVERIFY(!window.seenMouseEvent);
 
@@ -2119,8 +2122,8 @@ void tst_QApplication::touchEventPropagation()
                                                  touchPointList(releasedTouchPoints));
         QCoreApplication::processEvents();
         QVERIFY(!widget.seenTouchEvent);
-        QVERIFY(widget.seenMouseEvent);
-        QVERIFY(!window.seenTouchEvent);
+        QCOMPARE(widget.seenMouseEvent, mouseEventSynthesizing);
+        QCOMPARE(!window.seenTouchEvent, mouseEventSynthesizing);
         QVERIFY(!window.seenMouseEvent);
     }
 }
index 0c35107..3b45acf 100644 (file)
@@ -9409,6 +9409,10 @@ public:
 
 void tst_QWidget::touchEventSynthesizedMouseEvent()
 {
+    // Pass if the platform does not want mouse event synhesizing
+    if (!QGuiApplicationPrivate::platformIntegration()->styleHint(QPlatformIntegration::SynthesizeMouseFromTouchEvents).toBool())
+        return;
+
     {
         // Simple case, we ignore the touch events, we get mouse events instead
         QTouchDevice *device = new QTouchDevice;