summaryrefslogtreecommitdiff
path: root/modules/launcher/WallpaperList.qml
blob: fd82a2bbd0abbb394ae39180e2c38bd627bd6457 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import "root:/widgets"
import "root:/services"
import "root:/config"
import Quickshell
import QtQuick
import QtQuick.Controls

PathView {
    id: root

    required property TextField search
    required property PersistentProperties visibilities
    readonly property int numItems: {
        const screenWidth = QsWindow.window?.screen.width * 0.8;
        if (!screenWidth)
            return 0;
        const itemWidth = Config.launcher.sizes.wallpaperWidth * 0.8;
        const max = Config.launcher.maxWallpapers;
        if (max * itemWidth > screenWidth) {
            const items = Math.floor(screenWidth / itemWidth);
            return items > 1 && items % 2 === 0 ? items - 1 : items;
        }
        return max;
    }

    model: ScriptModel {
        readonly property string search: root.search.text.split(" ").slice(1).join(" ")

        values: {
            const list = Wallpapers.fuzzyQuery(search);
            if (list.length > 1 && list.length % 2 === 0)
                list.length -= 1; // Always show odd number
            return list;
        }
        onValuesChanged: root.currentIndex = search ? 0 : values.findIndex(w => w.path === Wallpapers.actualCurrent)
    }

    Component.onCompleted: currentIndex = Wallpapers.list.findIndex(w => w.path === Wallpapers.actualCurrent)
    Component.onDestruction: Wallpapers.stopPreview()

    onCurrentItemChanged: {
        if (currentItem)
            Wallpapers.preview(currentItem.modelData.path);
    }

    implicitWidth: Math.min(numItems, count) * (Config.launcher.sizes.wallpaperWidth * 0.8 + Appearance.padding.larger * 2)
    pathItemCount: numItems
    cacheItemCount: 4

    snapMode: PathView.SnapToItem
    preferredHighlightBegin: 0.5
    preferredHighlightEnd: 0.5
    highlightRangeMode: PathView.StrictlyEnforceRange

    delegate: WallpaperItem {
        visibilities: root.visibilities
    }

    path: Path {
        startY: root.height / 2

        PathAttribute {
            name: "z"
            value: 0
        }
        PathLine {
            x: root.width / 2
            relativeY: 0
        }
        PathAttribute {
            name: "z"
            value: 1
        }
        PathLine {
            x: root.width
            relativeY: 0
        }
    }
}