[vlc-commits] qml: new sizing policy for aligned controlbar
Fatih Uzunoglu
git at videolan.org
Mon Dec 7 10:08:25 UTC 2020
vlc | branch: master | Fatih Uzunoglu <fuzun54 at outlook.com> | Fri Dec 4 02:01:44 2020 +0300| [b209afe21f2252b857cac234b0711eb6830edf5b] | committer: Pierre Lamot
qml: new sizing policy for aligned controlbar
Signed-off-by: Pierre Lamot <pierre at videolabs.io>
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b209afe21f2252b857cac234b0711eb6830edf5b
---
modules/gui/qt/player/qml/ButtonsLayout.qml | 28 +++++++++++++--
modules/gui/qt/player/qml/ControlButtons.qml | 20 ++++++++---
modules/gui/qt/player/qml/PlayerButtonsLayout.qml | 42 ++++++++++++-----------
3 files changed, 64 insertions(+), 26 deletions(-)
diff --git a/modules/gui/qt/player/qml/ButtonsLayout.qml b/modules/gui/qt/player/qml/ButtonsLayout.qml
index b3a596b167..02fdc4b8f0 100644
--- a/modules/gui/qt/player/qml/ButtonsLayout.qml
+++ b/modules/gui/qt/player/qml/ButtonsLayout.qml
@@ -32,6 +32,10 @@ Widgets.NavigableFocusScope {
property var defaultSize: VLCStyle.icon_normal
property bool forceColors: false
+ property real minimumWidth: 0
+ property real extraWidth: undefined
+ property int expandableCount: 0 // widget count that can expand when extra width is available
+
implicitWidth: buttonrow.implicitWidth
implicitHeight: buttonrow.implicitHeight
@@ -63,13 +67,21 @@ Widgets.NavigableFocusScope {
if (item.focus) {
buttonrow._focusGiven = false
}
+
+ if (item.item.extraWidth !== undefined)
+ buttonsLayout.expandableCount--
+
+ if (item.item.minimumWidth !== undefined)
+ buttonsLayout.minimumWidth -= item.item.minimumWidth + buttonrow.spacing
+ else
+ buttonsLayout.minimumWidth -= item.item.width + buttonrow.spacing
}
delegate: Loader {
id: buttonloader
- sourceComponent: controlmodelbuttons.returnbuttondelegate(
- model.id)
+ sourceComponent: controlmodelbuttons.returnbuttondelegate(model.id)
+
onLoaded: {
if (!buttonrow._focusGiven) {
buttonloader.focus = true
@@ -103,6 +115,18 @@ Widgets.NavigableFocusScope {
if (buttonloader.item.navigationLeft !== undefined)
buttonloader.item.navigationLeft = buttonsLayout.navigationLeft
+
+ if (buttonloader.item.minimumWidth !== undefined)
+ buttonsLayout.minimumWidth += buttonloader.item.minimumWidth + buttonrow.spacing
+ else
+ buttonsLayout.minimumWidth += buttonloader.item.width + buttonrow.spacing
+
+ if (buttonloader.item.extraWidth !== undefined && buttonsLayout.extraWidth !== undefined) {
+ buttonsLayout.expandableCount++
+ buttonloader.item.extraWidth = Qt.binding( function() {
+ return (buttonsLayout.extraWidth / buttonsLayout.expandableCount) // distribute extra width
+ } )
+ }
}
}
}
diff --git a/modules/gui/qt/player/qml/ControlButtons.qml b/modules/gui/qt/player/qml/ControlButtons.qml
index f0f8b36bbd..2fb56926ea 100644
--- a/modules/gui/qt/player/qml/ControlButtons.qml
+++ b/modules/gui/qt/player/qml/ControlButtons.qml
@@ -781,7 +781,11 @@ Item{
property bool paintOnly: false
property VLCColors _colors: VLCStyle.colors
- implicitWidth: playingItemInfoRow.implicitWidth
+ readonly property real minimumWidth: cover.width
+ property real extraWidth: 0
+
+ implicitWidth: paintOnly ? playingItemInfoRow.implicitWidth : (minimumWidth + extraWidth)
+
implicitHeight: playingItemInfoRow.implicitHeight
Keys.onPressed: {
@@ -847,7 +851,9 @@ Item{
anchors.verticalCenter: parent.verticalCenter
leftPadding: VLCStyle.margin_xsmall
- width: implicitWidth + VLCStyle.margin_xsmall
+ width: (implicitWidth + VLCStyle.margin_xsmall)
+
+ visible: paintOnly || artworkInfoItem.extraWidth > 0
ToolTip {
text: i18n.qtr("%1\n%2").arg(titleLabel.text).arg(artistLabel.text)
@@ -867,10 +873,12 @@ Item{
Widgets.MenuLabel {
id: titleLabel
+
width: {
if (!paintOnly)
- implicitWidth < VLCStyle.artworkInfoTextWidth ? implicitWidth : VLCStyle.artworkInfoTextWidth
+ artworkInfoItem.implicitWidth - titleLabel.mapToItem(artworkInfoItem, titleLabel.x, titleLabel.y).x
}
+
text: {
if (paintOnly)
i18n.qtr("Title")
@@ -885,7 +893,7 @@ Item{
id: artistLabel
width: {
if (!paintOnly)
- implicitWidth < VLCStyle.artworkInfoTextWidth ? implicitWidth : VLCStyle.artworkInfoTextWidth
+ artworkInfoItem.implicitWidth - artistLabel.mapToItem(artworkInfoItem, artistLabel.x, artistLabel.y).x
}
text: {
if (paintOnly)
@@ -899,6 +907,10 @@ Item{
Widgets.MenuCaption {
id: progressIndicator
+ width: {
+ if (!paintOnly)
+ artworkInfoItem.implicitWidth - progressIndicator.mapToItem(artworkInfoItem, progressIndicator.x, progressIndicator.y).x
+ }
text: {
if (paintOnly)
" -- / -- "
diff --git a/modules/gui/qt/player/qml/PlayerButtonsLayout.qml b/modules/gui/qt/player/qml/PlayerButtonsLayout.qml
index 1ec7c20a14..087bd7c4ff 100644
--- a/modules/gui/qt/player/qml/PlayerButtonsLayout.qml
+++ b/modules/gui/qt/player/qml/PlayerButtonsLayout.qml
@@ -26,8 +26,7 @@ import "qrc:///widgets/" as Widgets
Widgets.NavigableFocusScope {
id: playerButtonsLayout
- implicitHeight: childrenRect.height
- implicitWidth: childrenRect.width
+ implicitHeight: Math.max(buttonrow_left.implicitHeight, buttonrow_center.implicitHeight, buttonrow_right.implicitHeight)
property alias isMiniplayer: controlmodelbuttons.isMiniplayer
property alias parentWindow: controlmodelbuttons.parentWindow
@@ -39,15 +38,21 @@ Widgets.NavigableFocusScope {
property bool forceColors: false
- property var models: [] // 0: left, 1: center, 2: right
+ enum Alignment {
+ Left = 0,
+ Center = 1,
+ Right = 2
+ }
+
+ property var models: []
Connections {
target: mainInterface
onToolBarConfUpdated: {
- models[0].reloadModel()
- models[1].reloadModel()
- models[2].reloadModel()
+ models[PlayerButtonsLayout.Alignment.Left].reloadModel()
+ models[PlayerButtonsLayout.Alignment.Center].reloadModel()
+ models[PlayerButtonsLayout.Alignment.Right].reloadModel()
}
}
@@ -61,24 +66,22 @@ Widgets.NavigableFocusScope {
ButtonsLayout {
id: buttonrow_left
- model: models[0]
+ model: models[PlayerButtonsLayout.Alignment.Left]
- implicitHeight: buttonrow.implicitHeight
+ extraWidth: (buttonrow_center.x - buttonrow_left.x - minimumWidth)
anchors {
left: parent.left
- top: parent.top
- bottom: parent.bottom
+ verticalCenter: parent.verticalCenter
leftMargin: playerButtonsLayout.marginLeft
-
topMargin: playerButtonsLayout.marginTop
bottomMargin: playerButtonsLayout.marginBottom
}
forceColors: playerButtonsLayout.forceColors
- visible: model.count > 0 && (buttonrow_center.model.count > 0 ? ((x+width) < buttonrow_center.x) : true)
+ visible: extraWidth < 0 ? false : true // extraWidth < 0 means there is not even available space for minimumSize
navigationParent: playerButtonsLayout
navigationRightItem: buttonrow_center
@@ -89,7 +92,7 @@ Widgets.NavigableFocusScope {
ButtonsLayout {
id: buttonrow_center
- model: models[1]
+ model: models[PlayerButtonsLayout.Alignment.Center]
anchors {
centerIn: parent
@@ -108,23 +111,22 @@ Widgets.NavigableFocusScope {
ButtonsLayout {
id: buttonrow_right
- model: models[2]
+ model: models[PlayerButtonsLayout.Alignment.Right]
+
+ extraWidth: (playerButtonsLayout.width - (buttonrow_center.x + buttonrow_center.width) - minimumWidth)
anchors {
right: parent.right
- top: parent.top
- bottom: parent.bottom
+ verticalCenter: parent.verticalCenter
rightMargin: playerButtonsLayout.marginRight
-
topMargin: playerButtonsLayout.marginTop
bottomMargin: playerButtonsLayout.marginBottom
}
forceColors: playerButtonsLayout.forceColors
-
- visible: model.count > 0 && (buttonrow_center.model.count > 0 ? ((buttonrow_center.x + buttonrow_center.width) < x)
- : !(((buttonrow_left.x + buttonrow_left.width) > x) && buttonrow_center.left.count > 0))
+
+ visible: extraWidth < 0 ? false : true // extraWidth < 0 means there is not even available space for minimumSize
navigationParent: playerButtonsLayout
navigationLeftItem: buttonrow_center
More information about the vlc-commits
mailing list