[vlc-devel] [PATCH 25/38] qml: play control button better mouse handling
Fatih Uzunoglu
fuzun54 at outlook.com
Thu Aug 20 19:55:34 CEST 2020
---
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
}
}
--
2.25.1
More information about the vlc-devel
mailing list