[vlc-devel] [PATCH 28/29] qml: fix drag auto scroll in toolbar editor
Fatih Uzunoglu
fuzun54 at outlook.com
Thu Apr 1 22:22:40 UTC 2021
---
.../dialogs/toolbar/qml/EditorDNDDelegate.qml | 3 +-
.../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
}
}
--
2.27.0
More information about the vlc-devel
mailing list