diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-12-12 12:42:02 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-12-16 23:21:23 +0100 |
commit | 161bd514d0c42cbc1f4c1af0351dbd6d6a99a0c9 (patch) | |
tree | a19ff836e53289b948b6cb2d10b114c7b0c3c735 | |
parent | 09e7059e6d5a945b74a4aa60e4c2f470fb22be48 (diff) |
Implement touch event handling for SplitView
Amend 80166d58a18370bd5a2c6c61d2519011cfd65721, which broke touch event
handling in SplitView. Implement handling of TouchBegin/Update/End
events equivalently to the mouse event handling.
As a drive-by, rename the logging category from 'mouse' to 'pointer',
and refactor the if/else sequence to a switch statement, reducing
duplication of code that's common for all event types.
Remove expectFail from the test that now passes.
Fixes: QTBUG-105312
Change-Id: I156f55fa40b2afaaa115e59940d26187121fc16a
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit 6de2397da24e8068282c2d2bda5d1637ac033bc6)
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r-- | src/quicktemplates2/qquicksplitview.cpp | 77 | ||||
-rw-r--r-- | tests/auto/quickcontrols2/controls/data/tst_splitview.qml | 1 |
2 files changed, 50 insertions, 28 deletions
diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp index 01883b1fc1..c68b26c9a1 100644 --- a/src/quicktemplates2/qquicksplitview.cpp +++ b/src/quicktemplates2/qquicksplitview.cpp @@ -255,7 +255,7 @@ QT_BEGIN_NAMESPACE */ Q_LOGGING_CATEGORY(qlcQQuickSplitView, "qt.quick.controls.splitview") -Q_LOGGING_CATEGORY(qlcQQuickSplitViewMouse, "qt.quick.controls.splitview.mouse") +Q_LOGGING_CATEGORY(qlcQQuickSplitViewPointer, "qt.quick.controls.splitview.pointer") Q_LOGGING_CATEGORY(qlcQQuickSplitViewState, "qt.quick.controls.splitview.state") void QQuickSplitViewPrivate::updateFillIndex() @@ -930,7 +930,7 @@ void QQuickSplitViewPrivate::updateHandleVisibilities() void QQuickSplitViewPrivate::updateHoveredHandle(QQuickItem *hoveredItem) { - qCDebug(qlcQQuickSplitViewMouse) << "updating hovered handle after" << hoveredItem << "was hovered"; + qCDebug(qlcQQuickSplitViewPointer) << "updating hovered handle after" << hoveredItem << "was hovered"; const int oldHoveredHandleIndex = m_hoveredHandleIndex; m_hoveredHandleIndex = m_handleItems.indexOf(hoveredItem); @@ -943,16 +943,16 @@ void QQuickSplitViewPrivate::updateHoveredHandle(QQuickItem *hoveredItem) QQuickSplitHandleAttached *oldHoveredHandleAttached = qobject_cast<QQuickSplitHandleAttached*>( qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(oldHoveredHandle, true)); QQuickSplitHandleAttachedPrivate::get(oldHoveredHandleAttached)->setHovered(false); - qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << oldHoveredHandleIndex << "is no longer hovered"; + qCDebug(qlcQQuickSplitViewPointer) << "handle item at index" << oldHoveredHandleIndex << "is no longer hovered"; } if (m_hoveredHandleIndex != -1) { QQuickSplitHandleAttached *handleAttached = qobject_cast<QQuickSplitHandleAttached*>( qmlAttachedPropertiesObject<QQuickSplitHandleAttached>(hoveredItem, true)); QQuickSplitHandleAttachedPrivate::get(handleAttached)->setHovered(true); - qCDebug(qlcQQuickSplitViewMouse) << "handle item at index" << m_hoveredHandleIndex << "is now hovered"; + qCDebug(qlcQQuickSplitViewPointer) << "handle item at index" << m_hoveredHandleIndex << "is now hovered"; } else { - qCDebug(qlcQQuickSplitViewMouse) << "either there is no hovered item or" << hoveredItem << "is not a handle"; + qCDebug(qlcQQuickSplitViewPointer) << "either there is no hovered item or" << hoveredItem << "is not a handle"; } } @@ -1021,7 +1021,7 @@ void QQuickSplitViewPrivate::handlePress(const QPointF &point) setResizing(true); - qCDebug(qlcQQuickSplitViewMouse).nospace() << "handled press -" + qCDebug(qlcQQuickSplitViewPointer).nospace() << "handled press -" << " left/top index=" << m_pressedHandleIndex << "," << " size before press=" << m_leftOrTopItemSizeBeforePress << "," << " item=" << leftOrTopItem @@ -1411,27 +1411,50 @@ void QQuickSplitView::hoverLeaveEvent(QHoverEvent *event) bool QQuickSplitView::childMouseEventFilter(QQuickItem *item, QEvent *event) { Q_D(QQuickSplitView); - qCDebug(qlcQQuickSplitViewMouse) << "childMouseEventFilter called with" << item << event; - - if (event->type() == QEvent::MouseButtonPress) { - QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); - const QPointF point = mapFromItem(item, mouseEvent->position()); - d->handlePress(point); - - // Keep the mouse grab if this item belongs to the handle, - // otherwise this event can be stolen e.g. Flickable if we're inside it. - if (d->m_pressedHandleIndex != -1) - item->setKeepMouseGrab(true); - } - else if (event->type() == QEvent::MouseButtonRelease) { - QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); - const QPointF point = mapFromItem(item, mouseEvent->position()); - d->handleRelease(point); - } - else if (event->type() == QEvent::MouseMove) { - QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event); - const QPointF point = mapFromItem(item, mouseEvent->position()); - d->handleMove(point); + qCDebug(qlcQQuickSplitViewPointer) << "childMouseEventFilter called with" << item << event; + + if (Q_LIKELY(event->isPointerEvent())) { + auto *pointerEvent = static_cast<QPointerEvent *>(event); + const auto &eventPoint = pointerEvent->points().first(); + const QPointF point = mapFromItem(item, eventPoint.position()); + + switch (event->type()) { + case QEvent::MouseButtonPress: + d->handlePress(point); + // Keep the mouse grab if this item belongs to the handle, + // otherwise this event can be stolen e.g. Flickable if we're inside it. + if (d->m_pressedHandleIndex != -1) + item->setKeepMouseGrab(true); + break; + case QEvent::MouseButtonRelease: + d->handleRelease(point); + break; + case QEvent::MouseMove: + d->handleMove(point); + break; + case QEvent::TouchBegin: + if (pointerEvent->pointCount() == 1) { + d->handlePress(point); + // We filter the event on behalf of item, but we want the item + // to be the exclusive grabber so that we can continue to filter + // touch events for it. + if (d->m_pressedHandleIndex != -1) { + item->setKeepTouchGrab(true); + pointerEvent->setExclusiveGrabber(eventPoint, item); + } + } + break; + case QEvent::TouchEnd: + if (pointerEvent->pointCount() == 1) + d->handleRelease(point); + break; + case QEvent::TouchUpdate: + if (pointerEvent->pointCount() == 1) + d->handleMove(point); + break; + default: + break; + } } // If this event belongs to the handle, filter it. (d->m_pressedHandleIndex != -1) means that diff --git a/tests/auto/quickcontrols2/controls/data/tst_splitview.qml b/tests/auto/quickcontrols2/controls/data/tst_splitview.qml index ac4d6cddd7..76174a3c8e 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_splitview.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_splitview.qml @@ -2591,7 +2591,6 @@ TestCase { touch.move(0, control, handleCenter.x + 100, handleCenter.y).commit() verify(firstHandle.SplitHandle.pressed) let firstItem = control.itemAt(0) - expectFail("", "broken, QTBUG-105312") compare(firstItem.width, 125) touch.release(0, control, handleCenter.x + 100, handleCenter.y).commit() |