[vlc-commits] qml: fix slider onHold issue

Abel Tesfaye git at videolan.org
Thu Jun 13 13:11:19 CEST 2019


vlc | branch: master | Abel Tesfaye <Abeltesfaye45 at gmail.com> | Fri May 31 14:00:55 2019 +0300| [e332a704a2a89346432dcd080dd92b4548f55b00] | committer: Thomas Guillem

qml: fix slider onHold issue

Fixes #22289

Signed-off-by: Thomas Guillem <thomas at gllm.fr>
Signed-off-by: Pierre Lamot <pierre at videolabs.io>

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

 modules/gui/qt/qml/player/SliderBar.qml | 42 ++++++++++++++++++++++++++++-----
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/modules/gui/qt/qml/player/SliderBar.qml b/modules/gui/qt/qml/player/SliderBar.qml
index b9a4f3248f..6135f81b9b 100644
--- a/modules/gui/qt/qml/player/SliderBar.qml
+++ b/modules/gui/qt/qml/player/SliderBar.qml
@@ -22,10 +22,22 @@ import "qrc:///style/"
 
 Slider {
     id: control
+    property int barHeight: 5
+    property bool _isHold: false
+
     anchors.margins: VLCStyle.margin_xxsmall
 
-    value: player.position
-    onMoved: player.position = control.position
+    Keys.onRightPressed: player.jumpFwd()
+    Keys.onLeftPressed: player.jumpBwd()
+
+    Connections {
+        /* only update the control position when the player position actually change, this avoid the slider
+         * to jump around when clicking
+         */
+        target: player
+        enabled: !_isHold
+        onPositionChanged: control.value = player.position
+    }
 
     height: control.barHeight + VLCStyle.fontHeight_normal + VLCStyle.margin_xxsmall * 2
     implicitHeight: control.barHeight + VLCStyle.fontHeight_normal + VLCStyle.margin_xxsmall * 2
@@ -37,8 +49,6 @@ Slider {
 
     stepSize: 0.01
 
-    property int barHeight: 5
-
     background: Rectangle {
         id: sliderRect
         width: control.availableWidth
@@ -46,7 +56,27 @@ Slider {
         height: implicitHeight
         color: "transparent"
 
+        MouseArea {
+            anchors.fill: parent
+            hoverEnabled: true
+
+            onPressed: function (event) {
+                control.focus = true
+                control._isHold = true
+                control.value = event.x / control.width
+                player.position = control.value
+            }
+            onReleased: control._isHold = false
+            onPositionChanged: function (event) {
+                if (pressed && (event.x <= control.width)) {
+                    control.value = event.x / control.width
+                    player.position = control.value
+                }
+            }
+        }
+
         Rectangle {
+            id: progressRect
             width: control.visualPosition * parent.width
             height: control.barHeight
             color: control.activeFocus ? VLCStyle.colors.accent : VLCStyle.colors.bgHover
@@ -54,7 +84,7 @@ Slider {
         }
 
         Rectangle {
-            id: bufferRect    
+            id: bufferRect
             property int bufferAnimWidth: 100 * VLCStyle.scale
             property int bufferAnimPosition: 0
             property int bufferFrames: 1000
@@ -73,7 +103,7 @@ Slider {
                         target: bufferRect
                         width: bufferAnimWidth
                         visible: true
-                        x: (bufferAnimPosition / bufferFrames)* (parent.width - bufferAnimWidth)
+                        x: (bufferAnimPosition / bufferFrames) * (parent.width - bufferAnimWidth)
                         animateLoading: true
                     }
                 },



More information about the vlc-commits mailing list