From 5da5230ab29743b63bf238a379891c98ac9d5038 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 30 Nov 2011 15:48:54 +0200 Subject: Remove event type parameter from handleTouchEvent. Requiring platform and generic plug-ins to pass TouchBegin, TouchUpdate, or TouchEnd is unnecessary. The type can be easily deduced from the touch point states. In fact handleTouchEvent already collected the combined point states, it was just not utilized until now. Change-Id: Icf3c787fefdebc51609a763bc4286c18a0b6aac2 Reviewed-by: Lars Knoll --- src/gui/kernel/qwindowsysteminterface_qpa.cpp | 18 ++++++++++++------ src/gui/kernel/qwindowsysteminterface_qpa.h | 4 ++-- .../generic/touchscreen/qtoucheventsenderqpa.cpp | 5 ++--- src/plugins/generic/touchscreen/qtoucheventsenderqpa.h | 2 +- src/plugins/generic/touchscreen/qtouchscreen.cpp | 2 +- src/plugins/generic/touchscreen/qtouchscreen.h | 2 +- src/plugins/platforms/cocoa/qnsview.mm | 8 ++++---- src/plugins/platforms/windows/qwindowsmousehandler.cpp | 5 ++--- src/plugins/platforms/xcb/qxcbconnection_maemo.cpp | 2 +- src/testlib/qtesttouch.h | 2 +- 10 files changed, 27 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index 016446780b..874ceb426a 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -219,16 +219,15 @@ void QWindowSystemInterface::registerTouchDevice(QTouchDevice *device) QTouchDevicePrivate::registerDevice(device); } -void QWindowSystemInterface::handleTouchEvent(QWindow *w, QEvent::Type type, QTouchDevice *device, - const QList &points, Qt::KeyboardModifiers mods) +void QWindowSystemInterface::handleTouchEvent(QWindow *w, QTouchDevice *device, + const QList &points, Qt::KeyboardModifiers mods) { unsigned long time = QWindowSystemInterfacePrivate::eventTime.elapsed(); - handleTouchEvent(w, time, type, device, points, mods); + handleTouchEvent(w, time, device, points, mods); } -void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEvent::Type type, - QTouchDevice *device, - const QList &points, Qt::KeyboardModifiers mods) +void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QTouchDevice *device, + const QList &points, Qt::KeyboardModifiers mods) { if (!points.size()) // Touch events must have at least one point return; @@ -268,6 +267,13 @@ void QWindowSystemInterface::handleTouchEvent(QWindow *tlw, ulong timestamp, QEv ++point; } + // Determine the event type based on the combined point states. + QEvent::Type type = QEvent::TouchUpdate; + if (states == Qt::TouchPointPressed) + type = QEvent::TouchBegin; + else if (states == Qt::TouchPointReleased) + type = QEvent::TouchEnd; + QWindowSystemInterfacePrivate::TouchEvent *e = new QWindowSystemInterfacePrivate::TouchEvent(tlw, timestamp, type, device, touchPoints, mods); QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 423281955c..bcd4de944c 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -99,9 +99,9 @@ public: }; static void registerTouchDevice(QTouchDevice *device); - static void handleTouchEvent(QWindow *w, QEvent::Type type, QTouchDevice *device, + static void handleTouchEvent(QWindow *w, QTouchDevice *device, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); - static void handleTouchEvent(QWindow *w, ulong timestamp, QEvent::Type type, QTouchDevice *device, + static void handleTouchEvent(QWindow *w, ulong timestamp, QTouchDevice *device, const QList &points, Qt::KeyboardModifiers mods = Qt::NoModifier); static void handleGeometryChange(QWindow *w, const QRect &newRect); diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp index 08db058e10..f8dc84373d 100644 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp +++ b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp @@ -66,8 +66,7 @@ void QTouchEventSenderQPA::touch_configure(int x_min, int x_max, int y_min, int hw_range_y_max = y_max; } -void QTouchEventSenderQPA::touch_point(QEvent::Type state, - const QList &points) +void QTouchEventSenderQPA::touch_point(const QList &points) { QRect winRect; if (m_forceToActiveWindow) { @@ -107,7 +106,7 @@ void QTouchEventSenderQPA::touch_point(QEvent::Type state, #endif } - QWindowSystemInterface::handleTouchEvent(0, state, m_device, touchPoints); + QWindowSystemInterface::handleTouchEvent(0, m_device, touchPoints); } QT_END_NAMESPACE diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h index b6e1613b24..f0e923b3a0 100644 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h +++ b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h @@ -55,7 +55,7 @@ class QTouchEventSenderQPA : public QTouchScreenObserver public: QTouchEventSenderQPA(const QString &spec = QString()); void touch_configure(int x_min, int x_max, int y_min, int y_max); - void touch_point(QEvent::Type state, const QList &points); + void touch_point(const QList &points); private: bool m_forceToActiveWindow; diff --git a/src/plugins/generic/touchscreen/qtouchscreen.cpp b/src/plugins/generic/touchscreen/qtouchscreen.cpp index fd2de62d6b..fd73bffd4f 100644 --- a/src/plugins/generic/touchscreen/qtouchscreen.cpp +++ b/src/plugins/generic/touchscreen/qtouchscreen.cpp @@ -291,7 +291,7 @@ void QTouchScreenData::processInputEvent(input_event *data) if (!skip && !(m_state == m_prevState && m_state == QEvent::TouchEnd)) for (int i = 0; i < m_observers.count(); ++i) - m_observers.at(i)->touch_point(m_state, m_touchPoints); + m_observers.at(i)->touch_point(m_touchPoints); m_prevState = m_state; if (m_state == QEvent::TouchBegin) diff --git a/src/plugins/generic/touchscreen/qtouchscreen.h b/src/plugins/generic/touchscreen/qtouchscreen.h index 3c35b0012f..6127cdba32 100644 --- a/src/plugins/generic/touchscreen/qtouchscreen.h +++ b/src/plugins/generic/touchscreen/qtouchscreen.h @@ -59,7 +59,7 @@ class QTouchScreenObserver { public: virtual void touch_configure(int x_min, int x_max, int y_min, int y_max) = 0; - virtual void touch_point(QEvent::Type state, const QList &points) = 0; + virtual void touch_point(const QList &points) = 0; }; class QTouchScreenHandler : public QObject diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 4ae268dda5..a0a5a2e5cf 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -295,28 +295,28 @@ static QTouchDevice *touchDevice = 0; { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchBegin, touchDevice, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, touchDevice, points); } - (void)touchesMovedWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchUpdate, touchDevice, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, touchDevice, points); } - (void)touchesEndedWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, touchDevice, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, touchDevice, points); } - (void)touchesCancelledWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, touchDevice, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, touchDevice, points); } #ifndef QT_NO_WHEELEVENT diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index a2b6aa8d68..608230e6e0 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -280,14 +280,13 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, if (!m_touchDevice) { m_touchDevice = new QTouchDevice; + // TODO: Device used to be hardcoded to screen in previous code. m_touchDevice->setType(QTouchDevice::TouchScreen); m_touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::NormalizedPosition); QWindowSystemInterface::registerTouchDevice(m_touchDevice); } - // TODO: Device used to be hardcoded to screen in previous code. - // What is the correct event type? Which parts of translateRawTouchEvent() are required? - QWindowSystemInterface::handleTouchEvent(window, QEvent::TouchBegin, + QWindowSystemInterface::handleTouchEvent(window, m_touchDevice, touchPoints); return true; diff --git a/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp b/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp index 719fc85ae2..23421e59d2 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp @@ -288,7 +288,7 @@ void QXcbConnection::handleGenericEvent(xcb_ge_event_t *event) QWindowSystemInterface::registerTouchDevice(dev); m_xinputData->qtTouchDevice = dev; } - QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xideviceevent->time, (QEvent::Type)0 /*None*/, dev, touchPoints); + QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xideviceevent->time, dev, touchPoints); } if (xideviceevent->evtype == XI_ButtonRelease) { diff --git a/src/testlib/qtesttouch.h b/src/testlib/qtesttouch.h index 6a9909b617..4ebbd37c27 100644 --- a/src/testlib/qtesttouch.h +++ b/src/testlib/qtesttouch.h @@ -136,7 +136,7 @@ namespace QTest if (!points.isEmpty()) { if (targetWindow) { - QWindowSystemInterface::handleTouchEvent(targetWindow,QEvent::None, device, touchPointList(points.values())); + QWindowSystemInterface::handleTouchEvent(targetWindow, device, touchPointList(points.values())); QTest::qWait(10); } #ifdef QT_WIDGETS_LIB -- cgit v1.2.3