diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-06-18 10:49:11 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-06-18 10:49:11 (GMT) |
commit | 3b04dba36b31360d94583f382b9054bcdea0e2a7 (patch) | |
tree | f56d1329980987a21d0c457e21ebb99f820e3ef2 /src/gui/kernel/qwidget.cpp | |
parent | 9756f523fd1c31192a87c65449434280a59b49f7 (diff) | |
download | Qt-3b04dba36b31360d94583f382b9054bcdea0e2a7.zip Qt-3b04dba36b31360d94583f382b9054bcdea0e2a7.tar.gz Qt-3b04dba36b31360d94583f382b9054bcdea0e2a7.tar.bz2 |
Change behavior of how touch and mouse events work together
We now send both types of events, i.e. accepting TouchBegin doesn't block mouse events anymore. We
are also introducing the idea of a "primary" touch point, which is the one that the system is also
generating mouse events for.
This lets us reuse existing mouse event code while still being able to add multi-touch support.
Diffstat (limited to 'src/gui/kernel/qwidget.cpp')
-rw-r--r-- | src/gui/kernel/qwidget.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index f05672e..8dd32f5 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -7883,6 +7883,43 @@ bool QWidget::event(QEvent *event) case QEvent::Gesture: event->ignore(); break; + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + { + QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); + const QTouchEvent::TouchPoint &touchPoint = touchEvent->touchPoints().first(); + if (touchPoint.isPrimary()) + break; + + // fake a mouse event! + QEvent::Type eventType = QEvent::None; + switch (touchEvent->type()) { + case QEvent::TouchBegin: + eventType = QEvent::MouseButtonPress; + break; + case QEvent::TouchUpdate: + eventType = QEvent::MouseMove; + break; + case QEvent::TouchEnd: + eventType = QEvent::MouseButtonRelease; + break; + default: + Q_ASSERT(!true); + break; + } + if (eventType == QEvent::None) + break; + + QMouseEvent mouseEvent(eventType, + touchPoint.pos().toPoint(), + touchPoint.screenPos().toPoint(), + Qt::LeftButton, + Qt::LeftButton, + touchEvent->modifiers()); + (void) QApplication::sendEvent(this, &mouseEvent); + break; + } #ifndef QT_NO_PROPERTIES case QEvent::DynamicPropertyChange: { const QByteArray &propName = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName(); |