diff options
-rw-r--r-- | src/gui/kernel/qapplication_lite.cpp | 31 | ||||
-rw-r--r-- | src/gui/kernel/qapplication_p.h | 1 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface.cpp | 9 | ||||
-rw-r--r-- | src/gui/kernel/qwindowsysteminterface.h | 23 |
4 files changed, 64 insertions, 0 deletions
diff --git a/src/gui/kernel/qapplication_lite.cpp b/src/gui/kernel/qapplication_lite.cpp index 5fc56a8..491dd02 100644 --- a/src/gui/kernel/qapplication_lite.cpp +++ b/src/gui/kernel/qapplication_lite.cpp @@ -102,6 +102,11 @@ void QApplicationPrivate::processUserEvent(QWindowSystemInterface::UserEvent *e) case QEvent::KeyRelease: QApplicationPrivate::processKeyEvent(static_cast<QWindowSystemInterface::KeyEvent *>(e)); break; + case QEvent::TouchBegin: + case QEvent::TouchUpdate: + case QEvent::TouchEnd: + QApplicationPrivate::processTouchEvent(static_cast<QWindowSystemInterface::TouchEvent *>(e)); + break; default: qWarning() << "Unknown user input event type:" << e->type; break; @@ -797,4 +802,30 @@ void QApplicationPrivate::processCloseEvent(QWidget *tlw) tlw->d_func()->close_helper(QWidgetPrivate::CloseWithSpontaneousEvent); } +void QApplicationPrivate::processTouchEvent(QWindowSystemInterface::TouchEvent *e) +{ + QList<QTouchEvent::TouchPoint> touchPoints; + Qt::TouchPointStates states; + + int primaryPoint = -1; + foreach(struct QWindowSystemInterface::TouchPoint point, e->points) { + QTouchEvent::TouchPoint p; + p.setId(point.id); + p.setPressure(point.pressure); + states |= point.state; + if (point.isPrimary) { + point.state |= Qt::TouchPointPrimary; + primaryPoint = point.id; + } + p.setState(point.state); + p.setRect(point.area); + p.setScreenPos(point.area.center()); + p.setNormalizedPos(point.normalPosition); + + touchPoints.append(p); + } + + translateRawTouchEvent(e->widget.data(), e->devType, touchPoints); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 7ad8ca5..f06826d 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -489,6 +489,7 @@ public: static void processMouseEvent(QWindowSystemInterface::MouseEvent *e); static void processKeyEvent(QWindowSystemInterface::KeyEvent *e); static void processWheelEvent(QWindowSystemInterface::WheelEvent *e); + static void processTouchEvent(QWindowSystemInterface::TouchEvent *e); static void processCloseEvent(QWidget *tlw); static void processGeometryChange(QWidget *tlw, const QRect &newRect); diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 22b45ac..102d1a3 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -133,4 +133,13 @@ void QWindowSystemInterfacePrivate::queueUserEvent(QWindowSystemInterface::UserE if (dispatcher) dispatcher->wakeUp(); } + +void QWindowSystemInterface::handleTouchEvent(QWidget *tlw, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, QList<struct TouchPoint> points) +{ + if (!points.size()) // Touch events must have at least one point + return; + TouchEvent *e = new TouchEvent(tlw, timestamp, type, devType, points); + QWindowSystemInterfacePrivate::queueUserEvent(e); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h index e0c46d1..ca73305 100644 --- a/src/gui/kernel/qwindowsysteminterface.h +++ b/src/gui/kernel/qwindowsysteminterface.h @@ -75,6 +75,21 @@ public: static void handleWheelEvent(QWidget *w, ulong timestamp, const QPoint & local, const QPoint & global, int d, Qt::Orientation o); + struct TouchPoint { + int id; // for application use + bool isPrimary; // for application use + QPointF normalPosition; // touch device coordinates, (0 to 1, 0 to 1) + QRectF area; // the touched area, centered at position in screen coordinates + qreal pressure; // 0 to 1 + Qt::TouchPointStates state; //Qt::TouchPoint{Pressed|Moved|Stationary|Released} + }; + + static void handleTouchEvent(QWidget *w, QEvent::Type type, QTouchEvent::DeviceType devType, QList<struct TouchPoint> points) { + handleTouchEvent(w, eventTime.elapsed(), type, devType, points); + } + + static void handleTouchEvent(QWidget *w, ulong timestamp, QEvent::Type type, QTouchEvent::DeviceType devType, QList<struct TouchPoint> points); + // delivered directly by the plugin via spontaneous events static void handleGeometryChange(QWidget *w, const QRect &newRect); static void handleCloseEvent(QWidget *w); @@ -121,6 +136,14 @@ public: Qt::KeyboardModifiers modifiers; }; + class TouchEvent : public UserEvent { + public: + TouchEvent(QWidget *w, ulong time, QEvent::Type t, QTouchEvent::DeviceType d, QList<struct TouchPoint> p) + :UserEvent(w, time, t) { devType = d; points = p; } + QTouchEvent::DeviceType devType; + QList<struct TouchPoint> points; + }; + private: static QTime eventTime; |