[vlc-devel] [PATCH 23/27] qml: enable automatic scroll during playlist item dragging

Fatih Uzunoglu fuzun54 at outlook.com
Fri Oct 9 18:56:44 CEST 2020


---
 .../gui/qt/playlist/qml/PlaylistListView.qml  | 48 +++++++++++++++++++
 modules/gui/qt/widgets/qml/DNDLabel.qml       |  6 +++
 2 files changed, 54 insertions(+)

diff --git a/modules/gui/qt/playlist/qml/PlaylistListView.qml b/modules/gui/qt/playlist/qml/PlaylistListView.qml
index ca13da18d5..c84d00bc2d 100644
--- a/modules/gui/qt/playlist/qml/PlaylistListView.qml
+++ b/modules/gui/qt/playlist/qml/PlaylistListView.qml
@@ -65,8 +65,56 @@ Widgets.NavigableFocusScope {
         //label for DnD
         Widgets.DNDLabel {
             id: dragItem
+
             _colors: root._colors
             color: parent.color
+
+            property int _scrollingDirection: 0
+
+            on_PosChanged: {
+                var dragItemY = root.mapToGlobal(dragItem._pos.x, dragItem._pos.y).y
+                var viewY     = root.mapToGlobal(view.x, view.y).y
+
+                var topDiff    = (viewY + VLCStyle.dp(20, VLCStyle.scale)) - dragItemY
+                var bottomDiff = dragItemY - (viewY + view.height - VLCStyle.dp(20, VLCStyle.scale))
+
+                if(!view.listView.atYBeginning && topDiff > 0) {
+                    _scrollingDirection = -1
+
+                    view.fadeRectTopHovered = true
+                }
+                else if( !view.listView.atYEnd && bottomDiff > 0) {
+                    _scrollingDirection = 1
+
+                    view.fadeRectBottomHovered = true
+                }
+                else {
+                    _scrollingDirection = 0
+
+                    view.fadeRectTopHovered = false
+                    view.fadeRectBottomHovered = false
+                }
+            }
+
+            SmoothedAnimation {
+                id: upAnimation
+                target: view.listView
+                property: "contentY"
+                to: 0
+                running: dragItem._scrollingDirection === -1 && dragItem.visible
+
+                velocity: VLCStyle.dp(150, VLCStyle.scale)
+            }
+
+            SmoothedAnimation {
+                id: downAnimation
+                target: view.listView
+                property: "contentY"
+                to: view.listView.contentHeight - view.height
+                running: dragItem._scrollingDirection === 1 && dragItem.visible
+
+                velocity: VLCStyle.dp(150, VLCStyle.scale)
+            }
         }
 
         PlaylistContextMenu {
diff --git a/modules/gui/qt/widgets/qml/DNDLabel.qml b/modules/gui/qt/widgets/qml/DNDLabel.qml
index 39a189faf3..d6e209245a 100644
--- a/modules/gui/qt/widgets/qml/DNDLabel.qml
+++ b/modules/gui/qt/widgets/qml/DNDLabel.qml
@@ -42,10 +42,16 @@ Rectangle {
 
     property var count: 0
 
+    property point _pos: null
+
     function updatePos(x, y) {
         var pos = root.mapFromGlobal(x, y)
         dragItem.x = pos.x
         dragItem.y = pos.y
+
+        // since we override position update during dragging with updatePos(),
+        // it is better to track the final position through a property:
+        _pos = pos
     }
 
     RectangularGlow {
-- 
2.25.1



More information about the vlc-devel mailing list