summaryrefslogtreecommitdiff
path: root/modules/utilities/cards/Toggles.qml
blob: 8e4dfb5450857ccc1831520e5d5108b348c8701b (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
import qs.components
import qs.services
import qs.config
import qs.modules.controlcenter
import Quickshell
import Quickshell.Bluetooth
import QtQuick
import QtQuick.Layouts

StyledRect {
    id: root

    required property var visibilities

    Layout.fillWidth: true
    implicitHeight: layout.implicitHeight + Appearance.padding.large * 2

    radius: Appearance.rounding.normal
    color: Colours.palette.m3surfaceContainer

    GridLayout {
        id: layout

        anchors.fill: parent
        anchors.margins: Appearance.padding.large

        columns: 2
        rowSpacing: Appearance.spacing.normal
        columnSpacing: Appearance.spacing.normal
        uniformCellWidths: true

        StyledText {
            Layout.columnSpan: 2
            text: qsTr("Quick Toggles")
            font.pointSize: Appearance.font.size.normal
        }

        Toggle {
            icon: "wifi"
            text: qsTr("WiFi")
            checked: Network.wifiEnabled

            function onClicked(): void {
                Network.toggleWifi();
            }
        }

        Toggle {
            icon: "bluetooth"
            text: qsTr("Bluetooth")
            checked: Bluetooth.defaultAdapter?.enabled ?? false

            function onClicked(): void {
                const adapter = Bluetooth.defaultAdapter;
                if (adapter)
                    adapter.enabled = !adapter.enabled;
            }
        }

        Toggle {
            icon: "mic"
            text: qsTr("Microphone")
            checked: !Audio.sourceMuted

            function onClicked(): void {
                const audio = Audio.source?.audio;
                if (audio)
                    audio.muted = !audio.muted;
            }
        }

        Toggle {
            icon: "settings"
            text: qsTr("Settings")
            toggle: false

            function onClicked(): void {
                root.visibilities.utilities = false;
                WindowFactory.create(null, {
                    screen: QsWindow.window?.screen ?? null
                });
            }
        }
    }

    component Toggle: StyledRect {
        id: toggle

        required property string icon
        required property string text
        property bool checked
        property bool toggle
        property bool internalChecked

        function onClicked(): void {
        }

        onCheckedChanged: internalChecked = checked

        radius: internalChecked ? Appearance.rounding.small : implicitHeight / 2
        color: internalChecked ? Colours.palette.m3primary : Colours.palette.m3surfaceContainerHigh

        Layout.fillWidth: true
        implicitWidth: label.implicitWidth + Appearance.padding.larger * 2
        implicitHeight: label.implicitHeight + Appearance.padding.smaller * 2

        StateLayer {
            color: toggle.internalChecked ? Colours.palette.m3onPrimary : Colours.palette.m3onSurface

            function onClicked(): void {
                if (toggle.toggle)
                    toggle.internalChecked = !toggle.internalChecked;
                toggle.onClicked();
            }
        }

        RowLayout {
            id: label

            anchors.centerIn: parent
            spacing: Appearance.spacing.small

            MaterialIcon {
                text: toggle.icon
                color: toggle.internalChecked ? Colours.palette.m3onPrimary : Colours.palette.m3onSurface
                fill: toggle.internalChecked ? 1 : 0

                Behavior on fill {
                    Anim {}
                }
            }

            StyledText {
                text: toggle.text
                color: toggle.internalChecked ? Colours.palette.m3onPrimary : Colours.palette.m3onSurface
                font.pointSize: Appearance.font.size.small
            }
        }

        Behavior on radius {
            Anim {}
        }
    }
}