From 9a813f827feee7eb4a6036f7be64e3208bdf89bc Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 5 May 2025 16:26:38 +1000 Subject: feat: wallpaper --- modules/background/Background.qml | 2 ++ modules/background/Wallpaper.qml | 75 +++++++++++++++++++++++++++++++++++++++ services/Wallpapers.qml | 14 ++++++++ 3 files changed, 91 insertions(+) create mode 100644 modules/background/Wallpaper.qml diff --git a/modules/background/Background.qml b/modules/background/Background.qml index 7a46c72..2dda9fb 100644 --- a/modules/background/Background.qml +++ b/modules/background/Background.qml @@ -26,6 +26,8 @@ Variants { anchors.bottom: true anchors.left: true anchors.right: true + + Wallpaper {} } } } diff --git a/modules/background/Wallpaper.qml b/modules/background/Wallpaper.qml new file mode 100644 index 0000000..80848d5 --- /dev/null +++ b/modules/background/Wallpaper.qml @@ -0,0 +1,75 @@ +pragma ComponentBehavior: Bound + +import "root:/widgets" +import "root:/services" +import "root:/config" +import QtQuick + +Item { + id: root + + property url source: Wallpapers.current ? `file://${Wallpapers.current}` : "" + property Image current: one + + anchors.fill: parent + + onSourceChanged: { + if (current === one) + two.update(); + else + one.update(); + } + + Img { + id: one + } + + Img { + id: two + } + + component Img: Image { + id: img + + function update(): void { + if (source === root.source) + root.current = this; + else + source = root.source; + } + + anchors.fill: parent + asynchronous: true + fillMode: Image.PreserveAspectCrop + opacity: 0 + scale: 0.8 + + onStatusChanged: { + if (status === Image.Ready) + root.current = this; + } + + states: State { + name: "visible" + when: root.current === img + + PropertyChanges { + img.opacity: 1 + img.scale: 1 + } + } + + transitions: Transition { + from: "*" + to: "*" + + NumberAnimation { + target: img + properties: "opacity,scale" + duration: Appearance.anim.durations.normal + easing.type: Easing.BezierSpline + easing.bezierCurve: Appearance.anim.curves.standard + } + } + } +} diff --git a/services/Wallpapers.qml b/services/Wallpapers.qml index 7e9a576..8e98e32 100644 --- a/services/Wallpapers.qml +++ b/services/Wallpapers.qml @@ -9,9 +9,14 @@ import Qt.labs.platform Singleton { id: root + readonly property string currentPath: `${StandardPaths.standardLocations(StandardPaths.GenericStateLocation)[0]}/caelestia/wallpaper/last.txt`.slice(7) readonly property string path: `${StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]}/Wallpapers`.slice(7) property list list + property bool showPreview: false + readonly property string current: showPreview ? preview : actualCurrent + property string preview + property string actualCurrent readonly property list preppedWalls: list.map(w => ({ name: Fuzzy.prepare(w.name), @@ -32,6 +37,15 @@ Singleton { setWall.startDetached(); } + reloadableId: "wallpapers" + + FileView { + path: root.currentPath + watchChanges: true + onFileChanged: reload() + onLoaded: root.actualCurrent = text().trim() + } + Process { id: setWall -- cgit v1.2.3-freya