aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/appearance/ThemeTab.qml
blob: acee97aee36d3cafaf71daeba38bfbb7e0331d48 (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
// 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 QtQuick
import "../.."

// Colour schemes from unified-desktop-theme, each with its swatches and a mock
// of a panel in its colours. Clicking one applies it through install.sh.
Column {
    id: tab
    spacing: 10

    // install.sh reloads Hyprland, kitty and conky; this says what it cannot
    // reach, or why it failed.
    property string notice: ""
    Connections {
        target: Udt
        function onApplied(scheme, ok, message) {
            tab.notice = ok
                ? `${scheme} applied. Restart Qt, GTK, btop and Joplin; neovim needs :colorscheme udt.`
                : `failed: ${message}`;
        }
    }

    Text {
        visible: tab.notice !== ""
        width: parent.width
        wrapMode: Text.Wrap
        text: tab.notice
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 3 }
        color: tab.notice.indexOf("failed") === 0 ? Theme.red : Theme.green
    }

    Repeater {
        model: Udt.names

        Rectangle {
            required property string modelData
            // What a search hit scrolls to (ThemeModule's searchItems key).
            objectName: modelData
            readonly property var sw: Udt.swatches[modelData] ?? ({})
            readonly property bool isCurrent: Udt.current === modelData

            width: tab.width
            implicitHeight: 96
            radius: 10
            color: hover.hovered ? Qt.alpha(Theme.surface, 0.75)
                                 : Qt.alpha(Theme.surface, 0.35)
            border.width: 1
            border.color: isCurrent ? Qt.alpha(Theme.accent, 0.6) : "transparent"

            HoverHandler { id: hover }
            MouseArea {
                anchors.fill: parent
                enabled: !Udt.applying && !isCurrent
                cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
                onClicked: Udt.apply(modelData)
            }

            Row {
                anchors.fill: parent
                anchors.margins: 14
                spacing: 16

                // A mock of the desktop in that scheme's colours:
                // swatches alone say what the colours are, this
                // says how they sit together.
                Rectangle {
                    anchors.verticalCenter: parent.verticalCenter
                    width: 150; height: 68
                    radius: 6
                    color: sw.bg ?? Theme.base
                    border.width: 1
                    border.color: Qt.alpha(sw.text ?? Theme.text, 0.15)
                    clip: true

                    Column {
                        anchors.fill: parent
                        anchors.margins: 7
                        spacing: 5

                        Row {
                            spacing: 4
                            Rectangle {
                                width: 26; height: 8; radius: 2
                                color: sw.accent ?? Theme.accent
                            }
                            Rectangle {
                                width: 16; height: 8; radius: 2
                                color: sw.surface ?? Theme.surface
                            }
                            Rectangle {
                                width: 16; height: 8; radius: 2
                                color: sw.surface ?? Theme.surface
                            }
                        }

                        Rectangle {
                            width: parent.width; height: 20; radius: 3
                            color: sw.surface ?? Theme.surface

                            Rectangle {
                                anchors.verticalCenter: parent.verticalCenter
                                x: 5; width: 60; height: 5; radius: 2
                                color: Qt.alpha(sw.text ?? Theme.text, 0.75)
                            }
                            Rectangle {
                                anchors.verticalCenter: parent.verticalCenter
                                anchors.right: parent.right
                                anchors.rightMargin: 5
                                width: 22; height: 9; radius: 3
                                color: sw.accent ?? Theme.accent
                            }
                        }

                        Row {
                            spacing: 4
                            Rectangle { width: 9; height: 9; radius: 5; color: sw.green ?? Theme.green }
                            Rectangle { width: 9; height: 9; radius: 5; color: sw.yellow ?? Theme.yellow }
                            Rectangle { width: 9; height: 9; radius: 5; color: sw.red ?? Theme.red }
                        }
                    }
                }

                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    spacing: 8

                    Row {
                        spacing: 8
                        Text {
                            text: modelData
                            font { family: Theme.fontFamily; pixelSize: Theme.fontSize; bold: true }
                            color: Theme.text
                        }
                        Text {
                            anchors.verticalCenter: parent.verticalCenter
                            visible: isCurrent
                            text: "current"
                            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
                            color: Theme.accent
                        }
                        Text {
                            anchors.verticalCenter: parent.verticalCenter
                            visible: Udt.applying
                            text: "applying…"
                            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
                            color: Theme.overlay
                        }
                    }

                    Row {
                        spacing: 5
                        Repeater {
                            model: [sw.bg, sw.surface, sw.text, sw.accent,
                                    sw.green, sw.yellow, sw.red]
                            Rectangle {
                                required property var modelData
                                visible: modelData !== undefined && modelData !== ""
                                width: 22; height: 22; radius: 4
                                color: modelData ?? "transparent"
                                border.width: 1
                                border.color: Qt.alpha(Theme.text, 0.1)
                            }
                        }
                    }
                }
            }
        }
    }
}