From 6c1670d8c273819435867c42725c0db0eee597dc Mon Sep 17 00:00:00 2001 From: Morten Johan Sorvig Date: Wed, 8 Aug 2012 11:44:39 +0200 Subject: [PATCH] Add hint for touch -> mouse event synthesizing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/gui/kernel/qplatformintegration.cpp | 2 ++ src/gui/kernel/qplatformintegration.h | 3 ++- .../platforms/cocoa/qcocoaintegration.mm | 3 +++ src/widgets/kernel/qapplication.cpp | 4 +++ .../kernel/qapplication/tst_qapplication.cpp | 27 ++++++++++--------- .../widgets/kernel/qwidget/tst_qwidget.cpp | 4 +++ 6 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp index b713b713ae..85933de8b2 100644 --- a/src/gui/kernel/qplatformintegration.cpp +++ b/src/gui/kernel/qplatformintegration.cpp @@ -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; diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h index 8ed48b268a..49dce3ea22 100644 --- a/src/gui/kernel/qplatformintegration.h +++ b/src/gui/kernel/qplatformintegration.h @@ -134,7 +134,8 @@ public: PasswordMaskDelay, FontSmoothingGamma, StartDragVelocity, - UseRtlExtensions + UseRtlExtensions, + SynthesizeMouseFromTouchEvents }; virtual QVariant styleHint(StyleHint hint) const; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 95155f3540..65ee03d53f 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -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); } diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 1fcd7b1fbc..d26804fddf 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -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 diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index fc91ba23b3..929b587dfb 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -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 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); } } diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 0c35107157..3b45acfa1a 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -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;