diff options
author | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-06-29 10:10:10 +0200 |
---|---|---|
committer | Mikolaj Boc <mikolaj.boc@qt.io> | 2023-07-05 16:45:41 +0200 |
commit | 844009f8e0c5d87fda378a6ead1331813a372496 (patch) | |
tree | 799a836f013e1ecf68d9e894fec310089ec184cf /src/widgets/itemviews/qabstractitemview.cpp | |
parent | 3f6041a24fe9b663e6a00481a30e84b2cd15763c (diff) |
Immediately drag when start distance is 0 in abstract item view
This change makes system drag become initiated right after dragging
is detected when drag start distance from
QApplication::startDragDistance is 0. Otherwise the starting distance
is ignored and the value of 1 is implicitly used.
The startDragDistance of 0 is needed on WASM, as the native
dragstart event arrives exactly after the first mousemove event.
With this change, it is possible to set up drag correctly prior to
the native dragstart event arriving.
Fixes: QTBUG-114947
Change-Id: I112d97d251c9e9b1a39196ddcc39a37024b441f6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/widgets/itemviews/qabstractitemview.cpp')
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 5f3861202b..ac1eb0c78d 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -1857,7 +1857,6 @@ void QAbstractItemView::mousePressEvent(QMouseEvent *event) void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) { Q_D(QAbstractItemView); - QPoint topLeft; QPoint bottomRight = event->position().toPoint(); d->draggedPosition = bottomRight + d->offset(); @@ -1867,13 +1866,7 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) #if QT_CONFIG(draganddrop) if (state() == DraggingState) { - topLeft = d->pressedPosition - d->offset(); - if ((topLeft - bottomRight).manhattanLength() > QApplication::startDragDistance()) { - d->pressedIndex = QModelIndex(); - startDrag(d->model->supportedDragActions()); - setState(NoState); // the startDrag will return when the dnd operation is done - stopAutoScroll(); - } + d->maybeStartDrag(bottomRight); return; } #endif // QT_CONFIG(draganddrop) @@ -1884,10 +1877,8 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) || edit(index, NoEditTriggers, event)) return; - if (d->selectionMode != SingleSelection) - topLeft = d->pressedPosition - d->offset(); - else - topLeft = bottomRight; + const QPoint topLeft = + d->selectionMode != SingleSelection ? d->pressedPosition - d->offset() : bottomRight; d->checkMouseMove(index); @@ -1898,6 +1889,7 @@ void QAbstractItemView::mouseMoveEvent(QMouseEvent *event) && (event->buttons() != Qt::NoButton) && !d->selectedDraggableIndexes().isEmpty()) { setState(DraggingState); + d->maybeStartDrag(bottomRight); return; } #endif @@ -4701,6 +4693,20 @@ QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const indexes.removeIf(isNotDragEnabled); return indexes; } + +void QAbstractItemViewPrivate::maybeStartDrag(QPoint eventPosition) +{ + Q_Q(QAbstractItemView); + + const QPoint topLeft = pressedPosition - offset(); + if ((topLeft - eventPosition).manhattanLength() > QApplication::startDragDistance()) { + pressedIndex = QModelIndex(); + q->startDrag(model->supportedDragActions()); + q->setState(QAbstractItemView::NoState); // the startDrag will return when the dnd operation + // is done + q->stopAutoScroll(); + } +} #endif /*! |