-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightControlRow.qml
More file actions
272 lines (249 loc) · 7.69 KB
/
Copy pathLightControlRow.qml
File metadata and controls
272 lines (249 loc) · 7.69 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
pragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Controls
Item {
id: root
property var light: ({})
property int rowIndex: 0
property int rowCount: 1
property real rowSpacing: 0
property bool preferenceBusy: false
property bool actionBusy: false
property color foreground: "white"
property color accent: "#ff6b6b"
property color switchOnColor: "#4ade80"
property color dim: Qt.darker(foreground, 1.55)
property string fontFamily: "sans-serif"
property real rowHeight: 38
property real dragHandleWidth: 22
property real actionSize: 26
property real bodyFontSize: 14
property real captionFontSize: 11
property real iconFontSize: 16
property real controlGap: 6
property string displayName: "Key Light"
property string statusText: ""
property var cancelFocusTarget: null
property bool editingName: false
property real dragDistance: 0
signal moveRequested(int fromIndex, int toIndex)
signal renameRequested(var light, int index, string name)
signal toggleRequested(var light, bool currentlyChecked)
implicitHeight: rowHeight
height: implicitHeight
z: reorderDrag.active ? 10 : 0
opacity: reorderDrag.active ? 0.8 : 1
transform: Translate { y: reorderDrag.active ? reorderDrag.translation.y : 0 }
Item {
id: dragHandle
objectName: "dragHandle"
width: root.dragHandleWidth
height: parent.height
anchors.left: parent.left
Text {
anchors.centerIn: parent
text: "☰"
color: root.dim
font.family: root.fontFamily
font.pixelSize: root.iconFontSize
}
HoverHandler { id: dragHover }
ToolTip.visible: dragHover.hovered
ToolTip.text: "Drag to reorder"
DragHandler {
id: reorderDrag
target: null
enabled: root.rowCount > 1 && !root.preferenceBusy && !root.editingName
grabPermissions: PointerHandler.CanTakeOverFromAnything
| PointerHandler.ApprovesTakeOverByAnything
xAxis.enabled: false
yAxis.enabled: true
onTranslationChanged: if (active) root.dragDistance = translation.y
onActiveChanged: {
if (active) {
root.dragDistance = 0
return
}
var rowHeight = Math.max(1, root.height + root.rowSpacing)
var destination = Math.max(0, Math.min(root.rowCount - 1,
root.rowIndex + Math.round(root.dragDistance / rowHeight)))
if (destination !== root.rowIndex) root.moveRequested(root.rowIndex, destination)
root.dragDistance = 0
}
}
}
Column {
anchors.left: dragHandle.right
anchors.leftMargin: 4
anchors.right: lightActions.left
anchors.rightMargin: 8
anchors.verticalCenter: parent.verticalCenter
spacing: 0
Text {
visible: !root.editingName
text: root.displayName
textFormat: Text.PlainText
color: root.foreground
font.family: root.fontFamily
font.pixelSize: root.bodyFontSize
font.bold: true
width: parent.width
elide: Text.ElideRight
}
TextField {
id: nameEditor
objectName: "nameEditor"
visible: root.editingName
width: parent.width
height: root.actionSize
leftPadding: 6
rightPadding: 6
topPadding: 0
bottomPadding: 0
maximumLength: 64
color: root.foreground
selectionColor: root.accent
selectedTextColor: root.foreground
font.family: root.fontFamily
font.pixelSize: root.bodyFontSize
selectByMouse: true
background: Rectangle {
color: "transparent"
border.width: 1
border.color: root.dim
radius: 3
}
onAccepted: root.renameRequested(root.light, root.rowIndex, text)
Keys.onEscapePressed: {
root.editingName = false
if (root.cancelFocusTarget) root.cancelFocusTarget.forceActiveFocus()
}
}
Text {
visible: !root.editingName
text: root.statusText
textFormat: Text.PlainText
color: root.dim
font.family: root.fontFamily
font.pixelSize: root.captionFontSize
}
}
Row {
id: lightActions
anchors.right: lightSwitch.left
anchors.rightMargin: root.controlGap
anchors.verticalCenter: parent.verticalCenter
spacing: 2
Rectangle {
objectName: "renameButton"
visible: !root.editingName
width: root.actionSize
height: root.actionSize
color: renameHover.hovered ? Qt.rgba(root.foreground.r, root.foreground.g, root.foreground.b, 0.12) : "transparent"
radius: 3
enabled: !root.preferenceBusy
Text {
anchors.centerIn: parent
text: "✎"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: root.iconFontSize
}
HoverHandler { id: renameHover }
ToolTip.visible: renameHover.hovered
ToolTip.text: "Rename light"
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
nameEditor.text = String(root.light.name || "Key Light")
root.editingName = true
Qt.callLater(function() {
nameEditor.forceActiveFocus()
nameEditor.selectAll()
})
}
}
}
Rectangle {
visible: root.editingName
width: root.actionSize
height: root.actionSize
color: "transparent"
enabled: !root.preferenceBusy
Text {
anchors.centerIn: parent
text: "✓"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: root.iconFontSize
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.renameRequested(root.light, root.rowIndex, nameEditor.text)
}
}
Rectangle {
visible: root.editingName
width: root.actionSize
height: root.actionSize
color: "transparent"
enabled: !root.preferenceBusy
Text {
anchors.centerIn: parent
text: "×"
color: root.foreground
font.family: root.fontFamily
font.pixelSize: root.iconFontSize
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.editingName = false
}
}
}
Item {
id: lightSwitch
objectName: "lightSwitch"
readonly property bool checked: root.light.reachable === true && Number(root.light.on) === 1
readonly property real trackHeight: 18
readonly property real trackWidth: Math.round(trackHeight * 1.9)
readonly property real knobSize: Math.round(trackHeight * 0.72)
readonly property real knobInset: Math.round((trackHeight - knobSize) / 2)
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
width: trackWidth + 8
height: trackHeight + 8
enabled: root.light.reachable === true
opacity: enabled ? 1 : 0.45
Rectangle {
id: toggleTrack
objectName: "toggleTrack"
width: lightSwitch.trackWidth
height: lightSwitch.trackHeight
anchors.centerIn: parent
radius: height / 2
color: lightSwitch.checked ? root.switchOnColor : Qt.rgba(root.foreground.r, root.foreground.g, root.foreground.b, 0.16)
border.width: 1
border.color: root.dim
Rectangle {
width: lightSwitch.knobSize
height: lightSwitch.knobSize
radius: height / 2
x: lightSwitch.checked
? toggleTrack.width - width - lightSwitch.knobInset
: lightSwitch.knobInset
anchors.verticalCenter: parent.verticalCenter
color: root.foreground
}
}
MouseArea {
anchors.fill: parent
enabled: lightSwitch.enabled && !root.actionBusy
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
onClicked: root.toggleRequested(root.light, lightSwitch.checked)
}
}
}