[vlc-commits] [Git][videolan/vlc][master] 3 commits: qml: make playback speed button has fixed width

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sun Jan 19 12:07:00 UTC 2025



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


Commits:
e0059c3c by Fatih Uzunoglu at 2025-01-19T11:53:50+00:00
qml: make playback speed button has fixed width

- - - - -
fb2f15e6 by Fatih Uzunoglu at 2025-01-19T11:53:50+00:00
qml: handle high precision adjustment and use `WheelToVLCConverter` in `PlaybackSpeedButton.qml`

- - - - -
fbe1b1e8 by Fatih Uzunoglu at 2025-01-19T11:53:50+00:00
qml: handle horizontal orientation as well in `PlaybackSpeedButton` wheel handler

- - - - -


1 changed file:

- modules/gui/qt/player/qml/controlbarcontrols/PlaybackSpeedButton.qml


Changes:

=====================================
modules/gui/qt/player/qml/controlbarcontrols/PlaybackSpeedButton.qml
=====================================
@@ -44,16 +44,32 @@ PopupIconToolButton {
         Navigation.rightItem: root
     }
 
-    contentItem: T.Label {
-        verticalAlignment: Text.AlignVCenter
-        horizontalAlignment: Text.AlignHCenter
+    contentItem: Item {
+        implicitHeight: label.implicitHeight
+        implicitWidth: textMetrics.width
+
+        TextMetrics {
+            id: textMetrics
+            font: label.font
+            // '-' is for additional space if certain digits have more width with certain fonts
+            text: "0.00x-"
+        }
+
+        Text {
+            id: label
+
+            anchors.fill: parent
+
+            verticalAlignment: Text.AlignVCenter
+            horizontalAlignment: Text.AlignHCenter
 
-        font.pixelSize: VLCStyle.fontSize_normal
+            font.pixelSize: VLCStyle.fontSize_normal
 
-        text: !root.paintOnly ? qsTr("%1x").arg(+Player.rate.toFixed(2))
-                              : qsTr("1x")
+            text: !root.paintOnly ? qsTr("%1x").arg(+Player.rate.toFixed(2))
+                                  : qsTr("1x")
 
-        color: root.color
+            color: root.color
+        }
     }
 
     // TODO: Qt bug 6.2: QTBUG-103604
@@ -62,39 +78,53 @@ PopupIconToolButton {
 
         z: -1
 
+        WheelToVLCConverter {
+            id: wheelToVLC
+
+            function handle(steps: int) {
+                let func
+                if (steps > 0)
+                    func = root.popup.contentItem.slider.increase
+                else
+                    func = root.popup.contentItem.slider.decrease
+
+                for (let i = 0; i < Math.abs(steps); ++i)
+                    func()
+            }
+
+            Component.onCompleted: {
+                wheelUpDown.connect(wheelToVLC.handle)
+                wheelLeftRight.connect(wheelToVLC.handle)
+            }
+        }
+
         WheelHandler {
-            onWheel: (event) => {
+            orientation: Qt.Vertical | Qt.Horizontal
+
+            onWheel: (wheel) => {
                 if (!root.popup.contentItem || !root.popup.contentItem.slider) {
                     event.accepted = false
                     return
                 }
 
-                let delta = 0
-
-                if (event.angleDelta.x)
-                    delta = event.angleDelta.x
-                else if (event.angleDelta.y)
-                    delta = event.angleDelta.y
-                else {
-                    event.accepted = false
-                    return
+                // NOTE: Uncomment below to support (not only handle) high precision adjustment:
+                // if ((Math.abs(wheel.pixelDelta.x) % 120 > 0) || (Math.abs(wheel.pixelDelta.y) % 120 > 0)) {
+                //     let delta = 0
+                //     if (Math.abs(wheel.pixelDelta.x) > Math.abs(wheel.pixelDelta.y))
+                //         delta = wheel.pixelDelta.x
+                //     else
+                //         delta = wheel.pixelDelta.y
+
+                //     if (wheel.inverted)
+                //         delta = -delta
+
+                //     root.popup.contentItem.slider.value += 0.01 * delta
+                // } else
+                {
+                    wheelToVLC.qmlWheelEvent(wheel)
                 }
 
-                if (event.inverted)
-                    delta = -delta
-
-                event.accepted = true
-
-                delta = delta / 8 / 15
-
-                let func
-                if (delta > 0)
-                    func = root.popup.contentItem.slider.increase
-                else
-                    func = root.popup.contentItem.slider.decrease
-
-                for (let i = 0; i < Math.ceil(Math.abs(delta)); ++i)
-                    func()
+                wheel.accepted = true
             }
         }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/cf03e5ea9850ae855a5ded44649372ed27aa9fe3...fbe1b1e8b6a6adf3951b7a5f0ffe007b022da9b9

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