[vlc-commits] qml: fix drag auto scroll in toolbar editor

Fatih Uzunoglu git at videolan.org
Tue Apr 6 09:55:13 UTC 2021


vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Apr  2 01:22:40 2021 +0300| [87717a7a50f818f76d1a45133d4056898695af75] | committer: Pierre Lamot

qml: fix drag auto scroll in toolbar editor

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

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

 .../qt/dialogs/toolbar/qml/EditorDNDDelegate.qml   |  3 +-
 .../gui/qt/dialogs/toolbar/qml/ToolbarEditor.qml   | 72 ++++++++++++----------
 2 files changed, 42 insertions(+), 33 deletions(-)

diff --git a/modules/gui/qt/dialogs/toolbar/qml/EditorDNDDelegate.qml b/modules/gui/qt/dialogs/toolbar/qml/EditorDNDDelegate.qml
index 8107cb2279..360397d04f 100644
--- a/modules/gui/qt/dialogs/toolbar/qml/EditorDNDDelegate.qml
+++ b/modules/gui/qt/dialogs/toolbar/qml/EditorDNDDelegate.qml
@@ -135,7 +135,8 @@ MouseArea {
         }
 
         onXChanged: {
-            root.handleScroll(this)
+            if (content.Drag.active)
+                root.handleScroll(this)
         }
     }
 
diff --git a/modules/gui/qt/dialogs/toolbar/qml/ToolbarEditor.qml b/modules/gui/qt/dialogs/toolbar/qml/ToolbarEditor.qml
index f60879c7d9..e04fe5166d 100644
--- a/modules/gui/qt/dialogs/toolbar/qml/ToolbarEditor.qml
+++ b/modules/gui/qt/dialogs/toolbar/qml/ToolbarEditor.qml
@@ -186,6 +186,8 @@ Rectangle{
                                         onContainsDragChanged: {
                                             if (containsDrag)
                                                 _viewThatContainsDrag = this
+                                            else if (_viewThatContainsDrag === this)
+                                                _viewThatContainsDrag = null
                                         }
 
                                         Text {
@@ -252,57 +254,63 @@ Rectangle{
         }
 
         onXChanged: {
-            handleScroll(this)
+            if (buttonDragItem.Drag.active)
+                handleScroll(this)
         }
     }
 
-    property int _scrollingDirection: 0
-
     function handleScroll(dragItem) {
         var view = _viewThatContainsDrag
 
-        if (view === undefined) {
-            upAnimation.target = null
-            downAnimation.target = null
-
-            _scrollingDirection = 0
-            return
+        if (view === undefined || view === null) {
+            if (!!scrollAnimation.target)
+                view = scrollAnimation.target
+            else
+                return
         }
 
-        upAnimation.target = view
-        downAnimation.target = view
-
-        downAnimation.to = Qt.binding(function() { return view.contentWidth - view.width; })
+        var dragItemX = dragItem.x
+        var viewX     = view.mapToItem(root, view.x, view.y).x
 
-        var dragItemX = root.mapToGlobal(dragItem.x, dragItem.y).x
-        var viewX     = view.mapToGlobal(view.x, view.y).x
+        var leftMark  = (viewX + VLCStyle.dp(20, VLCStyle.scale))
+        var rightMark = (viewX + view.width - VLCStyle.dp(20, VLCStyle.scale))
 
-        var leftDiff  = (viewX + VLCStyle.dp(20, VLCStyle.scale)) - dragItemX
-        var rightDiff = dragItemX - (viewX + view.width - VLCStyle.dp(20, VLCStyle.scale))
+        scrollAnimation.target = view
+        scrollAnimation.dragItem = dragItem
 
-        if (!view.atXBeginning && leftDiff > 0) {
-            _scrollingDirection = -1
-        } else if (!view.atXEnd && rightDiff > 0) {
-            _scrollingDirection = 1
+        if (!view.atXBeginning && dragItemX <= leftMark) {
+            scrollAnimation.direction = -1
+        } else if (!view.atXEnd && dragItemX >= rightMark) {
+            scrollAnimation.direction = 1
         } else {
-            _scrollingDirection = 0
+            scrollAnimation.direction = 0
         }
     }
 
     SmoothedAnimation {
-        id: upAnimation
-        property: "contentX"
-        to: 0
-        running: root._scrollingDirection === -1 && target !== null
+        id: scrollAnimation
+
+        property var dragItem
+        property int direction: 0 // -1: left, 0: stop, 1: right
+
+        to: {
+            if (direction === -1)
+                0
+            else if (direction === 1 && !!target)
+                target.contentWidth - target.width
+            else
+                0
+        }
 
-        velocity: VLCStyle.dp(150, VLCStyle.scale)
-    }
+        running: {
+            if (!!dragItem && (direction === -1 || direction === 1))
+                dragItem.Drag.active
+            else
+                false
+        }
 
-    SmoothedAnimation {
-        id: downAnimation
         property: "contentX"
-        running: root._scrollingDirection === 1 && target !== null
-
         velocity: VLCStyle.dp(150, VLCStyle.scale)
+        reversingMode: SmoothedAnimation.Immediate
     }
 }



More information about the vlc-commits mailing list