[vlc-commits] qml: play control button better mouse handling
    Fatih Uzunoglu 
    git at videolan.org
       
    Thu Aug 27 12:44:55 CEST 2020
    
    
  
vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Tue Aug  4 21:39:44 2020 +0300| [14d571d324fec3ca6a50c6fc37a11aca8720fb0b] | committer: Pierre Lamot
qml: play control button better mouse handling
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=14d571d324fec3ca6a50c6fc37a11aca8720fb0b
---
 modules/gui/qt/player/qml/ControlButtons.qml | 41 ++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)
diff --git a/modules/gui/qt/player/qml/ControlButtons.qml b/modules/gui/qt/player/qml/ControlButtons.qml
index ff1b10faa9..7602ca869b 100644
--- a/modules/gui/qt/player/qml/ControlButtons.qml
+++ b/modules/gui/qt/player/qml/ControlButtons.qml
@@ -156,7 +156,7 @@ Item{
             property bool paintOnly: false
             enabled: !paintOnly
 
-            onClicked: mainPlaylistController.togglePlayPause()
+            property bool realHovered: false
 
             contentItem: Label {
                 color: videoOverlays ? (playBtn.enabled ? playBtn.color : playBtn.colorDisabled)
@@ -176,6 +176,43 @@ Item{
 
             background: Item {
 
+                MouseArea {
+                    id: playBtnMouseArea
+
+                    anchors.fill: parent
+                    anchors.margins: VLCStyle.dp(1)
+
+                    hoverEnabled: true
+
+                    readonly property int radius: playBtnMouseArea.width / 2
+
+                    function distance2D(x0, y0, x1, y1) {
+                        return Math.sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))
+                    }
+
+                    onPositionChanged: {
+                        if (distance2D(playBtnMouseArea.mouseX, playBtnMouseArea.mouseY, playBtnMouseArea.width / 2, playBtnMouseArea.height / 2) < radius) {
+                            // mouse is inside of the round button
+                            playBtn.realHovered = true
+                        }
+                        else {
+                            // mouse is outside
+                            playBtn.realHovered = false
+                        }
+                    }
+
+                    onHoveredChanged: {
+                        if (!playBtnMouseArea.containsMouse)
+                            playBtn.realHovered = false
+                    }
+
+                    onClicked: {
+                        if (playBtn.realHovered)
+                            mainPlaylistController.togglePlayPause()
+                    }
+
+                }
+
                 Rectangle {
                     radius: (width * 0.5)
                     anchors.fill: parent
@@ -218,7 +255,7 @@ Item{
                     source: outerRect
                     maskSource: innerRect
 
-                    visible: !(playBtn.activeFocus || playBtn.hovered || playBtn.highlighted)
+                    visible: !(playBtn.activeFocus || playBtn.realHovered || playBtn.highlighted)
                     antialiasing: true
                 }
             }
    
    
More information about the vlc-commits
mailing list