qml: simplify logic in MiniPlayer.qml

This commit is contained in:
Fatih Uzunoglu 2024-03-11 18:17:08 +02:00 committed by Jean-Baptiste Kempf
parent 9f9339427b
commit 4ef63e2aca
1 changed files with 18 additions and 21 deletions

View File

@ -25,17 +25,9 @@ import "qrc:///style/"
ControlBar { ControlBar {
id: root id: root
// Binding evaluation order: visible: animation.running || (state === "inViewport")
// state -> implicitHeight OR visible -> anchors.bottomMargin
// Care must be taken to not cause binding loops. anchors.bottomMargin: (state === "outViewport") ? -_delayedImplicitHeight : 0
visible: {
if (state === "inViewport")
return true
else if ((anchors.bottomMargin + implicitHeight) > Number.EPSILON)
return true
else
return false
}
state: (Player.playingState === Player.PLAYING_STATE_STOPPED) ? "outViewport" state: (Player.playingState === Player.PLAYING_STATE_STOPPED) ? "outViewport"
: "inViewport" : "inViewport"
@ -51,29 +43,34 @@ ControlBar {
identifier: PlayerControlbarModel.Miniplayer identifier: PlayerControlbarModel.Miniplayer
property real _delayedImplicitHeight
onImplicitHeightChanged: { onImplicitHeightChanged: {
// Animation should not be based on the implicit height change if (!animation.running) {
// but rather the visibility state: // Animation should not be based on the implicit height change
behavior.enabled = false // but rather the visibility state:
Qt.callLater(() => { behavior.enabled = true }) behavior.enabled = false
Qt.callLater(() => { behavior.enabled = true })
}
} }
BindingCompat on anchors.bottomMargin { BindingCompat on _delayedImplicitHeight {
id: binding
// eliminate intermediate adjustments until implicit height is calculated fully // eliminate intermediate adjustments until implicit height is calculated fully
// we can not delay on component load because we do not want twitching // we can not delay on component load because we do not want twitching
// NOTE: The delay here can be removed, as long as a direct height is set // NOTE: The delay here can be removed, as long as a direct height is set
// for the whole control instead of implicit height. // for the whole control instead of implicit height.
delayed: behavior.enabled delayed: behavior.enabled
value: root.implicitHeight
value: (root.state === "outViewport") ? -root.implicitHeight : 0
} }
Behavior on anchors.bottomMargin { Behavior on anchors.bottomMargin {
id: behavior id: behavior
enabled: false enabled: false
NumberAnimation { easing.type: Easing.InOutSine; duration: VLCStyle.duration_long; } NumberAnimation {
id: animation
easing.type: Easing.InOutSine
duration: VLCStyle.duration_long
}
} }
} }