foxygit / TV-Launcher Log in
commits tags

/qml/Theme.qml · 7.2 KB

raw
pragma Singleton
import QtQuick

// Alla färger och mått på ett ställe (motsvarar CSS-variabler).
// Komponenterna läser t.ex. Theme.card och Theme.accent; när ett värde
// här ändras uppdateras hela gränssnittet direkt.
//
// preset, accent, tileScale och radiusScale sätts från inställningarna
// (Main.qml binder dem till prefs, som sparas i settings.ini).
QtObject {
    id: theme

    // ---- skalning -------------------------------------------------------
    property real s: 1                // fönsterhöjd / 1080
    property real tileScale: 1        // rutstorlek
    property real radiusScale: 1      // hörnens rundning
    function dp(v) { return Math.round(v * s) }
    function tile(v) { return Math.round(v * s * tileScale) }
    function r(v) { return Math.round(v * s * radiusScale) }

    // ---- val ------------------------------------------------------------
    property string preset: "standard"
    property color accent: "#3daee9"
    property string tileMode: "app"     // "app" | "theme" | "accent"
    property real tileOpacity: 1        // 1 = helt täckande
    property string homePath: ""

    readonly property var presets: ({
        standard: { name: "Standard",
            bg: "#0f1317", bgTop: "#1a2330", surface: "#1e252e", surfaceHi: "#2a333f",
            card: "#2f353d", cardFocus: "#3a4350", panel: "#262a31", sidebar: "#141820",
            border: "#3a4552", borderSoft: "#2f3a46", track: "#55606c",
            text: "#eef1f4", textDim: "#98a3af", placeholder: "#66717d",
            backdropTop: "#2a2350", backdropMid: "#1a1d33", backdropBottom: "#101320", backdropGlow: "#a0507a" },
        midnight: { name: "Midnatt",
            bg: "#0a0f1e", bgTop: "#121b36", surface: "#141c33", surfaceHi: "#1f2a4a",
            card: "#1b2440", cardFocus: "#26335a", panel: "#121a30", sidebar: "#0a1020",
            border: "#2c3a63", borderSoft: "#222e52", track: "#3a4a78",
            text: "#eef2fb", textDim: "#93a1c4", placeholder: "#5f6c90",
            backdropTop: "#13235a", backdropMid: "#0c1736", backdropBottom: "#070c1c", backdropGlow: "#2d6bd6" },
        oled: { name: "OLED svart",
            bg: "#000000", bgTop: "#050505", surface: "#101010", surfaceHi: "#1c1c1c",
            card: "#141414", cardFocus: "#242424", panel: "#0a0a0a", sidebar: "#000000",
            border: "#2a2a2a", borderSoft: "#1e1e1e", track: "#3a3a3a",
            text: "#f2f2f2", textDim: "#9a9a9a", placeholder: "#5e5e5e",
            backdropTop: "#000000", backdropMid: "#000000", backdropBottom: "#000000", backdropGlow: "#000000" },
        warm: { name: "Varm",
            bg: "#17110d", bgTop: "#2a1d15", surface: "#241a14", surfaceHi: "#33261d",
            card: "#2e221a", cardFocus: "#3d2e23", panel: "#221912", sidebar: "#150f0b",
            border: "#4a372a", borderSoft: "#3a2b20", track: "#5e4636",
            text: "#f6efe8", textDim: "#b3a191", placeholder: "#7d6b5c",
            backdropTop: "#4a2a1a", backdropMid: "#2a1a12", backdropBottom: "#120c08", backdropGlow: "#c0702a" },
        forest: { name: "Skog",
            bg: "#0d1512", bgTop: "#15261f", surface: "#16221d", surfaceHi: "#203029",
            card: "#1c2a24", cardFocus: "#273a31", panel: "#14201b", sidebar: "#0b1310",
            border: "#2f4a3e", borderSoft: "#253b31", track: "#3e5e50",
            text: "#eef5f1", textDim: "#98b0a5", placeholder: "#5f7a6e",
            backdropTop: "#173a2c", backdropMid: "#10241c", backdropBottom: "#08120e", backdropGlow: "#3a9a6a" }
    })
    readonly property var presetKeys: ["standard", "midnight", "oled", "warm", "forest"]

    readonly property var accents: [
        { name: "Blå", color: "#3daee9" }, { name: "Lila", color: "#9b59b6" },
        { name: "Rosa", color: "#e93d8c" }, { name: "Röd", color: "#da4453" },
        { name: "Orange", color: "#f67400" }, { name: "Gul", color: "#fdbc4b" },
        { name: "Grön", color: "#27ae60" }, { name: "Turkos", color: "#1abc9c" },
        { name: "Vit", color: "#e8e8e8" }
    ]

    readonly property var p: presets[preset] || presets.standard

    // ---- färger ---------------------------------------------------------
    readonly property color bg: p.bg
    readonly property color bgTop: p.bgTop
    readonly property color surface: p.surface          // fält, dialoger
    readonly property color surfaceHi: p.surfaceHi      // markerade fält
    readonly property color card: p.card                // kort i inställningar
    readonly property color cardFocus: p.cardFocus
    readonly property color panel: p.panel              // inställningarnas innehållsyta
    readonly property color sidebar: p.sidebar
    readonly property color border: p.border
    readonly property color borderSoft: p.borderSoft
    readonly property color track: p.track              // reglage, av-läge
    readonly property color text: p.text
    readonly property color textDim: p.textDim
    readonly property color placeholder: p.placeholder
    readonly property color danger: "#e5534b"
    readonly property color onAccent: Qt.colorEqual(accent, "#e8e8e8") || Qt.colorEqual(accent, "#fdbc4b")
                                      ? "#111111" : "#ffffff"
    readonly property color scrim: "#b0000000"

    readonly property color backdropTop: p.backdropTop
    readonly property color backdropMid: p.backdropMid
    readonly property color backdropBottom: p.backdropBottom
    readonly property color backdropGlow: p.backdropGlow

    function alpha(c, a) {
        const col = Qt.lighter(c, 1.0)   // tar även emot strängar som "#ff0000"
        return Qt.rgba(col.r, col.g, col.b, a)
    }

    // Färg att välja för en app (Utseende). Tom = automatiskt.
    readonly property var tileColorChoices: [
        { value: "", label: "Automatisk" },
        { value: "#2d5d8a", label: "Blå" }, { value: "#3e5a8f", label: "Kungsblå" },
        { value: "#2b7a8a", label: "Petrol" }, { value: "#2f7d5b", label: "Grön" },
        { value: "#5c6b2d", label: "Oliv" }, { value: "#a2552b", label: "Orange" },
        { value: "#8a2d4b", label: "Vinröd" }, { value: "#7a3e8f", label: "Lila" },
        { value: "#3a3f47", label: "Grå" }, { value: "#111111", label: "Svart" },
        { value: "#e8e8e8", label: "Vit" }
    ]

    // Rutans bakgrund: appens egen färg, annars enligt tileMode.
    function tileColor(name, custom) {
        let base
        if (custom && custom !== "") base = custom
        else if (tileMode === "theme") base = cardFocus
        else if (tileMode === "accent") base = Qt.darker(accent, 1.6)
        else base = Qt.darker(colorFor(name), 1.15)
        return alpha(base, tileOpacity)
    }

    // Bildsökväg eller webbadress -> URL för Image.
    function imageUrl(p) {
        if (!p) return ""
        if (/^[a-z]+:\/\//i.test(p)) return p
        if (p.startsWith("~/")) return "file://" + homePath + p.slice(1)
        return "file://" + p
    }

    readonly property string fontFamily: "Noto Sans"

    readonly property var tileColors: ["#2d5d8a", "#7a3e8f", "#2f7d5b", "#a2552b",
                                       "#8a2d4b", "#3e5a8f", "#5c6b2d", "#2b7a8a"]

    function colorFor(name) {
        let h = 0
        for (let i = 0; i < name.length; ++i)
            h = (h * 31 + name.charCodeAt(i)) >>> 0
        return tileColors[h % tileColors.length]
    }
}