diff options
author | MohammadHossein Qanbari <mohammad.qanbari@qt.io> | 2024-03-04 18:24:32 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2024-03-18 08:59:21 -0700 |
commit | 25099f84c544748437c3954d279856bb8c866886 (patch) | |
tree | fc90d79ae8d686dbd72578850f0bd16b1eb857ee /src/quick | |
parent | 060caf44f8ca631020a5c1e42f34008f4099e9db (diff) |
Flickable: don't allow dragging with mouse buttons other than left
The SwipeView's page did not change to a new page when the user
right-clicked on text content inside the page. This occurred because
the mouse press event enabled the 'pressed' variable, indicating the
beginning of a drag. Since the text item did not accept the press event,
there was no need to handle the move and release events. Consequently,
the 'pressed' variable remained true.
If the 'pressed' variable is true, then the SwipeView's contentItem does
not update the highlight item. This implies that the highlight animators
will not start. Consequently, although the current index and item would
change, the content item view is not updated.
To fix this issue, the 'pressed' variable should not be true when the
press event is not accepted. When it's a mouse event, the value of the
'pressed' variable is set to true when the left button is pressed,
similar to the existing condition in the handleMoveEvent() method.
Since the bug originated in 'maybeBeginDrag()', the condition is added
to this method by passing the event's buttons.
The testcase creates a SwipeView component with two page items that
include a Label item. The test involves performing mouse and touch
events on the text content. Subsequently, when the current index is
changed, the testcase compares the content item to ensure it is
adjusted to its position to display the current item accordingly.
[ChangeLog][Quick][Flickable][Drag] Flickable is meant to be dragged
(flicked) by touch events; and as a matter of legacy support, for now
it can also be dragged by the left mouse button. Dragging with other
mouse buttons, such as the right and middle buttons, is not allowed.
Fixes: QTBUG-97252
Pick-to: 6.7
Change-Id: I6c4e7fb68302d9ab9b5cea67b20f66db57f5efa1
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/items/qquickflickable.cpp | 9 | ||||
-rw-r--r-- | src/quick/items/qquickflickable_p_p.h | 3 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/quick/items/qquickflickable.cpp b/src/quick/items/qquickflickable.cpp index f77ac092a0..7adc163d09 100644 --- a/src/quick/items/qquickflickable.cpp +++ b/src/quick/items/qquickflickable.cpp @@ -1101,14 +1101,17 @@ void QQuickFlickablePrivate::handlePressEvent(QPointerEvent *event) } q->setKeepMouseGrab(stealMouse); - maybeBeginDrag(computeCurrentTime(event), event->points().first().position()); + maybeBeginDrag(computeCurrentTime(event), event->points().first().position(), + event->isSinglePointEvent() ? static_cast<QSinglePointEvent *>(event)->buttons() + : Qt::NoButton); } -void QQuickFlickablePrivate::maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn) +void QQuickFlickablePrivate::maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn, Qt::MouseButtons buttons) { Q_Q(QQuickFlickable); clearDelayedPress(); - pressed = true; + // consider dragging only when event is left mouse button or touch event which has no button + pressed = buttons.testFlag(Qt::LeftButton) || (buttons == Qt::NoButton); if (hData.transitionToBounds) hData.transitionToBounds->stopTransition(); diff --git a/src/quick/items/qquickflickable_p_p.h b/src/quick/items/qquickflickable_p_p.h index 25d0f3d498..8d251ba9ff 100644 --- a/src/quick/items/qquickflickable_p_p.h +++ b/src/quick/items/qquickflickable_p_p.h @@ -234,7 +234,8 @@ public: void handleMoveEvent(QPointerEvent *); void handleReleaseEvent(QPointerEvent *); - void maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn); + void maybeBeginDrag(qint64 currentTimestamp, const QPointF &pressPosn, + Qt::MouseButtons buttons = Qt::NoButton); void drag(qint64 currentTimestamp, QEvent::Type eventType, const QPointF &localPos, const QVector2D &deltas, bool overThreshold, bool momentum, bool velocitySensitiveOverBounds, const QVector2D &velocity); |