From 97ea9d49929b223036e96388c66d700ea731d6db Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 5 May 2025 17:06:12 +1000 Subject: feat: wallpaper and colour preview --- modules/background/Wallpaper.qml | 2 +- modules/launcher/WallpaperList.qml | 6 ++++++ services/Colours.qml | 4 ++-- services/Wallpapers.qml | 33 +++++++++++++++++++++++++++++---- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/modules/background/Wallpaper.qml b/modules/background/Wallpaper.qml index 80848d5..b126617 100644 --- a/modules/background/Wallpaper.qml +++ b/modules/background/Wallpaper.qml @@ -42,7 +42,7 @@ Item { asynchronous: true fillMode: Image.PreserveAspectCrop opacity: 0 - scale: 0.8 + scale: Wallpapers.showPreview ? 1 : 0.8 onStatusChanged: { if (status === Image.Ready) diff --git a/modules/launcher/WallpaperList.qml b/modules/launcher/WallpaperList.qml index 9582957..430964e 100644 --- a/modules/launcher/WallpaperList.qml +++ b/modules/launcher/WallpaperList.qml @@ -24,6 +24,12 @@ PathView { } Component.onCompleted: currentIndex = Wallpapers.list.findIndex(w => w.path === Wallpapers.current) + Component.onDestruction: Wallpapers.stopPreview() + + onCurrentItemChanged: { + if (currentItem) + Wallpapers.preview(currentItem.modelData.path); + } implicitWidth: Math.min(LauncherConfig.maxWallpapers, count) * (LauncherConfig.sizes.wallpaperWidth * 0.8 + Appearance.padding.larger * 2) pathItemCount: LauncherConfig.maxWallpapers diff --git a/services/Colours.qml b/services/Colours.qml index 27e0afd..fd0d1f6 100644 --- a/services/Colours.qml +++ b/services/Colours.qml @@ -33,8 +33,8 @@ Singleton { return Qt.hsla(c.hslHue, c.hslSaturation, 0.2, 1); } - function load(data: string, preview: bool): void { - const colours = preview ? preview : current; + function load(data: string, isPreview: bool): void { + const colours = isPreview ? preview : current; for (const line of data.trim().split("\n")) { let [name, colour] = line.split(" "); name = name.trim(); diff --git a/services/Wallpapers.qml b/services/Wallpapers.qml index 8e98e32..1d2a097 100644 --- a/services/Wallpapers.qml +++ b/services/Wallpapers.qml @@ -9,13 +9,13 @@ 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 currentNamePath: `${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 + readonly property string current: showPreview ? previewPath : actualCurrent + property string previewPath property string actualCurrent readonly property list preppedWalls: list.map(w => ({ @@ -33,19 +33,44 @@ Singleton { } function setWallpaper(path: string): void { + actualCurrent = path; setWall.path = path; setWall.startDetached(); } + function preview(path: string): void { + previewPath = path; + showPreview = true; + getPreviewColoursProc.running = true; + } + + function stopPreview(): void { + showPreview = false; + Colours.showPreview = false; + } + reloadableId: "wallpapers" FileView { - path: root.currentPath + path: root.currentNamePath watchChanges: true onFileChanged: reload() onLoaded: root.actualCurrent = text().trim() } + Process { + id: getPreviewColoursProc + + command: ["caelestia", "scheme", "print", root.previewPath] + stdout: SplitParser { + splitMarker: "" + onRead: data => { + Colours.load(data, true); + Colours.showPreview = true; + } + } + } + Process { id: setWall -- cgit v1.2.3-freya