// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL import QtQuick import QtQuick.Controls as QQC2 import org.kde.kirigami as Kirigami import koutnet.app // One theme on the gallery's grid: the picture as it will look behind the // window, its name under it, and a mark on the one in use. // // This is Plasma's wallpaper tile rather than one more settings row, because a // theme is judged by looking at it. A list of names says which theme is called // what; a grid of pictures says which one you want, which is the only question // this tab exists to answer. The colours are not being chosen here - they belong // to the colour scheme on the tab next door - so the picture is the whole of // what a tile offers. QQC2.AbstractButton { id: root // The picture as an Image can take it: a file:// URL, not the bare path a // setting keeps (see FsUtils). Empty is a tile with no picture on it, which // is the way back to a plain window rather than a theme. property string sourceUrl // The theme's name written the way a name is written, which is the file's // own name with the capitals on. It is what the tile is named to a screen // reader, and what the tile says under the picture. property string label // The theme in use, which is one checkbox on a tile rather than a row // saying "selected" beside a picture: one place in the grid where the // answer to "which one is this" is answered, and it is on the picture. property bool selected: false // The size of the caption, fixed rather than asked of the label, so that a // grid of tiles with names of two lengths and names of one line each still // has its rows level. readonly property int kCaptionHeight: Math.round(Kirigami.Units.gridUnit * 1.4) // Five eighths, which is a wallpaper's own shape: the picture is cropped to // the tile the way the window crops it to itself, and a thumbnail that is a // different shape from the wallpaper is a thumbnail of some other part of // the picture than the one the window will show. readonly property int kPictureHeight: Math.round(width * 0.625) // The size the pictures are decoded at: twice the narrowest tile the grid // lays out, which is every tile it lays out at the density this screen is at. // Fixed rather than read off the item, and the reason is in the image below. readonly property int kThumbnailWidth: Kirigami.Units.gridUnit * 10 * 2 readonly property int kThumbnailHeight: Math.round(kThumbnailWidth * 0.625) implicitWidth: Kirigami.Units.gridUnit * 10 // Read off width, which the gallery sets: the tiles in a row share the width // and have to agree on their height too, or the rows are two heights. implicitHeight: kPictureHeight + Kirigami.Units.smallSpacing + kCaptionHeight checkable: true checked: root.selected // A tile that is a checkbox says so to a screen reader and takes a space bar, // which a plain button drawn like this one would not. Accessible.role: Accessible.CheckBox Accessible.name: root.label hoverEnabled: true background: Rectangle { radius: Kirigami.Units.cornerRadius // The picture is clipped to this, and the frame is drawn over it: a // border on a rounded rectangle is drawn inside its shape, so a border // that is not on top of the picture is a border the picture hides. color: "transparent" border.width: 0 clip: true Image { id: picture width: root.width height: root.kPictureHeight visible: root.sourceUrl.length > 0 source: root.sourceUrl // The window crops the wallpaper to fill, so the thumbnail does too: // a letterboxed one shows bars the window will never have and // squashes the middle of the picture. fillMode: Image.PreserveAspectCrop asynchronous: true // These are the pictures of a whole folder, several of them fifteen // megabytes of JPEG, and each one decoded at full size is sixty // megabytes of pixels for a thumbnail. Decoded once, at a fixed size, // and left in the cache: // // A sourceSize read off the size being drawn re-decodes the file // whenever that size changes, which on a grid of these means every // step of a window drag decoding the whole folder again - the grid // blinks through twenty-three of them while the settings window is // being resized. The same is done to the wallpaper itself, in // Main.qml, for the same reason. // // And the cache is left on: the tab is built again every time the // settings are opened, and without it every visit decodes every // picture in the folder all over again, for a grid of thumbnails // nobody scrolls back to. sourceSize.width: root.kThumbnailWidth sourceSize.height: root.kThumbnailHeight } // Where the picture is, so a tile with no picture is a picture of // nothing rather than a hole in the grid: the caption below is the // same either way, and it is the caption that says which is which. Rectangle { width: root.width height: root.kPictureHeight visible: root.sourceUrl.length === 0 color: ThemePalette.surfaceAlt } // The mark on the theme in use: the one thing in this tab that a // screenshot of it has to show. Rectangle { id: mark anchors.top: parent.top anchors.right: parent.right anchors.topMargin: Kirigami.Units.smallSpacing anchors.rightMargin: Kirigami.Units.smallSpacing width: Kirigami.Units.gridUnit * 0.85 height: width radius: width / 2 visible: root.selected // The highlight colour itself and not a "highlighted background" of // its own, which is not a colour Kirigami's theme has: a name that // is not there reads as no colour at all, and the mark is then a tick // floating on somebody's photograph. color: ThemePalette.accent QQC2.Label { anchors.centerIn: parent text: "✓" color: ThemePalette.accentText font.pixelSize: Math.round(Kirigami.Units.gridUnit * 0.55) } } } // The frame, over the picture, and the only border on the tile: the selected // one wears the highlight colour outright, a hovered one wears it faintly so // that a grid of pictures is still a grid of pictures and not a grid of // boxes. Rectangle { id: frame anchors.fill: parent radius: Kirigami.Units.cornerRadius color: "transparent" border.width: root.selected ? Math.max(1, Math.round(Kirigami.Units.smallSpacing / 3)) : Math.max(1, Math.round(Kirigami.Units.smallSpacing / 6)) border.color: root.selected ? ThemePalette.accent : Qt.alpha(ThemePalette.accent, root.hovered ? 0.5 : 0.15) Behavior on border.color { ColorAnimation { duration: Kirigami.Units.veryShortDuration } } } // The name, under the picture rather than over it: a caption over a // photograph needs a scrim to be readable, and a scrim is a grey box on // somebody's picture. QQC2.Label { anchors.bottom: parent.bottom anchors.left: parent.left anchors.right: parent.right height: root.kCaptionHeight verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter // Two lines, because the names are file names and some of them are // three words long; one line and a wide name is a name with a third of // it elided off the end. wrapMode: Text.Wrap maximumLineCount: 2 elide: Text.ElideRight text: root.label // The highlight colour on the card, not the colour for text on a // highlight: the name is written on the card, and the frame round the // picture is the only thing that is highlighted. color: root.selected ? ThemePalette.accent : ThemePalette.text font.weight: root.selected ? Font.DemiBold : Font.Normal } }