[vlc-commits] [Git][videolan/vlc][master] 14 commits: Revert "qml: don't reuse the end position for DragItem on the subsequent drag"

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Jun 12 13:47:07 UTC 2023



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
e511e7da by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
Revert "qml: don't reuse the end position for DragItem on the subsequent drag"

This reverts commit ecbea8c9072515a04c4434c2d4faacfb9d4493e9.

- - - - -
3063e7b6 by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: get rid of unnecessary property in DragItem

- - - - -
6acb7565 by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: fix DragItem position overriding in EditorDNDDelegate

- - - - -
dbe9305b by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: use VLCStyle.dragDelta in EditorDNDDelegate

- - - - -
42b5c478 by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: fix DragItem position overriding in GridItem

- - - - -
3030a1ae by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: fix DragItem position overriding in MusicArtistDelegate

- - - - -
789cd96f by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: fix DragItem position overriding in PlaylistDelegate

- - - - -
85cd09d8 by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: use VLCStyle.dragDelta in PlaylistDelegate

- - - - -
5214acde by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: fix DragItem position overriding in TableViewDelegate

- - - - -
728c4e22 by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: fix DragItem position overriding in ToolbarEditorButtonList

- - - - -
8c6b1dae by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: use VLCStyle.dragDelta in ToolbarEditorButtonList

- - - - -
d8464dc5 by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: export isDropAcceptable() as itemsMovable() to Helpers.js

- - - - -
99a7704a by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: use Helpers instead of isDropAcceptable() in PlaylistListView

- - - - -
f9757321 by Fatih Uzunoglu at 2023-06-12T13:10:27+00:00
qml: early resolve Playlist drag item indexes

- - - - -


9 changed files:

- modules/gui/qt/dialogs/toolbar/qml/EditorDNDDelegate.qml
- modules/gui/qt/dialogs/toolbar/qml/ToolbarEditorButtonList.qml
- modules/gui/qt/medialibrary/qml/MusicArtistDelegate.qml
- modules/gui/qt/playlist/qml/PlaylistDelegate.qml
- modules/gui/qt/playlist/qml/PlaylistListView.qml
- modules/gui/qt/util/qml/Helpers.js
- modules/gui/qt/widgets/qml/DragItem.qml
- modules/gui/qt/widgets/qml/GridItem.qml
- modules/gui/qt/widgets/qml/TableViewDelegate.qml


Changes:

=====================================
modules/gui/qt/dialogs/toolbar/qml/EditorDNDDelegate.qml
=====================================
@@ -58,6 +58,8 @@ Control {
 
         drag.target: loader
 
+        drag.smoothed: false
+
         hoverEnabled: true
 
         drag.onActiveChanged: {
@@ -75,15 +77,10 @@ Control {
             }
         }
 
-        onPositionChanged: {
-            if (drag.active) {
-                // FIXME: There must be a better way of this
-                const pos = mapToItem(loader.parent, mouseX, mouseY)
-                // y should be set first, because the automatic scroll is
-                // triggered by change on X
-                loader.y = pos.y
-                loader.x = pos.x
-            }
+        onPressed: {
+            const pos = mapToItem(loader.parent, mouseX, mouseY)
+            loader.y = pos.y + VLCStyle.dragDelta
+            loader.x = pos.x + VLCStyle.dragDelta
         }
     }
 


=====================================
modules/gui/qt/dialogs/toolbar/qml/ToolbarEditorButtonList.qml
=====================================
@@ -135,6 +135,8 @@ GridView {
 
         drag.target: buttonDragItem
 
+        drag.smoothed: false
+
         readonly property int mIndex: PlayerControlbarControls.controlList[model.index].id
 
         drag.onActiveChanged: {
@@ -155,16 +157,10 @@ GridView {
             }
         }
 
-        onPositionChanged: {
-            if (drag.active) {
-                // FIXME: There must be a better way of this
-
-                const pos = mapToItem(buttonDragItem.parent, mouseX, mouseY)
-                // y should be set first, because the automatic scroll is
-                // triggered by change on X
-                buttonDragItem.y = pos.y
-                buttonDragItem.x = pos.x
-            }
+        onPressed: {
+            const pos = mapToItem(buttonDragItem.parent, mouseX, mouseY)
+            buttonDragItem.y = pos.y + VLCStyle.dragDelta
+            buttonDragItem.x = pos.x + VLCStyle.dragDelta
         }
 
         Rectangle {


=====================================
modules/gui/qt/medialibrary/qml/MusicArtistDelegate.qml
=====================================
@@ -78,6 +78,7 @@ T.ItemDelegate {
         hoverEnabled: true
 
         drag.axis: Drag.XAndYAxis
+        drag.smoothed: false
 
         drag.target: Widgets.DragItem {
             indexes: [index]
@@ -102,9 +103,7 @@ T.ItemDelegate {
             dragItem.Drag.active = drag.active;
         }
 
-        onPositionChanged: {
-            if (drag.active == false) return;
-
+        onPressed: {
             const pos = drag.target.parent.mapFromItem(root, mouseX, mouseY);
 
             drag.target.x = pos.x + VLCStyle.dragDelta;


=====================================
modules/gui/qt/playlist/qml/PlaylistDelegate.qml
=====================================
@@ -264,8 +264,16 @@ T.ItemDelegate {
                 mainPlaylistController.goTo(index, true)
         }
 
+        onPressed: {
+            const pos = mapToItem(dragItem.parent, mouseX, mouseY)
+            dragItem.x = pos.x + VLCStyle.dragDelta
+            dragItem.y = pos.y + VLCStyle.dragDelta
+        }
+
         drag.target: dragItem
 
+        drag.smoothed: false
+
         drag.onActiveChanged: {
             if (drag.active) {
                 if (!selected) {
@@ -273,32 +281,16 @@ T.ItemDelegate {
                     root.model.setSelection([index])
                 }
 
-                if (contains(mapFromItem(dragItem.parent, dragItem.x, dragItem.y))) {
-                    // Force trigger entered signal in drop areas
-                    // so that containsDrag work properly
-                    dragItem.x = -1
-                    dragItem.y = -1
-                }
-
-                dragItem.Drag.active = drag.active
-            }
-            else {
+                dragItem.indexes = root.model.getSelection()
+                dragItem.Drag.active = true
+            } else {
                 dragItem.Drag.drop()
             }
         }
 
-        onPositionChanged: {
-            if (drag.active) {
-                // FIXME: Override dragItem's position
-                const pos = mapToItem(dragItem.parent, mouseX, mouseY)
-                dragItem.x = pos.x + VLCStyle.dp(15)
-                dragItem.y = pos.y
-            }
-        }
-
         TapHandler {
             acceptedDevices: PointerDevice.TouchScreen
-
+            
             onTapped: {
                 if (root.mode === PlaylistListView.Mode.Normal) {
                     mainPlaylistController.goTo(index, true)


=====================================
modules/gui/qt/playlist/qml/PlaylistListView.qml
=====================================
@@ -65,32 +65,10 @@ Control {
     }
 
     function isDropAcceptable(drop, index) {
-        if (drop.hasUrls)
-            return true // external drop (i.e. from filesystem)
-
-        if (Helpers.isValidInstanceOf(drop.source, Widgets.DragItem)) {
-            // internal drop (inter-view or intra-playlist)
-            const selection = drop.source.selection
-            if (!!selection) {
-                const length = selection.length
-                const firstIndex = selection[0]
-                const lastIndex = selection[length - 1]
-                let consecutive = true
-                if (length > 1) {
-                    for (let i = 0; i < length - 1; ++i) {
-                        if (selection[i + 1] - selection[i] !== 1) {
-                            consecutive = false
-                            break
-                        }
-                    }
-                }
-                return !consecutive || (index > lastIndex + 1 || index < firstIndex)
-            } else {
-                return true
-            }
-        }
-
-        return false
+        if (drop.source === dragItem)
+            return Helpers.itemsMovable(drop.source.indexes, index)
+        else
+            return true
     }
 
     function acceptDrop(index, drop) {
@@ -163,13 +141,7 @@ Control {
 
         parent: (typeof g_mainDisplay !== 'undefined') ? g_mainDisplay : root
 
-        property var selection: null // make this indexes alias?
-
-        indexes: selection
-
         onRequestData: {
-            selection = root.model.getSelection()
-            indexes = selection
             setData(identifier, indexes.map(function (index) {
                 const item = root.model.itemAt(index)
                 return {


=====================================
modules/gui/qt/util/qml/Helpers.js
=====================================
@@ -69,3 +69,27 @@ function alignUp(a, b) {
 function alignDown(a, b) {
     return Math.floor(a / b) * b
 }
+
+function isSortedIntegerArrayConsecutive(array) {
+    const length = array.length
+
+    if (length <= 1)
+        return true
+
+    const first = array[0]
+    const last = array[length - 1]
+
+    if (length === 2)
+        return Math.abs(first - last) === 1
+
+    const sum1 = array.reduce((i, j) => i + j)
+    const sum2 = length * (first + last) / 2
+
+    return (sum1 === sum2)
+}
+
+function itemsMovable(sortedItemIndexes, targetIndex) {
+    return !isSortedIntegerArrayConsecutive(sortedItemIndexes) ||
+            (targetIndex > (sortedItemIndexes[sortedItemIndexes.length - 1] + 1) ||
+             targetIndex < sortedItemIndexes[0])
+}


=====================================
modules/gui/qt/widgets/qml/DragItem.qml
=====================================
@@ -81,7 +81,7 @@ Item {
         console.assert(data.length === indexes.length)
         _data = data
 
-        if (!dragItem._active)
+        if (!dragItem.Drag.active)
             return
 
         Qt.callLater(dragItem.getSelectedInputItem, dragItem.setInputItems)
@@ -126,8 +126,6 @@ Item {
 
     readonly property int _maxCovers: 3
 
-    readonly property bool _active: Drag.active
-
     readonly property int _indexesSize: !!indexes ? indexes.length : 0
 
     readonly property int _displayedCoversCount: Math.min(_indexesSize, _maxCovers + 1)
@@ -142,16 +140,6 @@ Item {
 
     property int _currentRequest: 0
 
-    Drag.onActiveChanged: {
-        // FIXME: This should not be ideally necessary
-        // TODO: Rework D&D positioning
-        if (!Drag.active)
-            x = y = -1
-
-        if (!Drag.active)
-            dragItem._inputItems = undefined
-    }
-
     //---------------------------------------------------------------------------------------------
     // Implementation
     //---------------------------------------------------------------------------------------------
@@ -188,9 +176,8 @@ Item {
     Accessible.role: Accessible.NoRole
     Accessible.name: I18n.qtr("drag item")
 
-    on_ActiveChanged: {
-        if (_active) {
-
+    Drag.onActiveChanged: {
+        if (Drag.active) {
             // reset any data from previous drags before requesting new data,
             // so that we don't show invalid data while data is being requested
             _title = ""
@@ -203,6 +190,8 @@ Item {
             MainCtx.setCursor(Qt.DragMoveCursor)
         } else {
             MainCtx.restoreCursor()
+
+            dragItem._inputItems = undefined
         }
     }
 


=====================================
modules/gui/qt/widgets/qml/GridItem.qml
=====================================
@@ -188,6 +188,8 @@ T.ItemDelegate {
 
         drag.axis: Drag.XAndYAxis
 
+        drag.smoothed: false
+
         onClicked: {
             if (mouse.button === Qt.RightButton)
                 contextMenuButtonClicked(picture, root.mapToGlobal(mouse.x,mouse.y));
@@ -201,14 +203,12 @@ T.ItemDelegate {
                 root.itemDoubleClicked(picture,mouse.buttons, mouse.modifiers)
         }
 
-        onPressed: _modifiersOnLastPress = mouse.modifiers
+        onPressed: {
+            _modifiersOnLastPress = mouse.modifiers
 
-        onPositionChanged: {
-            if (drag.active) {
-                const pos = drag.target.parent.mapFromItem(root, mouseX, mouseY)
-                drag.target.x = pos.x + VLCStyle.dragDelta
-                drag.target.y = pos.y + VLCStyle.dragDelta
-            }
+            const pos = drag.target.parent.mapFromItem(root, mouseX, mouseY)
+            drag.target.x = pos.x + VLCStyle.dragDelta
+            drag.target.y = pos.y + VLCStyle.dragDelta
         }
 
         drag.onActiveChanged: {


=====================================
modules/gui/qt/widgets/qml/TableViewDelegate.qml
=====================================
@@ -125,9 +125,18 @@ T.Control {
 
             drag.axis: Drag.XAndYAxis
 
+            drag.smoothed: false
+
             // Events
 
-            onPressed: _modifiersOnLastPress = mouse.modifiers
+            onPressed: {
+                _modifiersOnLastPress = mouse.modifiers
+
+                const pos = drag.target.parent.mapFromItem(hoverArea, mouseX, mouseY);
+
+                drag.target.x = pos.x + VLCStyle.dragDelta;
+                drag.target.y = pos.y + VLCStyle.dragDelta;
+            }
 
             onClicked: {
                 if ((mouse.button === Qt.LeftButton) || !delegate.selected) {
@@ -138,16 +147,6 @@ T.Control {
                     delegate.rightClick(delegate, delegate.rowModel, hoverArea.mapToGlobal(mouse.x, mouse.y))
             }
 
-            onPositionChanged: {
-                if (drag.active == false)
-                    return;
-
-                const pos = drag.target.parent.mapFromItem(hoverArea, mouseX, mouseY);
-
-                drag.target.x = pos.x + VLCStyle.dragDelta;
-                drag.target.y = pos.y + VLCStyle.dragDelta;
-            }
-
             onDoubleClicked: {
                 if (mouse.button === Qt.LeftButton)
                     delegate.itemDoubleClicked(delegate._index, delegate.rowModel)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/400b3de57f7573468fb5fa0f3fb32ffe62e94cf6...f975732120fe04f70f4bbb1fd49aeb94ed97e62c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/400b3de57f7573468fb5fa0f3fb32ffe62e94cf6...f975732120fe04f70f4bbb1fd49aeb94ed97e62c
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