diff options
Diffstat (limited to 'desktop/modules/appearance/WallpaperTab.qml')
| -rw-r--r-- | desktop/modules/appearance/WallpaperTab.qml | 90 |
1 files changed, 87 insertions, 3 deletions
diff --git a/desktop/modules/appearance/WallpaperTab.qml b/desktop/modules/appearance/WallpaperTab.qml index 136b24d..cf41a4d 100644 --- a/desktop/modules/appearance/WallpaperTab.qml +++ b/desktop/modules/appearance/WallpaperTab.qml @@ -205,9 +205,59 @@ Column { } } + // The colour filter: a click shows only the wallpapers that carry the + // colour (Wallpapers.colors), a second click shows them all again. + Row { + id: colorRow + spacing: 8 + Text { + anchors.verticalCenter: parent.verticalCenter + text: "Colour" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 } + color: Theme.subtext + } + Repeater { + // Fixed colours, not the theme's: they name WallColors.js's hue + // buckets, which do not move with the scheme, and a scheme can + // reuse one colour under several names (one had peach = yellow, + // blue = lavender, mauve = pink, three pairs of twin circles). + model: [ + { key: "red", color: "#ed8796" }, { key: "peach", color: "#f5a97f" }, + { key: "yellow", color: "#eed49f" }, { key: "green", color: "#a6da95" }, + { key: "teal", color: "#8bd5ca" }, { key: "blue", color: "#8aadf4" }, + { key: "mauve", color: "#c6a0f6" }, { key: "dark", color: "#181926" }, + { key: "light", color: "#cad3f5" }, + ] + delegate: Rectangle { + required property var modelData + readonly property bool on: Wallpapers.colorFilter === modelData.key + anchors.verticalCenter: parent.verticalCenter + width: 22 + height: 22 + radius: width / 2 + color: modelData.color + border.width: on ? 3 : swatchHover.hovered ? 2 : 1 + border.color: on ? Theme.accent : Qt.alpha(Theme.text, swatchHover.hovered ? 0.6 : 0.2) + HoverHandler { id: swatchHover } + MouseArea { + anchors.fill: parent + cursorShape: Qt.PointingHandCursor + onClicked: Wallpapers.colorFilter = parent.on ? "" : modelData.key + } + } + } + Text { + anchors.verticalCenter: parent.verticalCenter + visible: Wallpapers.analysing + text: "analysing colours…" + font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } + color: Theme.overlay + } + } + Column { width: parent.width - height: parent.height - mockPane.height - parent.spacing + height: parent.height - mockPane.height - colorRow.height - parent.spacing * 2 spacing: 12 Row { @@ -232,6 +282,8 @@ Column { anchors.verticalCenter: parent.verticalCenter text: Wallpapers.scanning ? "scanning…" : Wallpapers.applying ? "applying…" + : Wallpapers.colorFilter !== "" + ? Wallpapers.groups.reduce((n, g) => n + g.files.length, 0) + " of " + Wallpapers.files.length + " wallpapers" : Wallpapers.files.length + " wallpapers" font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 } color: Theme.overlay @@ -268,18 +320,50 @@ Column { return out; } function rebuild() { + // An open folder the colour filter hid is folded for real, + // not just hidden, and unless another is open the first + // folder left opens in its place. Left open, it came back + // beside the next one opened once the filter was cleared. + // Not while the list is empty, before the first scan. + const keys = Wallpapers.groups.map(g => g.key); + const hidden = Object.keys(Wallpapers.expanded) + .filter(k => Wallpapers.expanded[k] && keys.indexOf(k) < 0); + if (keys.length > 0 && hidden.length > 0) { + hidden.forEach(k => Wallpapers.toggle(k)); + if (!keys.some(k => Wallpapers.expanded[k])) Wallpapers.toggle(keys[0]); + } rows.clear(); for (const g of Wallpapers.groups) { rows.append({ key: g.key, start: -1 }); if (Wallpapers.expanded[g.key]) rows.append(rowsOf(g)); } } + // One folder open at a time: opening one first folds any other, + // from the bottom up so the indexes above stay put, then scrolls + // to the new one's header, which a fold above it would move. function toggle(index) { const g = group(rows.get(index).key); const body = rowsOf(g); - if (Wallpapers.expanded[g.key]) rows.remove(index + 1, body.length); - else body.forEach((r, i) => rows.insert(index + 1 + i, r)); + if (Wallpapers.expanded[g.key]) { + rows.remove(index + 1, body.length); + Wallpapers.toggle(g.key); + return; + } + let folded = false; + for (let i = rows.count - 1; i >= 0; i--) { + const r = rows.get(i); + if (r.start >= 0 || r.key === g.key || !Wallpapers.expanded[r.key]) continue; + rows.remove(i + 1, rowsOf(group(r.key)).length); + Wallpapers.toggle(r.key); + if (i < index) folded = true; + } + if (folded) { + index = 0; + while (rows.get(index).key !== g.key) index++; + } + body.forEach((r, i) => rows.insert(index + 1 + i, r)); Wallpapers.toggle(g.key); + if (folded) positionViewAtIndex(index, ListView.Beginning); } // The width settles after creation, and a new column count |
