aboutsummaryrefslogtreecommitdiffstats
path: root/appearance/IconsTab.qml
blob: b2c7ee43c958eb44aced635a36216dae8d83d3fc (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

import Quickshell
import Quickshell.Widgets
import QtQuick

Flickable {
    contentHeight: col.implicitHeight
    clip: true

    property string liveCursorCursor: ""

    Column {
        id: col
        width: parent.width
        spacing: 12

        Text {
            text: Icons.scanning ? "scanning…" : `${Icons.iconThemes.length} icon themes · ${Icons.cursorThemes.length} cursor themes`
            color: Theme.overlay
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
        }

        Text {
            text: "Icon theme"
            color: Theme.subtext
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
        }

        // Flow, not a horizontal strip: the cards wrap onto further rows rather
        // than running off the right edge, and the tab scrolls vertically.
        Flow {
            width: parent.width
            spacing: 10
            Repeater {
                model: Icons.iconThemes
                Rectangle {
                    id: iconCard
                    required property string modelData
                    readonly property bool current: Icons.currentIcon === modelData
                    width: 230; height: 150; radius: 10
                    color: current ? Qt.alpha(Theme.accent, 0.2) : Qt.alpha(Theme.surface, 0.35)
                    border.width: current ? 2 : 1
                    border.color: current ? Theme.accent : "transparent"

                    MouseArea {
                        anchors.fill: parent
                        cursorShape: Qt.PointingHandCursor
                        onClicked: Icons.applyIcon(modelData)
                    }

                    Column {
                        width: parent.width - 16
                        anchors.centerIn: parent
                        spacing: 10
                        Row {
                            anchors.horizontalCenter: parent.horizontalCenter
                            spacing: 8
                            Repeater {
                                model: ["folder", "text-x-generic", "image-x-generic", "network-wireless"]
                                IconImage {
                                    required property string modelData
                                    readonly property string glyph: (Icons.iconPreview[iconCard.modelData] ?? {})[modelData] ?? ""
                                    // Absolute paths must carry file://, or they
                                    // resolve against the config's qrc base and
                                    // fail; Gtk's builtin icons come back as
                                    // /org/gtk gresource paths Qt cannot open.
                                    source: glyph.indexOf("/") === 0 && glyph.indexOf("/org/gtk/") !== 0
                                            ? "file://" + glyph : ""
                                    implicitSize: 44
                                }
                            }
                        }
                        Text {
                            width: parent.width
                            horizontalAlignment: Text.AlignHCenter
                            text: iconCard.current ? modelData + "  current" : modelData
                            color: Theme.text
                            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
                            wrapMode: Text.WrapAnywhere
                            maximumLineCount: 2
                            elide: Text.ElideRight
                        }
                    }
                }
            }
        }

        Row {
            spacing: 10
            Text {
                anchors.verticalCenter: parent.verticalCenter
                text: "Cursor theme"
                color: Theme.subtext
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2; bold: true }
            }
            Item { width: 12; height: 1 }
            Text {
                anchors.verticalCenter: parent.verticalCenter
                text: "Size"
                color: Theme.subtext
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
            }
            Repeater {
                model: [16, 24, 32, 48, 64]
                Tab {
                    required property var modelData
                    anchors.verticalCenter: parent.verticalCenter
                    text: String(modelData)
                    selected: Icons.cursorSize === modelData
                    onClicked: Icons.setCursorSize(modelData)
                }
            }
        }

        Flow {
            width: parent.width
            spacing: 10
            Repeater {
                model: Icons.cursorThemes
                Rectangle {
                    id: cursorCard
                    required property string modelData
                    readonly property bool current: Icons.currentCursor === modelData
                    width: 230; height: 150; radius: 10
                    color: current ? Qt.alpha(Theme.accent, 0.2) : Qt.alpha(Theme.surface, 0.35)
                    border.width: current ? 2 : 1
                    border.color: current ? Theme.accent : "transparent"

                    HoverHandler {
                        onHoveredChanged: {
                            if (hovered) {
                                // Previews are already batched on open; hovering
                                // only switches the real cursor and reverts it.
                                liveCursorCursor = modelData;
                                Quickshell.execDetached(["hyprctl", "setcursor", modelData,
                                                         String(Icons.cursorSize)]);
                            } else if (liveCursorCursor === modelData) {
                                liveCursorCursor = "";
                                Quickshell.execDetached(["hyprctl", "setcursor", Icons.currentCursor,
                                                         String(Icons.cursorSize)]);
                            }
                        }
                    }
                    MouseArea {
                        anchors.fill: parent
                        cursorShape: Qt.PointingHandCursor
                        onClicked: Icons.applyCursor(modelData)
                    }

                    Column {
                        width: parent.width - 16
                        anchors.centerIn: parent
                        spacing: 10
                        Row {
                            anchors.horizontalCenter: parent.horizontalCenter
                            spacing: 8
                            Repeater {
                                // The cases that tell themes apart: arrow, hand,
                                // text and horizontal resize.
                                model: ["left_ptr", "hand2", "xterm", "resize"]
                                Image {
                                    required property string modelData
                                    readonly property string p: (Icons.cursorPreview[cursorCard.modelData] ?? {})[modelData] ?? ""
                                    width: 44; height: 44
                                    asynchronous: true
                                    source: p !== "" ? "file://" + p : ""
                                    fillMode: Image.PreserveAspectFit
                                }
                            }
                        }
                        Text {
                            width: parent.width
                            horizontalAlignment: Text.AlignHCenter
                            text: cursorCard.current ? modelData + "  current" : modelData
                            color: Theme.text
                            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
                            wrapMode: Text.WrapAnywhere
                            maximumLineCount: 2
                            elide: Text.ElideRight
                        }
                    }
                }
            }
        }

        Text {
            width: parent.width
            wrapMode: Text.Wrap
            visible: Icons.notice !== ""
            text: Icons.notice
            color: Theme.green
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
        }
    }

    onVisibleChanged: if (!visible && liveCursorCursor !== "") {
        Quickshell.execDetached(["hyprctl", "setcursor", Icons.currentCursor, String(Icons.cursorSize)]);
        liveCursorCursor = "";
    }

    // A Loader destroys this item on tab switch or drawer close, and visible
    // does not necessarily change first, so revert the real cursor here too.
    Component.onDestruction: if (liveCursorCursor !== "") {
        Quickshell.execDetached(["hyprctl", "setcursor", Icons.currentCursor, String(Icons.cursorSize)]);
        liveCursorCursor = "";
    }
}