[vlc-commits] qml: support drag item in table view

Prince Gupta git at videolan.org
Thu Dec 10 09:34:49 UTC 2020


vlc | branch: master | Prince Gupta <guptaprince8832 at gmail.com> | Thu Nov 12 15:03:52 2020 +0530| [5ff57a501b64b43374bfb44dfb4b9d3cb0ff6d59] | committer: Pierre Lamot

qml: support drag item in table view

Signed-off-by: Pierre Lamot <pierre at videolabs.io>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5ff57a501b64b43374bfb44dfb4b9d3cb0ff6d59
---

 .../gui/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)



More information about the vlc-commits mailing list