summaryrefslogtreecommitdiff
path: root/raveos-hyprland-theme/theme-data/dms/Modules/Settings/Widgets/DeviceAliasRow.qml
blob: bec5ff1f6e94462f5acb4bdc5da007997164d739 (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
180
pragma ComponentBehavior: Bound

import QtQuick
import qs.Common
import qs.Services
import qs.Widgets

Rectangle {
    id: root

    LayoutMirroring.enabled: I18n.isRtl
    LayoutMirroring.childrenInherit: true

    required property var deviceNode
    property string deviceType: "output"

    property bool showHideButton: false
    property bool isHidden: false

    signal editRequested(var deviceNode)
    signal resetRequested(var deviceNode)
    signal hideRequested(var deviceNode)

    width: parent?.width ?? 0
    height: deviceRowContent.height + Theme.spacingM * 2
    radius: Theme.cornerRadius
    color: deviceMouseArea.containsMouse ? Theme.surfaceHover : "transparent"

    readonly property bool hasCustomAlias: AudioService.hasDeviceAlias(deviceNode?.name ?? "")
    readonly property string displayedName: AudioService.displayName(deviceNode)

    Row {
        id: deviceRowContent
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.verticalCenter: parent.verticalCenter
        anchors.leftMargin: Theme.spacingM
        anchors.rightMargin: Theme.spacingM
        spacing: Theme.spacingM

        DankIcon {
            name: root.deviceType === "input" ? "mic" : "speaker"
            size: Theme.iconSize
            color: Theme.surfaceText
            anchors.verticalCenter: parent.verticalCenter
        }

        Column {
            anchors.verticalCenter: parent.verticalCenter
            width: parent.width - Theme.iconSize - Theme.spacingM * 3 - buttonsRow.width
            spacing: 2

            StyledText {
                text: root.displayedName
                font.pixelSize: Theme.fontSizeMedium
                font.weight: Font.Medium
                color: Theme.surfaceText
                width: parent.width
                elide: Text.ElideRight
                horizontalAlignment: Text.AlignLeft
            }

            Column {
                width: parent.width
                spacing: 2

                Row {
                    width: parent.width
                    spacing: Theme.spacingS

                    StyledText {
                        text: root.deviceNode?.name ?? ""
                        font.pixelSize: Theme.fontSizeSmall
                        color: Theme.surfaceVariantText
                        width: parent.width - (customAliasLabel.visible ? customAliasLabel.width + Theme.spacingS : 0)
                        elide: Text.ElideRight
                        anchors.verticalCenter: parent.verticalCenter
                        horizontalAlignment: Text.AlignLeft
                    }

                    Rectangle {
                        id: customAliasLabel
                        visible: root.hasCustomAlias
                        height: customAliasText.implicitHeight + 4
                        width: customAliasText.implicitWidth + Theme.spacingS * 2
                        radius: 3
                        color: Theme.withAlpha(Theme.primary, 0.15)
                        anchors.verticalCenter: parent.verticalCenter

                        StyledText {
                            id: customAliasText
                            text: I18n.tr("Custom")
                            font.pixelSize: Theme.fontSizeSmall - 1
                            color: Theme.primary
                            font.weight: Font.Medium
                            anchors.centerIn: parent
                        }
                    }
                }

                StyledText {
                    visible: root.hasCustomAlias
                    text: I18n.tr("Original: %1").arg(AudioService.originalName(root.deviceNode))
                    font.pixelSize: Theme.fontSizeSmall - 1
                    color: Theme.surfaceVariantText
                    width: parent.width
                    elide: Text.ElideRight
                    opacity: 0.6
                    horizontalAlignment: Text.AlignLeft
                }
            }
        }

        Row {
            id: buttonsRow
            anchors.verticalCenter: parent.verticalCenter
            spacing: Theme.spacingS

            DankActionButton {
                id: resetButton
                visible: root.hasCustomAlias
                buttonSize: 36
                iconName: "restart_alt"
                iconSize: 20
                backgroundColor: Theme.surfaceContainerHigh
                iconColor: Theme.surfaceVariantText
                tooltipText: I18n.tr("Reset to default name")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    root.resetRequested(root.deviceNode);
                }
            }

            DankActionButton {
                id: hideButton
                visible: root.showHideButton
                buttonSize: 36
                iconName: root.isHidden ? "visibility" : "visibility_off"
                iconSize: 20
                backgroundColor: Theme.surfaceContainerHigh
                iconColor: root.isHidden ? Theme.primary : Theme.surfaceVariantText
                tooltipText: root.isHidden ? I18n.tr("Show device") : I18n.tr("Hide device")
                anchors.verticalCenter: parent.verticalCenter
                onClicked: {
                    root.hideRequested(root.deviceNode);
                }
            }

            DankActionButton {
                id: editButton
                buttonSize: 36
                iconName: "edit"
                iconSize: 20
                backgroundColor: Theme.buttonBg
                iconColor: Theme.buttonText
                tooltipText: I18n.tr("Set custom name")
                anchors.verticalCenter: parent.verticalCenter
                visible: !root.isHidden
                onClicked: {
                    root.editRequested(root.deviceNode);
                }
            }
        }
    }

    MouseArea {
        id: deviceMouseArea
        anchors.fill: parent
        hoverEnabled: true
        propagateComposedEvents: true
        z: -1
    }

    Behavior on color {
        ColorAnimation {
            duration: Theme.shortDuration
            easing.type: Theme.standardEasing
        }
    }
}