fix: animate nexus wallpaper preview

This commit is contained in:
2 * r + 2 * t 2026-06-05 01:01:43 +10:00
parent 45c6c03c79
commit 68317ecf67
2 changed files with 46 additions and 17 deletions

View file

@ -6,10 +6,15 @@ Image {
id: root id: root
property bool hadPrevious property bool hadPrevious
property bool fadingOut
property bool preventInit
property int fadeOutAnim: Anim.FastEffects
property int fadeInAnim: Anim.DefaultEffects
property int fadeInLargeAnim: Anim.StandardLarge
function maybeStartInAnim(): void { function maybeStartInAnim(): void {
if (!opacityInAnim.running && status === Image.Ready) { if (!preventInit && !opacityInAnim.running && status === Image.Ready) {
opacityInAnim.type = hadPrevious ? Anim.DefaultEffects : Anim.StandardLarge; opacityInAnim.type = hadPrevious ? fadeInAnim : fadeInLargeAnim;
opacityInAnim.start(); opacityInAnim.start();
} }
} }
@ -26,6 +31,7 @@ Image {
opacity: 0 opacity: 0
onStatusChanged: maybeStartInAnim() onStatusChanged: maybeStartInAnim()
onPreventInitChanged: maybeStartInAnim()
Anim on opacity { Anim on opacity {
id: opacityInAnim id: opacityInAnim
@ -36,11 +42,24 @@ Image {
Behavior on source { Behavior on source {
SequentialAnimation { SequentialAnimation {
ScriptAction {
script: opacityInAnim.stop()
}
PropertyAction {
target: root
property: "fadingOut"
value: true
}
Anim { Anim {
target: root target: root
property: "opacity" property: "opacity"
to: 0 to: 0
type: Anim.FastEffects type: root.fadeOutAnim
}
PropertyAction {
target: root
property: "fadingOut"
value: false
} }
PropertyAction { PropertyAction {
target: root target: root

View file

@ -7,6 +7,7 @@ import Caelestia.Components
import Caelestia.Config import Caelestia.Config
import qs.components import qs.components
import qs.components.controls import qs.components.controls
import qs.components.images
import qs.services import qs.services
import qs.modules.nexus import qs.modules.nexus
import qs.modules.nexus.common import qs.modules.nexus.common
@ -43,9 +44,11 @@ ColumnLayout {
radius: Tokens.rounding.large radius: Tokens.rounding.large
Loader { Loader {
id: wallIndicatorLoader
anchors.centerIn: parent anchors.centerIn: parent
opacity: wallImg.status === Image.Ready ? 0 : 1 opacity: 0
active: opacity > 0 active: opacity > 0
sourceComponent: StyledRect { sourceComponent: StyledRect {
@ -60,7 +63,7 @@ ColumnLayout {
anchors.centerIn: parent anchors.centerIn: parent
containsIcon: true containsIcon: true
implicitSize: wallWrapper.implicitHeight * 0.4 implicitSize: Math.min(wallWrapper.implicitWidth, wallWrapper.implicitHeight) * 0.4
} }
} }
@ -71,24 +74,31 @@ ColumnLayout {
} }
} }
Image { Timer {
id: wallLoadDebounceTimer
interval: 100
onTriggered: {
if (wallImg.status !== Image.Ready)
wallIndicatorLoader.opacity = 1;
}
}
FadeImage {
id: wallImg id: wallImg
anchors.fill: parent anchors.fill: parent
source: Wallpapers.current source: Wallpapers.current
asynchronous: true preventInit: wallIndicatorLoader.opacity > 0
fillMode: Image.PreserveAspectCrop fadeOutAnim: Anim.DefaultEffects
sourceSize: { fadeInAnim: Anim.SlowEffects
const dpr = (QsWindow.window as QsWindow)?.devicePixelRatio ?? 1;
return Qt.size(width * dpr, height * dpr);
}
retainWhileLoading: true onSourceChanged: wallLoadDebounceTimer.restart()
opacity: status === Image.Ready ? 1 : 0
Behavior on opacity { onStatusChanged: {
Anim { if (status === Image.Ready) {
type: Anim.SlowEffects wallLoadDebounceTimer.stop();
wallIndicatorLoader.opacity = 0;
} }
} }
} }