From 4e400369c08db251cd489fec1229398c224d02b4 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 27 Mar 2020 16:06:11 +0000 Subject: Refactor pointer event hierarchy Some goals that have hopefully been achieved are: - make QPointerEvent and QEventPoint resemble their Qt Quick counterparts to such an extent that we can remove those wrappers and go back to delivering the original events in Qt Quick - make QEventPoint much smaller than QTouchEvent::TouchPoint, with no pimpl - remove most public setters - reduce the usage of complex constructors that take many arguments - don't repeat ourselves: move accessors and storage upwards rather than having redundant ones in subclasses - standardize the set of accessors in QPointerEvent - maintain source compatibility as much as possible: do not require modifying event-handling code in any QWidget subclass To avoid public setters we now introduce a few QMutable* subclasses. This is a bit like the Builder pattern except that it doesn't involve constructing a separate disposable object: the main event type can be cast to the mutable type at any time to enable modifications, iff the code is linked with gui-private. Therefore event classes can have less-"complete" constructors, because internal Qt code can use setters the same way it could use the ones in QTouchEvent before; and the event classes don't need many friends. Even some read-accessors can be kept private unless we are sure we want to expose them. Task-number: QTBUG-46266 Fixes: QTBUG-72173 Change-Id: I740e4e40165b7bc41223d38b200bbc2b403e07b6 Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/android/androidjniinput.cpp | 12 ++++++------ src/plugins/platforms/cocoa/qmultitouch_mac.mm | 16 ++++++++-------- src/plugins/platforms/cocoa/qmultitouch_mac_p.h | 2 +- src/plugins/platforms/ios/quiview.mm | 12 ++++++------ src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp | 12 ++++++------ src/plugins/platforms/wasm/qwasmeventtranslator.cpp | 12 ++++++------ src/plugins/platforms/windows/qwindowsmousehandler.cpp | 12 ++++++------ src/plugins/platforms/windows/qwindowspointerhandler.cpp | 10 +++++----- src/plugins/platforms/xcb/qxcbconnection_xi2.cpp | 16 ++++++++-------- 9 files changed, 52 insertions(+), 52 deletions(-) (limited to 'src/plugins/platforms') diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index 9906bdffd3..98f56808b7 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -228,19 +228,19 @@ namespace QtAndroidInput static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint id, jint action, jboolean /*primary*/, jint x, jint y, jfloat major, jfloat minor, jfloat rotation, jfloat pressure) { - Qt::TouchPointState state = Qt::TouchPointStationary; + QEventPoint::State state = QEventPoint::State::Stationary; switch (action) { case 0: - state = Qt::TouchPointPressed; + state = QEventPoint::State::Pressed; break; case 1: - state = Qt::TouchPointMoved; + state = QEventPoint::State::Updated; break; case 2: - state = Qt::TouchPointStationary; + state = QEventPoint::State::Stationary; break; case 3: - state = Qt::TouchPointReleased; + state = QEventPoint::State::Released; break; } @@ -258,7 +258,7 @@ namespace QtAndroidInput double(major * 2)); m_touchPoints.push_back(touchPoint); - if (state == Qt::TouchPointPressed) { + if (state == QEventPoint::State::Pressed) { QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext(); if (inputContext && qGuiApp) QMetaObject::invokeMethod(inputContext, "touchDown", Q_ARG(int, x), Q_ARG(int, y)); diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm index 7bbbb486e5..28d641b598 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm +++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm @@ -112,22 +112,22 @@ QCocoaTouch *QCocoaTouch::findQCocoaTouch(NSTouch *nstouch) return nullptr; } -Qt::TouchPointState QCocoaTouch::toTouchPointState(NSTouchPhase nsState) +QEventPoint::State QCocoaTouch::toTouchPointState(NSTouchPhase nsState) { - Qt::TouchPointState qtState = Qt::TouchPointReleased; + QEventPoint::State qtState = QEventPoint::State::Released; switch (nsState) { case NSTouchPhaseBegan: - qtState = Qt::TouchPointPressed; + qtState = QEventPoint::State::Pressed; break; case NSTouchPhaseMoved: - qtState = Qt::TouchPointMoved; + qtState = QEventPoint::State::Updated; break; case NSTouchPhaseStationary: - qtState = Qt::TouchPointStationary; + qtState = QEventPoint::State::Stationary; break; case NSTouchPhaseEnded: case NSTouchPhaseCancelled: - qtState = Qt::TouchPointReleased; + qtState = QEventPoint::State::Released; break; default: break; @@ -191,7 +191,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) const auto currentTouchesSnapshot = _currentTouches; for (QCocoaTouch *qcocoaTouch : currentTouchesSnapshot) { if (!_updateInternalStateOnly) { - qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased; + qcocoaTouch->_touchPoint.state = QEventPoint::State::Released; touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint); } delete qcocoaTouch; @@ -207,7 +207,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) if (_updateInternalStateOnly && !wasUpdateInternalStateOnly && !_currentTouches.isEmpty()) { QCocoaTouch *qcocoaTouch = _currentTouches.cbegin().value(); - qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased; + qcocoaTouch->_touchPoint.state = QEventPoint::State::Released; touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint); // Since this last touch also will end up being the first // touch (if the user adds a second finger without lifting diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h index 875a7d365e..ff4479fa4c 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac_p.h +++ b/src/plugins/platforms/cocoa/qmultitouch_mac_p.h @@ -88,7 +88,7 @@ class QCocoaTouch void updateTouchData(NSTouch *nstouch, NSTouchPhase phase); static QCocoaTouch *findQCocoaTouch(NSTouch *nstouch); - static Qt::TouchPointState toTouchPointState(NSTouchPhase nsState); + static QEventPoint::State toTouchPointState(NSTouchPhase nsState); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index d1a0cbf858..f5dd20bace 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -367,7 +367,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") return [super pointInside:point withEvent:event]; } -- (void)handleTouches:(NSSet *)touches withEvent:(UIEvent *)event withState:(Qt::TouchPointState)state withTimestamp:(ulong)timeStamp +- (void)handleTouches:(NSSet *)touches withEvent:(UIEvent *)event withState:(QEventPoint::State)state withTimestamp:(ulong)timeStamp { QIOSIntegration *iosIntegration = QIOSIntegration::instance(); bool supportsPressure = QIOSIntegration::instance()->touchDevice()->capabilities() & QPointingDevice::Capability::Pressure; @@ -417,7 +417,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") } } if (!uiTouch) { - touchPoint.state = Qt::TouchPointStationary; + touchPoint.state = QEventPoint::State::Stationary; } else { touchPoint.state = state; @@ -444,7 +444,7 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") } else { // We don't claim that our touch device supports QPointingDevice::Capability::Pressure, // but fill in a meaningful value in case clients use it anyway. - touchPoint.pressure = (state == Qt::TouchPointReleased) ? 0.0 : 1.0; + touchPoint.pressure = (state == QEventPoint::State::Released) ? 0.0 : 1.0; } } } @@ -499,17 +499,17 @@ Q_LOGGING_CATEGORY(lcQpaTablet, "qt.qpa.input.tablet") topLevel->requestActivateWindow(); } - [self handleTouches:touches withEvent:event withState:Qt::TouchPointPressed withTimestamp:ulong(event.timestamp * 1000)]; + [self handleTouches:touches withEvent:event withState:QEventPoint::State::Pressed withTimestamp:ulong(event.timestamp * 1000)]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { - [self handleTouches:touches withEvent:event withState:Qt::TouchPointMoved withTimestamp:ulong(event.timestamp * 1000)]; + [self handleTouches:touches withEvent:event withState:QEventPoint::State::Updated withTimestamp:ulong(event.timestamp * 1000)]; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { - [self handleTouches:touches withEvent:event withState:Qt::TouchPointReleased withTimestamp:ulong(event.timestamp * 1000)]; + [self handleTouches:touches withEvent:event withState:QEventPoint::State::Released withTimestamp:ulong(event.timestamp * 1000)]; // Remove ended touch points from the active set: #ifndef Q_OS_TVOS diff --git a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp index 40033d05c9..5653c9ee57 100644 --- a/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp +++ b/src/plugins/platforms/qnx/qqnxscreeneventhandler.cpp @@ -160,7 +160,7 @@ QQnxScreenEventHandler::QQnxScreenEventHandler(QQnxIntegration *integration) m_touchPoints[i].pressure = 1.0; // nothing touching - m_touchPoints[i].state = Qt::TouchPointReleased; + m_touchPoints[i].state = QEventPoint::State::Released; } } @@ -544,15 +544,15 @@ void QQnxScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType) QEvent::Type type = QEvent::None; switch (qnxType) { case SCREEN_EVENT_MTOUCH_TOUCH: - m_touchPoints[touchId].state = Qt::TouchPointPressed; + m_touchPoints[touchId].state = QEventPoint::State::Pressed; type = QEvent::TouchBegin; break; case SCREEN_EVENT_MTOUCH_MOVE: - m_touchPoints[touchId].state = Qt::TouchPointMoved; + m_touchPoints[touchId].state = QEventPoint::State::Updated; type = QEvent::TouchUpdate; break; case SCREEN_EVENT_MTOUCH_RELEASE: - m_touchPoints[touchId].state = Qt::TouchPointReleased; + m_touchPoints[touchId].state = QEventPoint::State::Released; type = QEvent::TouchEnd; break; } @@ -563,9 +563,9 @@ void QQnxScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType) if (i == touchId) { // current touch point is always active pointList.append(m_touchPoints[i]); - } else if (m_touchPoints[i].state != Qt::TouchPointReleased) { + } else if (m_touchPoints[i].state != QEventPoint::State::Released) { // finger is down but did not move - m_touchPoints[i].state = Qt::TouchPointStationary; + m_touchPoints[i].state = QEventPoint::State::Stationary; pointList.append(m_touchPoints[i]); } } diff --git a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp index 41e4b557c0..2387f3cdea 100644 --- a/src/plugins/platforms/wasm/qwasmeventtranslator.cpp +++ b/src/plugins/platforms/wasm/qwasmeventtranslator.cpp @@ -738,22 +738,22 @@ int QWasmEventTranslator::handleTouch(int eventType, const EmscriptenTouchEvent case EMSCRIPTEN_EVENT_TOUCHSTART: if (tp != pressedTouchIds.constEnd()) { touchPoint.state = (stationaryTouchPoint - ? Qt::TouchPointStationary - : Qt::TouchPointMoved); + ? QEventPoint::State::Stationary + : QEventPoint::State::Updated); } else { - touchPoint.state = Qt::TouchPointPressed; + touchPoint.state = QEventPoint::State::Pressed; } pressedTouchIds.insert(touchPoint.id, touchPoint.normalPosition); break; case EMSCRIPTEN_EVENT_TOUCHEND: - touchPoint.state = Qt::TouchPointReleased; + touchPoint.state = QEventPoint::State::Released; pressedTouchIds.remove(touchPoint.id); break; case EMSCRIPTEN_EVENT_TOUCHMOVE: touchPoint.state = (stationaryTouchPoint - ? Qt::TouchPointStationary - : Qt::TouchPointMoved); + ? QEventPoint::State::Stationary + : QEventPoint::State::Updated); pressedTouchIds.insert(touchPoint.id, touchPoint.normalPosition); break; diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 13dd324a09..5e2710bc28 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -601,7 +601,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, QTouchPointList touchPoints; touchPoints.reserve(winTouchPointCount); - Qt::TouchPointStates allStates; + QEventPoint::States allStates; GetTouchInputInfo(reinterpret_cast(msg.lParam), UINT(msg.wParam), winTouchInputs.data(), sizeof(TOUCHINPUT)); @@ -628,15 +628,15 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, touchPoint.normalPosition = normalPosition; if (winTouchInput.dwFlags & TOUCHEVENTF_DOWN) { - touchPoint.state = Qt::TouchPointPressed; + touchPoint.state = QEventPoint::State::Pressed; m_lastTouchPositions.insert(id, touchPoint.normalPosition); } else if (winTouchInput.dwFlags & TOUCHEVENTF_UP) { - touchPoint.state = Qt::TouchPointReleased; + touchPoint.state = QEventPoint::State::Released; m_lastTouchPositions.remove(id); } else { touchPoint.state = (stationaryTouchPoint - ? Qt::TouchPointStationary - : Qt::TouchPointMoved); + ? QEventPoint::State::Stationary + : QEventPoint::State::Updated); m_lastTouchPositions.insert(id, touchPoint.normalPosition); } @@ -648,7 +648,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, CloseTouchInputHandle(reinterpret_cast(msg.lParam)); // all touch points released, forget the ids we've seen, they may not be reused - if (allStates == Qt::TouchPointReleased) + if (allStates == QEventPoint::State::Released) m_touchInputIDToTouchPointID.clear(); QWindowSystemInterface::handleTouchEvent(window, diff --git a/src/plugins/platforms/windows/qwindowspointerhandler.cpp b/src/plugins/platforms/windows/qwindowspointerhandler.cpp index 7dc2bd729a..d5c3aeacff 100644 --- a/src/plugins/platforms/windows/qwindowspointerhandler.cpp +++ b/src/plugins/platforms/windows/qwindowspointerhandler.cpp @@ -491,7 +491,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd, << " message=" << Qt::hex << msg.message << " count=" << Qt::dec << count; - Qt::TouchPointStates allStates; + QEventPoint::States allStates; for (quint32 i = 0; i < count; ++i) { if (QWindowsContext::verbose > 1) @@ -526,13 +526,13 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd, touchPoint.normalPosition = normalPosition; if (touchInfo[i].pointerInfo.pointerFlags & POINTER_FLAG_DOWN) { - touchPoint.state = Qt::TouchPointPressed; + touchPoint.state = QEventPoint::State::Pressed; m_lastTouchPositions.insert(touchPoint.id, touchPoint.normalPosition); } else if (touchInfo[i].pointerInfo.pointerFlags & POINTER_FLAG_UP) { - touchPoint.state = Qt::TouchPointReleased; + touchPoint.state = QEventPoint::State::Released; m_lastTouchPositions.remove(touchPoint.id); } else { - touchPoint.state = stationaryTouchPoint ? Qt::TouchPointStationary : Qt::TouchPointMoved; + touchPoint.state = stationaryTouchPoint ? QEventPoint::State::Stationary : QEventPoint::State::Updated; m_lastTouchPositions.insert(touchPoint.id, touchPoint.normalPosition); } allStates |= touchPoint.state; @@ -544,7 +544,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd, } // all touch points released, forget the ids we've seen. - if (allStates == Qt::TouchPointReleased) + if (allStates == QEventPoint::State::Released) m_touchInputIDToTouchPointID.clear(); QWindowSystemInterface::handleTouchEvent(window, m_touchDevice, touchPoints, diff --git a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp index 74044db0de..dc8a533388 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_xi2.cpp @@ -819,7 +819,7 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo if (xiDeviceEvent->event_type == XCB_INPUT_TOUCH_BEGIN) { QWindowSystemInterface::TouchPoint tp; tp.id = xiDeviceEvent->detail % INT_MAX; - tp.state = Qt::TouchPointPressed; + tp.state = QEventPoint::State::Pressed; tp.pressure = -1.0; dev->touchPoints[tp.id] = tp; } @@ -926,9 +926,9 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo dev->size.height() * screen->geometry().height() / screen->physicalSize().height(); x = dev->firstPressedPosition.x() + dx; y = dev->firstPressedPosition.y() + dy; - touchPoint.state = Qt::TouchPointMoved; + touchPoint.state = QEventPoint::State::Updated; } else if (touchPoint.area.center() != QPoint(x, y)) { - touchPoint.state = Qt::TouchPointMoved; + touchPoint.state = QEventPoint::State::Updated; if (dev->qtTouchDevice->type() == QInputDevice::DeviceType::TouchPad) dev->pointPressedPosition[touchPoint.id] = QPointF(x, y); } @@ -948,7 +948,7 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo } break; case XCB_INPUT_TOUCH_END: - touchPoint.state = Qt::TouchPointReleased; + touchPoint.state = QEventPoint::State::Released; if (dev->qtTouchDevice->type() == QInputDevice::DeviceType::TouchPad && dev->pointPressedPosition.value(touchPoint.id) == QPointF(x, y)) { qreal dx = (nx - dev->firstPressedNormalPosition.x()) * dev->size.width() * screen->geometry().width() / screen->physicalSize().width(); @@ -967,13 +967,13 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo " area " << touchPoint.area << " pressure " << touchPoint.pressure; Qt::KeyboardModifiers modifiers = keyboard()->translateModifiers(xiDeviceEvent->mods.effective); QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xiDeviceEvent->time, dev->qtTouchDevice, dev->touchPoints.values(), modifiers); - if (touchPoint.state == Qt::TouchPointReleased) + if (touchPoint.state == QEventPoint::State::Released) // If a touchpoint was released, we can forget it, because the ID won't be reused. dev->touchPoints.remove(touchPoint.id); else // Make sure that we don't send TouchPointPressed/Moved in more than one QTouchEvent // with this touch point if the next XI2 event is about a different touch point. - touchPoint.state = Qt::TouchPointStationary; + touchPoint.state = QEventPoint::State::Stationary; } bool QXcbConnection::startSystemMoveResizeForTouch(xcb_window_t window, int edges) @@ -984,8 +984,8 @@ bool QXcbConnection::startSystemMoveResizeForTouch(xcb_window_t window, int edge if (deviceData.qtTouchDevice->type() == QInputDevice::DeviceType::TouchScreen) { auto pointIt = deviceData.touchPoints.constBegin(); for (; pointIt != deviceData.touchPoints.constEnd(); ++pointIt) { - Qt::TouchPointState state = pointIt.value().state; - if (state == Qt::TouchPointMoved || state == Qt::TouchPointPressed || state == Qt::TouchPointStationary) { + QEventPoint::State state = pointIt.value().state; + if (state == QEventPoint::State::Updated || state == QEventPoint::State::Pressed || state == QEventPoint::State::Stationary) { m_startSystemMoveResizeInfo.window = window; m_startSystemMoveResizeInfo.deviceid = devIt.key(); m_startSystemMoveResizeInfo.pointid = pointIt.key(); -- cgit v1.2.3