[vlc-commits] [Git][videolan/vlc][master] qml: fix dragging multiple items in KeyNavigableTableView

Steve Lhomme (@robUx4) gitlab at videolan.org
Mon Jul 22 15:22:59 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
bdd4ca71 by Fatih Uzunoglu at 2024-07-22T14:57:49+00:00
qml: fix dragging multiple items in KeyNavigableTableView

This already works fine in other places, I must have missed
updating this in the last iteration.

Brief explanation of how this works:

- Tap handler should set the focus, even if the drag handler
  takes over. This means that the focus should be set in
  both `canceled()` and `singleTapped()` handlers. This
  merely corresponds to `pressed()` signal of mouse area.
- Tap handler should not update the selection if the drag
  handler takes over. This means that the selection should
  not be updated upon `canceled()` but `singleTapped()`
- Drag handler must update the selection when it becomes
  active, as long as the dragged item is not already
  selected.

- - - - -


1 changed file:

- modules/gui/qt/widgets/qml/TableViewDelegate.qml


Changes:

=====================================
modules/gui/qt/widgets/qml/TableViewDelegate.qml
=====================================
@@ -112,6 +112,10 @@ T.Control {
             onActiveChanged: {
                 if (dragItem) {
                     if (active) {
+                        if (!selected) {
+                            delegate.ListView.view.selectionModel.select(index, ItemSelectionModel.ClearAndSelect)
+                        }
+
                         dragItem.Drag.active = true
                     } else {
                         dragItem.Drag.drop()
@@ -129,11 +133,17 @@ T.Control {
 
             grabPermissions: TapHandler.CanTakeOverFromHandlersOfDifferentType | TapHandler.ApprovesTakeOverByAnything
 
-            onSingleTapped: (point, button) => {
+            onSingleTapped: (eventPoint, button) => {
                 initialAction()
 
+                if (!(delegate.selected && button === Qt.RightButton)) {
+                    const view = delegate.ListView.view
+                    view.selectionModel.updateSelection(point.modifiers, view.currentIndex, index)
+                    view.currentIndex = index
+                }
+
                 if (button === Qt.RightButton)
-                    delegate.rightClick(delegate, delegate.rowModel, parent.mapToGlobal(point.position.x, point.position.y))
+                    delegate.rightClick(delegate, delegate.rowModel, parent.mapToGlobal(eventPoint.position.x, eventPoint.position.y))
             }
 
             onDoubleTapped: (point, button) => {
@@ -146,9 +156,7 @@ T.Control {
             }
 
             function initialAction() {
-                if ((point.pressedButtons === Qt.LeftButton) || !delegate.selected) {
-                    delegate.selectAndFocus(point.modifiers, Qt.MouseFocusReason)
-                }
+                delegate.forceActiveFocus(Qt.MouseFocusReason)
             }
         }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/bdd4ca716081abb5c4a54b33bf1c86af8cb6cbad

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/bdd4ca716081abb5c4a54b33bf1c86af8cb6cbad
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list