[vlc-devel] [PATCH 1/3] qt: improve right-click volume control

Romain Vimont rom1v at videolabs.io
Wed Apr 7 16:27:04 UTC 2021


Right-click allows to set the volume control to predefined steps (0%,
50%, 100% and 125%).

However, the last step (125%) was only reachable from the last pixel.

Instead, set to the nearest predefined value (and simplify the code for
readability).

         0%      50%      100% 125%
         |        |        |    |
         ^^^^^---------^^^^^^^^^-    (before)
         ^^^^^---------^^^^^^^---    (after)
---
 modules/gui/qt/player/qml/VolumeWidget.qml | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/modules/gui/qt/player/qml/VolumeWidget.qml b/modules/gui/qt/player/qml/VolumeWidget.qml
index 7e087495cf..67ac2ab58c 100644
--- a/modules/gui/qt/player/qml/VolumeWidget.qml
+++ b/modules/gui/qt/player/qml/VolumeWidget.qml
@@ -205,14 +205,15 @@ FocusScope{
 
                     onPositionChanged: function (event) {
                         if (sliderMouseArea.pressedButtons === Qt.RightButton) {
-                            if (sliderMouseArea.mouseX < sliderMouseArea.width * volControl.fullvolpos / 4)
+                            var pos = sliderMouseArea.mouseX * volControl.maxvolpos / sliderMouseArea.width
+                            if (pos < 0.25)
                                 volControl.value = 0
-                            else if (sliderMouseArea.mouseX < sliderMouseArea.width * volControl.fullvolpos * 3 / 4)
+                            else if (pos < 0.75)
                                 volControl.value = 0.5
-                            else if (sliderMouseArea.mouseX >= sliderMouseArea.width)
-                                volControl.value = 1.25
-                            else
+                            else if (pos < 1.125)
                                 volControl.value = 1
+                            else
+                                volControl.value = 1.25
                             return
                         }
 
-- 
2.31.0



More information about the vlc-devel mailing list