// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL pragma Singleton import QtQuick import org.kde.kirigami as Kirigami // the module its own siblings live in: ThemeLibrary and FsUtils are both in it import koutnet.app // The colours the interface is painted in, once a theme is picked. // // A theme is a picture, and putting it behind the window is the smallest half of // what picking one is for: the surfaces, the text and the accent are all read off // that picture, so the whole window is the colour of the theme rather than a // scheme with a photograph behind it. A picture decides hue and saturation while // the scheme keeps its lightness, because every colour here carries text the // scheme worked its contrast out for; a hand-picked colour keeps its own // lightness too, within a range the text can still be read against. A light // scheme shows least of a picture's tint, and a pick says its colour plainly. // With no picture picked, every one of these is the scheme colour it replaces, // as before themes existed. QtObject { // Read into one property, so that the "no picture at all" case is asked about // in one place and the setting is read in one place. readonly property string wallpaperPath: appSettings.wallpaperPath // A wallpaper picked by hand is a file:// URL and a theme picked in the // settings is a bare path; the library reads files, so this is the path. readonly property string picturePath: FsUtils.toLocalPath(wallpaperPath) // The surfaces, at the lightness of the scheme's backgrounds. See // ThemeLibrary.toneFor: hue and saturation from the picture, lightness from // the base. A hand-picked colour is asked first and wins over both. readonly property color surfaceAlt: ThemeLibrary.toneFor(picturePath, AppPalette.alternateBackground) // A flat field reads as a wall, and an interface is not a wall: the surface is // three colours a step apart - window, a raised column or panel, a card - // and what sits on them says which is which. The steps are small because they // must read in the other direction too: the same numbers are a quarter of a // percent of contrast against the text, and interpolation towards the text // darkens a light scheme and lightens a dark one. readonly property color surfaceSunk: Kirigami.ColorUtils.linearInterpolation(surface, text, 0.04) readonly property color surfaceRaised: Kirigami.ColorUtils.linearInterpolation(surface, text, 0.07) readonly property color surfaceCard: Kirigami.ColorUtils.linearInterpolation(surfaceRaised, text, 0.03) // What a row is filled with under the pointer, a shade above the surface and // well below the selection: hovering is a question, choosing is an answer. readonly property color hover: Kirigami.ColorUtils.linearInterpolation(surface, text, 0.06) // The scheme's highlight is a colour rather than a step, and a rail of them // reads as bright buttons instead of one chosen row. This keeps the selection // in the same gamut, a shade away. Interpolating towards the text makes the // step the right way round in both schemes. readonly property color selection: Kirigami.ColorUtils.linearInterpolation(surface, text, 0.12) // The selection for the thing the window is about - the conversation in front // of you, the tab that is open: two steps off the surface with a wash of the // accent, so it is both raised and coloured. readonly property color selectionStrong: Kirigami.ColorUtils.linearInterpolation( Kirigami.ColorUtils.linearInterpolation(surface, text, 0.14), accent, 0.22) // A hairline for edges that need no shadow: the scheme's text at a tenth, the // same restraint as the steps above. readonly property color border: Kirigami.ColorUtils.linearInterpolation(surface, text, 0.10) // The text at the scheme's text lightness and washed barely: a tint of the // scheme's colour, staying where the scheme put it. readonly property color text: ThemeLibrary.toneFor(picturePath, AppPalette.text) // A hand-picked colour beats the picture. The pick is asked first, and with // no wallpaper it is the only tint: its own hue, saturation and lightness, // kept in a range the text on the surface can still be read against. readonly property color surface: appSettings.surfaceColor.length > 0 ? ThemeLibrary.pickedTone(appSettings.surfaceColor, AppPalette.background) : ThemeLibrary.toneFor(picturePath, AppPalette.background) // The accent, washed for being looked at rather than read against - see // ThemeLibrary.accentFor. A hand-picked colour is asked first and keeps its // own lightness; with no pick the picture's tone takes the scheme's. readonly property color accent: appSettings.accentColor.length > 0 ? ThemeLibrary.pickedAccent(appSettings.accentColor, AppPalette.highlight) : ThemeLibrary.accentFor(picturePath, AppPalette.highlight) // What is written on the accent: whichever scheme text colour reads better on // it, not the one for the scheme's highlight. The accent keeps the scheme's // lightness, so the scheme is nearly always right and a picture often is not. // A picked accent can now be light under a dark scheme or dark under a light // one, so the ink is chosen from the accent itself rather than the scheme. readonly property color accentText: accent.hslLightness > 0.55 ? "#101010" : "#ffffff" // How the wallpaper is drawn, as the Image's own fill mode. The setting // stores the position of the choice in the appearance page's list and this is // the same order; out-of-range falls to cover, the only way before the choice. // // Here rather than in the window's file because more than one surface draws // the picture - the window and the list's translucent copy - and they must // answer the same way or the copies stop lining up. function wallpaperFillModeOf(mode) { const modes = [ Image.Stretch, Image.PreserveAspectFit, Image.PreserveAspectCrop, Image.Tile, Image.TileVertically, Image.TileHorizontally, Image.Pad ] return modes[Math.max(0, Math.min(modes.length - 1, mode))] } }