aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/obs/ObsScenesPage.qml
blob: b689c72a854b312635fdf27292f54b52f65f6564 (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
// 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 "../.."
import "../../island"

// One row per scene: its name and a field holding its glyph. Paste an icon
// from the Nerd Fonts cheat sheet; an empty field falls back to the generic.
Column {
    id: page

    spacing: 6

    // Bumped on discard/save so the rows are rebuilt. A TextInput breaks its
    // text binding on user edit, so without this a Discard would leave the
    // discarded glyph on screen.
    property int rev: 0
    Connections {
        target: SceneIcons
        function onReset() { page.rev++ }
    }

    readonly property var rows: {
        const out = [];
        const add = n => { if (!out.some(r => r.name === n)) out.push({ name: n, rev: page.rev }); };
        for (const n in SceneIcons.map.scenes) add(n);
        for (const n of Obs.scenes) add(n);
        return out;
    }

    function glyphOf(name) {
        const d = SceneIcons.draft;
        if (d && d.scenes) return d.scenes[name] ?? "";
        return SceneIcons.map.scenes[name] ?? "";
    }

    function genericGlyph() {
        const d = SceneIcons.draft;
        return d ? (d.generic ?? "") : SceneIcons.map.generic;
    }

    Text {
        width: parent.width
        wrapMode: Text.Wrap
        text: "Paste an icon from the Nerd Fonts cheat sheet. An empty field falls back to the default for unmapped scenes."
        color: Theme.subtext
        font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 4 }
    }

    Repeater {
        model: page.rows
        delegate: Item {
            id: row
            required property var modelData
            objectName: modelData.name
            width: page.width
            height: 40

            Text {
                anchors { left: parent.left; right: field.left; rightMargin: 10; verticalCenter: parent.verticalCenter }
                elide: Text.ElideRight
                text: row.modelData.name
                color: Theme.text
                font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
            }

            Rectangle {
                id: field
                anchors { right: parent.right; verticalCenter: parent.verticalCenter }
                width: 64
                height: 34
                radius: 8
                color: Theme.surface
                border.width: 1
                border.color: field.invalid ? Theme.red : Qt.alpha(Theme.text, 0.15)
                readonly property string value: page.glyphOf(row.modelData.name)
                readonly property bool invalid: value !== "" && !SceneIcons.validGlyph(value)

                TextInput {

                    activeFocusOnTab: true
                    anchors.fill: parent
                    horizontalAlignment: TextInput.AlignHCenter
                    verticalAlignment: TextInput.AlignVCenter
                    selectByMouse: true
                    text: field.value
                    color: Theme.text
                    font { family: Theme.iconFamily; pixelSize: Theme.fontSize + 4 }
                    onTextEdited: SceneIcons.editScene(row.modelData.name, text)
                }
            }
        }
    }

    Item {
        width: parent.width
        height: 40

        Text {
            anchors { left: parent.left; right: gfield.left; rightMargin: 10; verticalCenter: parent.verticalCenter }
            elide: Text.ElideRight
            text: "Default for unmapped scenes"
            color: Theme.text
            font { family: Theme.fontFamily; pixelSize: Theme.fontSize - 2 }
        }

        Rectangle {
            id: gfield
            anchors { right: parent.right; verticalCenter: parent.verticalCenter }
            width: 64
            height: 34
            radius: 8
            color: Theme.surface
            border.width: 1
            border.color: gfield.invalid ? Theme.red : Qt.alpha(Theme.text, 0.15)
            readonly property string value: page.genericGlyph()
            readonly property bool invalid: value !== "" && !SceneIcons.validGlyph(value)

            TextInput {

                activeFocusOnTab: true
                anchors.fill: parent
                horizontalAlignment: TextInput.AlignHCenter
                verticalAlignment: TextInput.AlignVCenter
                selectByMouse: true
                text: gfield.value
                color: Theme.text
                font { family: Theme.iconFamily; pixelSize: Theme.fontSize + 4 }
                onTextEdited: SceneIcons.editGeneric(text)
            }
        }
    }
}