[vlc-commits] [Git][videolan/vlc][master] 4 commits: qml/ControlLayout: Code cleanup
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sun Apr 2 07:02:48 UTC 2023
Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC
Commits:
00058ecc by Benjamin Arnaud at 2023-04-02T06:37:47+00:00
qml/ControlLayout: Code cleanup
No functionnal changes
- - - - -
dce53de9 by Benjamin Arnaud at 2023-04-02T06:37:47+00:00
qml/ControlLayout: Ensure 'item(s)' are valid
- - - - -
9476171d by Benjamin Arnaud at 2023-04-02T06:37:47+00:00
qml/ControlLayout: Code cleanup
No functional changes
- - - - -
8909317b by Benjamin Arnaud at 2023-04-02T06:37:47+00:00
qml/PlayerControlLayout: Code cleanup
No functional changes
- - - - -
2 changed files:
- modules/gui/qt/player/qml/ControlLayout.qml
- modules/gui/qt/player/qml/PlayerControlLayout.qml
Changes:
=====================================
modules/gui/qt/player/qml/ControlLayout.qml
=====================================
@@ -30,43 +30,69 @@ import "qrc:///widgets/" as Widgets
FocusScope {
id: controlLayout
- signal requestLockUnlockAutoHide(bool lock)
-
- property alias model: repeater.model
+ // Properties
readonly property real minimumWidth: {
- var minimumWidth = 0
var count = repeater.count
+ if (count === 0)
+ return 0
+
+ var size = 0
+
for (var i = 0; i < count; ++i) {
var item = repeater.itemAt(i)
- if (item.minimumWidth !== undefined)
- minimumWidth += item.minimumWidth
+ if (item.minimumWidth === undefined)
+ size += item.implicitWidth
else
- minimumWidth += item.implicitWidth
+ size += item.minimumWidth
}
- minimumWidth += ((count - 1) * playerControlLayout.spacing)
-
- return minimumWidth
+ return size + ((count - 1) * playerControlLayout.spacing)
}
property bool rightAligned: false
+ property var altFocusAction: Navigation.defaultNavigationUp
+
+ readonly property ColorContext colorContext: ColorContext {
+ id: theme
+ colorSet: ColorContext.Window
+ }
+
+ // Aliases
+
+ property alias model: repeater.model
+
+ // Signals
+
+ signal requestLockUnlockAutoHide(bool lock)
+
+ // Settings
+
+ implicitWidth: minimumWidth
+ implicitHeight: rowLayout.implicitHeight
+
Navigation.navigable: {
for (var i = 0; i < repeater.count; ++i) {
- if (repeater.itemAt(i).item.focus) {
+ var item = repeater.itemAt(i).item
+
+ if (item && item.focus) {
return true
}
}
return false
}
- implicitWidth: minimumWidth
- implicitHeight: rowLayout.implicitHeight
+ // Events
- property var altFocusAction: Navigation.defaultNavigationUp
+ Component.onCompleted: {
+ visibleChanged.connect(_handleFocus)
+ activeFocusChanged.connect(_handleFocus)
+ }
+
+ // Functions
function _handleFocus() {
if (typeof activeFocus === "undefined")
@@ -76,15 +102,7 @@ FocusScope {
altFocusAction()
}
- Component.onCompleted: {
- visibleChanged.connect(_handleFocus)
- activeFocusChanged.connect(_handleFocus)
- }
-
- readonly property ColorContext colorContext: ColorContext {
- id: theme
- colorSet: ColorContext.Window
- }
+ // Children
RowLayout {
id: rowLayout
@@ -113,17 +131,33 @@ FocusScope {
delegate: Loader {
id: loader
+ // Properties
+
+ property int minimumWidth: {
+ if (expandable)
+ return item.minimumWidth
+ else if (item)
+ return item.implicitWidth
+ else
+ return 0
+ }
+
+ readonly property bool expandable: (item && item.minimumWidth !== undefined)
+
+ // Settings
+
source: PlayerControlbarControls.control(model.id).source
focus: (index === 0)
- Layout.alignment: Qt.AlignVCenter | (rightAligned ? Qt.AlignRight : Qt.AlignLeft)
- Layout.minimumWidth: minimumWidth
Layout.fillWidth: expandable
- Layout.maximumWidth: item.implicitWidth
- readonly property real minimumWidth: (expandable ? item.minimumWidth : item.implicitWidth)
- readonly property bool expandable: (item.minimumWidth !== undefined)
+ Layout.minimumWidth: minimumWidth
+
+ // NOTE: -1 resets to the implicit maximum width.
+ Layout.maximumWidth: (item) ? item.implicitWidth : -1
+
+ Layout.alignment: Qt.AlignVCenter | (rightAligned ? Qt.AlignRight : Qt.AlignLeft)
BindingCompat {
delayed: true // this is important
@@ -132,6 +166,8 @@ FocusScope {
value: (loader.x + minimumWidth <= rowLayout.width)
}
+ // Events
+
Component.onCompleted: repeater.countChanged.connect(controlLayout._handleFocus)
onActiveFocusChanged: {
@@ -140,22 +176,6 @@ FocusScope {
}
}
- Connections {
- target: item
-
- enabled: loader.status === Loader.Ready
-
- onEnabledChanged: {
- if (activeFocus && !item.enabled) // Loader has focus but item is not enabled
- recoverFocus()
- }
-
- onVisibleChanged: {
- if (activeFocus && !item.visible)
- recoverFocus()
- }
- }
-
onLoaded: {
// control should not request focus if they are not enabled:
item.focus = Qt.binding(function() { return item.enabled && item.visible })
@@ -182,28 +202,58 @@ FocusScope {
}
}
+ // Connections
+
+ Connections {
+ target: item
+
+ enabled: loader.status === Loader.Ready
+
+ onEnabledChanged: {
+ if (activeFocus && !item.enabled) // Loader has focus but item is not enabled
+ recoverFocus()
+ }
+
+ onVisibleChanged: {
+ if (activeFocus && !item.visible)
+ recoverFocus()
+ }
+ }
+
+ // Functions
+
function applyNavigation() {
+ if (item == null) return
+
var itemLeft = repeater.itemAt(index - 1)
var itemRight = repeater.itemAt(index + 1)
if (itemLeft) {
- var componentLeft = itemLeft.item;
+ var componentLeft = itemLeft.item
- item.Navigation.leftItem = componentLeft
+ if (componentLeft)
+ {
+ item.Navigation.leftItem = componentLeft
- componentLeft.Navigation.rightItem = item
+ componentLeft.Navigation.rightItem = item
+ }
}
if (itemRight) {
- var componentRight = itemRight.item;
+ var componentRight = itemRight.item
- item.Navigation.rightItem = componentRight
+ if (componentRight)
+ {
+ item.Navigation.rightItem = componentRight
- componentRight.Navigation.leftItem = item
+ componentRight.Navigation.leftItem = item
+ }
}
}
function removeNavigation() {
+ if (item == null) return
+
var itemLeft = repeater.itemAt(index - 1)
// NOTE: The current item was removed from the repeater so we test against the
@@ -223,21 +273,9 @@ FocusScope {
}
}
- function _focusIfFocusable(_loader) {
- if (!!_loader && !!_loader.item && _loader.item.focus) {
- if (item.focusReason !== undefined)
- _loader.item.forceActiveFocus(item.focusReason)
- else {
- console.warn("focusReason is not available in %1!".arg(item))
- _loader.item.forceActiveFocus()
- }
- return true
- } else {
- return false
- }
- }
-
function recoverFocus(_index) {
+ if (item == null) return
+
if (!controlLayout.visible)
return
@@ -270,6 +308,22 @@ FocusScope {
controlLayout.altFocusAction()
}
}
+
+ // Private
+
+ function _focusIfFocusable(_loader) {
+ if (!!_loader && !!_loader.item && _loader.item.focus) {
+ if (item.focusReason !== undefined)
+ _loader.item.forceActiveFocus(item.focusReason)
+ else {
+ console.warn("focusReason is not available in %1!".arg(item))
+ _loader.item.forceActiveFocus()
+ }
+ return true
+ } else {
+ return false
+ }
+ }
}
}
=====================================
modules/gui/qt/player/qml/PlayerControlLayout.qml
=====================================
@@ -26,26 +26,21 @@ import "qrc:///widgets/" as Widgets
FocusScope {
id: playerControlLayout
- implicitWidth: layoutLoader_left.implicitWidth + layoutLoader_center.implicitWidth + layoutLoader_right.implicitWidth + 2 * layoutSpacing
- implicitHeight: VLCStyle.maxControlbarControlHeight
+ // Properties
property real defaultSize: VLCStyle.icon_normal // default size for IconToolButton based controls
property real spacing: VLCStyle.margin_normal // spacing between controls
+
property real layoutSpacing: VLCStyle.margin_xxlarge // spacing between layouts (left, center, and right)
property int identifier: -1
+
readonly property PlayerControlbarModel model: {
if (!!MainCtx.controlbarProfileModel.currentModel)
- MainCtx.controlbarProfileModel.currentModel.getModel(identifier)
+ return MainCtx.controlbarProfileModel.currentModel.getModel(identifier)
else
- null
- }
-
- signal requestLockUnlockAutoHide(bool lock)
-
- Component.onCompleted: {
- console.assert(identifier >= 0)
+ return null
}
readonly property ColorContext colorContext: ColorContext {
@@ -53,11 +48,28 @@ FocusScope {
colorSet: ColorContext.Window
}
+ // Signals
+
+ signal requestLockUnlockAutoHide(bool lock)
+
+ // Settings
+
+ implicitWidth: loaderLeft.implicitWidth + loaderCenter.implicitWidth
+ + loaderRight.implicitWidth + 2 * layoutSpacing
+
+ implicitHeight: VLCStyle.maxControlbarControlHeight
+
+ // Events
+
+ Component.onCompleted: console.assert(identifier >= 0)
+
+ // Children
+
Loader {
- id: layoutLoader_left
+ id: loaderLeft
anchors {
- right: layoutLoader_center.left
+ right: loaderCenter.left
left: parent.left
top: parent.top
bottom: parent.bottom
@@ -66,8 +78,7 @@ FocusScope {
rightMargin: layoutSpacing - spacing
}
- active: !!playerControlLayout.model
- && !!playerControlLayout.model.left
+ active: !!playerControlLayout.model && !!playerControlLayout.model.left
focus: true
@@ -79,19 +90,19 @@ FocusScope {
ctx: MainCtx
}
- Navigation.parentItem: playerControlLayout
- Navigation.rightItem: layoutLoader_center.item
-
focus: true
altFocusAction: Navigation.defaultNavigationRight
+ Navigation.parentItem: playerControlLayout
+ Navigation.rightItem: loaderCenter.item
+
onRequestLockUnlockAutoHide: playerControlLayout.requestLockUnlockAutoHide(lock)
}
}
Loader {
- id: layoutLoader_center
+ id: loaderCenter
anchors {
horizontalCenter: parent.horizontalCenter
@@ -99,8 +110,7 @@ FocusScope {
bottom: parent.bottom
}
- active: !!playerControlLayout.model
- && !!playerControlLayout.model.center
+ active: !!playerControlLayout.model && !!playerControlLayout.model.center
width: (parent.width < implicitWidth) ? parent.width
: implicitWidth
@@ -113,23 +123,23 @@ FocusScope {
ctx: MainCtx
}
- Navigation.parentItem: playerControlLayout
- Navigation.leftItem: layoutLoader_left.item
- Navigation.rightItem: layoutLoader_right.item
-
focus: true
altFocusAction: Navigation.defaultNavigationUp
+ Navigation.parentItem: playerControlLayout
+ Navigation.leftItem: loaderLeft.item
+ Navigation.rightItem: loaderRight.item
+
onRequestLockUnlockAutoHide: playerControlLayout.requestLockUnlockAutoHide(lock)
}
}
Loader {
- id: layoutLoader_right
+ id: loaderRight
anchors {
- left: layoutLoader_center.right
+ left: loaderCenter.right
right: parent.right
top: parent.top
bottom: parent.bottom
@@ -138,8 +148,7 @@ FocusScope {
leftMargin: layoutSpacing - spacing
}
- active: !!playerControlLayout.model
- && !!playerControlLayout.model.right
+ active: !!playerControlLayout.model && !!playerControlLayout.model.right
sourceComponent: ControlLayout {
model: ControlListFilter {
@@ -151,13 +160,13 @@ FocusScope {
rightAligned: true
- Navigation.parentItem: playerControlLayout
- Navigation.leftItem: layoutLoader_center.item
-
focus: true
altFocusAction: Navigation.defaultNavigationLeft
+ Navigation.parentItem: playerControlLayout
+ Navigation.leftItem: loaderCenter.item
+
onRequestLockUnlockAutoHide: playerControlLayout.requestLockUnlockAutoHide(lock)
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6e1902417d5727d6cc65e0a00977e13b2a95059d...8909317baf97ab643cc4cfbc5e3d0275d555b742
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6e1902417d5727d6cc65e0a00977e13b2a95059d...8909317baf97ab643cc4cfbc5e3d0275d555b742
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