[vlc-devel] [PATCH 07/16] qml: support drag item in table view

Prince Gupta guptaprince8832 at gmail.com
Fri Dec 4 12:19:04 CET 2020


---
 .../qt/widgets/qml/KeyNavigableTableView.qml  | 24 +++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
index 3a541aa8c0..8efa0cb802 100644
--- a/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
+++ b/modules/gui/qt/widgets/qml/KeyNavigableTableView.qml
@@ -78,6 +78,7 @@ NavigableFocusScope {
 
     property alias add:       view.add
     property alias displaced: view.displaced
+    property Item dragItem
 
     Accessible.role: Accessible.Table
 
@@ -199,6 +200,7 @@ NavigableFocusScope {
             property alias showSeparator: separator.visible
             readonly property bool highlighted: selected || hoverArea.containsMouse || activeFocus
             readonly property int _index: index
+            property int _modifiersOnLastPress: Qt.NoModifier
 
             width: view.width
             height: root.rowHeight
@@ -222,6 +224,20 @@ NavigableFocusScope {
                 hoverEnabled: true
                 Keys.onMenuPressed: root.contextMenuButtonClicked(contextButton,rowModel)
                 acceptedButtons: Qt.RightButton | Qt.LeftButton
+                drag.target: root.dragItem
+                drag.axis: Drag.XAndYAxis
+                drag.onActiveChanged: {
+                    // perform the "click" action because the click action is only executed on mouse release (we are in the pressed state)
+                    // but we will need the updated list on drop
+                    if (drag.active && !selectionDelegateModel.isSelected(root.model.index(index, 0))) {
+                        selectionDelegateModel.updateSelection(_modifiersOnLastPress , view.currentIndex, index)
+                    } else if (root.dragItem) {
+                        root.dragItem.Drag.drop()
+                    }
+                    root.dragItem.Drag.active = drag.active
+                }
+
+                onPressed: _modifiersOnLastPress = mouse.modifiers
 
                 onClicked: {
                     if (mouse.button === Qt.LeftButton || !selectionDelegateModel.isSelected(root.model.index(index, 0))) {
@@ -235,6 +251,14 @@ NavigableFocusScope {
                     }
                 }
 
+                onPositionChanged: {
+                    if (drag.active) {
+                        var pos = drag.target.parent.mapFromItem(hoverArea, mouseX, mouseY)
+                        drag.target.x = pos.x + 12
+                        drag.target.y = pos.y + 12
+                    }
+                }
+
                 onDoubleClicked: {
                     actionForSelection(selectionDelegateModel.selectedIndexes)
                     root.itemDoubleClicked(model)
-- 
2.25.1



More information about the vlc-devel mailing list