Add hint for touch -> mouse event synthesizing
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>
This commit is contained in:
parent
09dd19df5c
commit
6c1670d8c2
@ -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;
|
||||
|
@ -134,7 +134,8 @@ public:
|
||||
PasswordMaskDelay,
|
||||
FontSmoothingGamma,
|
||||
StartDragVelocity,
|
||||
UseRtlExtensions
|
||||
UseRtlExtensions,
|
||||
SynthesizeMouseFromTouchEvents
|
||||
};
|
||||
|
||||
virtual QVariant styleHint(StyleHint hint) const;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user