[vlc-commits] [Git][videolan/vlc][master] 2 commits: qml/PlayButton: Code cleanup

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat May 13 09:47:15 UTC 2023



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


Commits:
9377da10 by Benjamin Arnaud at 2023-05-13T09:23:29+00:00
qml/PlayButton: Code cleanup

No functional changes.

- - - - -
9d6c7e1c by Benjamin Arnaud at 2023-05-13T09:23:29+00:00
qml/ArtworkInfoWidget: Code cleanup

No functional changes.

- - - - -


2 changed files:

- modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
- modules/gui/qt/player/qml/controlbarcontrols/PlayButton.qml


Changes:

=====================================
modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
=====================================
@@ -15,6 +15,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 import QtQuick 2.12
 import QtQuick.Controls 2.12
 import QtQuick.Layouts 1.12
@@ -25,7 +26,9 @@ import "qrc:///widgets/" as Widgets
 import "qrc:///style/"
 
 AbstractButton {
-    id: artworkInfoItem
+    id: root
+
+    // Properties
 
     property bool paintOnly: false
 
@@ -40,14 +43,29 @@ AbstractButton {
                                                    artistLabel.implicitWidth,
                                                    progressIndicator.implicitWidth)
 
+    readonly property ColorContext colorContext: ColorContext {
+        id: theme
+
+        colorSet: ColorContext.ToolButton
+
+        focused: root.visualFocus
+        hovered: root.hovered
+    }
+
     property int _preferredHeight: VLCStyle.dp(60, VLCStyle.scale)
 
     property bool _keyPressed: false
 
+    // Settings
+
     text: I18n.qtr("Open player")
 
     padding: VLCStyle.focus_border
 
+    Accessible.onPressAction: root.clicked()
+
+    // Keys
+
     Keys.onPressed: {
         if (KeyHelper.matchOk(event)) {
             event.accepted = true
@@ -71,16 +89,9 @@ AbstractButton {
         }
     }
 
-    onClicked: g_mainDisplay.showPlayer()
+    // Events
 
-    Accessible.onPressAction: artworkInfoItem.clicked()
-
-    readonly property ColorContext colorContext: ColorContext {
-        id: theme
-        colorSet: ColorContext.ToolButton
-        focused: artworkInfoItem.visualFocus
-        hovered: artworkInfoItem.hovered
-    }
+    onClicked: g_mainDisplay.showPlayer()
 
     background: Widgets.AnimatedBackground {
         active: visualFocus
@@ -88,6 +99,8 @@ AbstractButton {
         activeBorderColor: theme.visualFocus
     }
 
+    // Children
+
     contentItem: RowLayout {
         spacing: infoColumn.visible ? VLCStyle.margin_xsmall : 0
 
@@ -96,8 +109,7 @@ AbstractButton {
 
             implicitWidth: implicitHeight
 
-            implicitHeight: Math.min(artworkInfoItem._preferredHeight,
-                                     artworkInfoItem.maximumHeight)
+            implicitHeight: Math.min(root._preferredHeight, root.maximumHeight)
 
             color: theme.bg.primary
 
@@ -133,7 +145,7 @@ AbstractButton {
                 Accessible.name: I18n.qtr("Cover")
 
                 ToolTip.visible: infoColumn.width < infoColumn.implicitWidth
-                                 && (artworkInfoItem.hovered || artworkInfoItem.visualFocus)
+                                 && (root.hovered || root.visualFocus)
                 ToolTip.delay: VLCStyle.delayToolTipAppear
                 ToolTip.text: I18n.qtr("%1\n%2\n%3").arg(titleLabel.text)
                                                     .arg(artistLabel.text)
@@ -184,7 +196,7 @@ AbstractButton {
                 Layout.fillWidth: true
                 Layout.fillHeight: true
 
-                visible: (infoColumn.height >= artworkInfoItem._preferredHeight)
+                visible: (infoColumn.height >= root._preferredHeight)
 
                 text: {
                     if (paintOnly)


=====================================
modules/gui/qt/player/qml/controlbarcontrols/PlayButton.qml
=====================================
@@ -15,6 +15,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
+
 import QtQuick 2.12
 import QtQuick.Templates 2.12 as T
 
@@ -24,25 +25,41 @@ import "qrc:///widgets/" as Widgets
 import "qrc:///style/"
 import "qrc:///util/Helpers.js" as Helpers
 
-
 T.Control {
-    id: playBtn
-
-    implicitWidth: implicitHeight
+    id: root
 
-    implicitHeight: Math.min(VLCStyle.icon_medium, maximumHeight)
-
-    scale: (_keyOkPressed || (mouseArea.pressed && cursorInside)) ? 0.95
-                                                                  : 1.00
+    // Properties
 
     property int maximumHeight: VLCStyle.icon_medium
 
     property bool paintOnly: false
 
+    readonly property ColorContext colorContext: ColorContext {
+        id: theme
+
+        colorSet: ColorContext.ToolButton
+
+        enabled: root.enabled || root.paintOnly
+        focused: root.activeFocus
+        hovered: root.cursorInside
+        pressed: mouseArea.containsPress
+    }
+
     property bool _keyOkPressed: false
 
+    // Aliases
+
     property alias cursorInside: mouseArea.cursorInside
 
+    // Settings
+
+    implicitWidth: implicitHeight
+
+    implicitHeight: Math.min(VLCStyle.icon_medium, maximumHeight)
+
+    scale: (_keyOkPressed || (mouseArea.pressed && cursorInside)) ? 0.95
+                                                                  : 1.00
+
     Accessible.role: Accessible.Button
     Accessible.name: I18n.qtr("Play/Pause")
     Accessible.checkable: true
@@ -51,6 +68,51 @@ T.Control {
     Accessible.onPressAction: mainPlaylistController.togglePlayPause()
     Accessible.onToggleAction: mainPlaylistController.togglePlayPause()
 
+    // States
+
+    states: [
+        State {
+            name: "focused"
+            when: visualFocus
+
+            PropertyChanges {
+                target: hoverShadow
+                opacity: 0.0
+            }
+
+            PropertyChanges {
+                target: focusShadow
+                opacity: 1.0
+            }
+        },
+        State {
+            name: "hover"
+            when: cursorInside
+
+            PropertyChanges {
+                target: hoverShadow
+                opacity: 1.0
+            }
+
+            PropertyChanges {
+                target: focusShadow
+                opacity: 0.0
+            }
+        }
+    ]
+
+    transitions: Transition {
+        from: ""; to: "*"
+        reversible: true
+        NumberAnimation {
+            properties: "opacity"
+            easing.type: Easing.InOutSine
+            duration: VLCStyle.duration_veryShort
+        }
+    }
+
+    // Keys
+
     Keys.onPressed: {
         if (KeyHelper.matchOk(event) ) {
             if (!event.isAutoRepeat) {
@@ -74,20 +136,14 @@ T.Control {
         }
     }
 
+    // Functions
+
     function _pressAndHoldAction() {
         _keyOkPressed = false
         mainPlaylistController.stop()
     }
 
-    readonly property ColorContext colorContext: ColorContext {
-        id: theme
-        colorSet: ColorContext.ToolButton
-
-        enabled: playBtn.enabled || playBtn.paintOnly
-        focused: playBtn.activeFocus
-        hovered: playBtn.cursorInside
-        pressed: mouseArea.containsPress
-    }
+    // Children
 
     Timer {
         id: keyHoldTimer
@@ -126,7 +182,7 @@ T.Control {
                 return
             }
 
-            playBtn.forceActiveFocus(Qt.MouseFocusReason)
+            root.forceActiveFocus(Qt.MouseFocusReason)
         }
 
         onClicked: {
@@ -140,47 +196,6 @@ T.Control {
         }
     }
 
-    states: [
-        State {
-            name: "focused"
-            when: visualFocus
-
-            PropertyChanges {
-                target: hoverShadow
-                opacity: 0.0
-            }
-
-            PropertyChanges {
-                target: focusShadow
-                opacity: 1.0
-            }
-        },
-        State {
-            name: "hover"
-            when: cursorInside
-
-            PropertyChanges {
-                target: hoverShadow
-                opacity: 1.0
-            }
-
-            PropertyChanges {
-                target: focusShadow
-                opacity: 0.0
-            }
-        }
-    ]
-
-    transitions: Transition {
-        from: ""; to: "*"
-        reversible: true
-        NumberAnimation {
-            properties: "opacity"
-            easing.type: Easing.InOutSine
-            duration: VLCStyle.duration_veryShort
-        }
-    }
-
     contentItem: T.Label {
         text: {
             var state = Player.playingState



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/185d8522afa716cc7c7677715b63447d8f1c58aa...9d6c7e1cd1eea35ec33e44838d53f0db4054d10c

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/185d8522afa716cc7c7677715b63447d8f1c58aa...9d6c7e1cd1eea35ec33e44838d53f0db4054d10c
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