-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPanel.qml
More file actions
1192 lines (1061 loc) · 40.2 KB
/
Copy pathPanel.qml
File metadata and controls
1192 lines (1061 loc) · 40.2 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import QtQuick
import Quickshell
import Quickshell.Io
import qs.Commons
import qs.Ui
import "HueApi.js" as HueApi
Panel {
id: root
moduleName: "omarchy-philips-hue"
ipcTarget: "omarchy-philips-hue"
property var anchorItem: null
property var hostWidget: null
readonly property var barIdentity: hostWidget || root
property var config: null
property string currentThemeName: ""
property var lightsById: ({})
property var rooms: []
property var roomsWithLights: []
property var orphanLights: []
property int pendingFetches: 0
property bool loading: false
property bool lastFetchFailed: false
property var actionQueue: []
property var expandedRooms: ({})
readonly property int roomCount: root.roomsWithLights.length
readonly property int lightTotal: root.lightsTotal()
readonly property int lightedRoomCount: root.lightedRooms().length
readonly property int emptyRoomCount: root.emptyRooms().length
readonly property bool allLightsOn: root.computeAllLightsOn()
readonly property bool insecureMode: root.config !== null && !root.config.bridgeId
readonly property string statusText: {
if (root.config === null) return "Not paired"
if (root.lastFetchFailed) return "Bridge unreachable"
if (root.loading) return "Loading…"
var roomLabel = root.lightedRoomCount + " room" + (root.lightedRoomCount === 1 ? "" : "s")
var apiLabel = root.config ? " · Hue " + root.config.apiVersion : ""
return roomLabel + " · " + root.lightTotal + " light" + (root.lightTotal === 1 ? "" : "s") + apiLabel
}
function computeAllLightsOn() {
if (root.lightedRoomCount === 0) return false
var rooms = root.lightedRooms()
for (var i = 0; i < rooms.length; i++) {
if (!rooms[i].on) return false
}
return true
}
function lightedRooms() {
var result = []
for (var i = 0; i < root.roomsWithLights.length; i++) {
if (root.roomsWithLights[i].lightCount > 0) result.push(root.roomsWithLights[i])
}
return result
}
function emptyRooms() {
var result = []
for (var i = 0; i < root.roomsWithLights.length; i++) {
if (root.roomsWithLights[i].lightCount === 0) result.push(root.roomsWithLights[i])
}
return result
}
function lightsTotal() {
var total = 0
for (var i = 0; i < root.roomsWithLights.length; i++) {
total += root.roomsWithLights[i].lightCount
}
return total + root.orphanLights.length
}
function open() {
root.controller.show()
root.refresh()
}
function openFromHotkey() {
root.controller.show()
root.refresh()
}
function close() {
root.controller.hide()
}
function refresh() {
if (!root.config) {
configFile.reload()
return
}
root.lastFetchFailed = false
if (root.roomsWithLights.length === 0 && root.orphanLights.length === 0) root.loading = true
lightsProc.running = false
groupsProc.running = false
Qt.callLater(startFetches)
}
function startFetches() {
if (!root.config) return
root.pendingFetches = 2
lightsProc.command = HueApi.apiCmd(["get-lights"])
groupsProc.command = HueApi.apiCmd(["get-groups"])
lightsProc.running = true
groupsProc.running = true
}
function finishFetch(success) {
root.pendingFetches--
if (success === false) root.lastFetchFailed = true
if (root.pendingFetches <= 0) {
root.loading = false
root.assembleRooms()
}
}
function assembleRooms() {
var used = {}
var result = []
for (var i = 0; i < root.rooms.length; i++) {
var room = root.rooms[i]
var lights = HueApi.roomLights(room, root.lightsById)
for (var j = 0; j < room.lightIds.length; j++) used[room.lightIds[j]] = true
result.push({
id: room.id,
apiId: room.apiId,
controlId: room.controlId,
name: room.name,
on: room.on,
lightCount: lights.length,
lights: lights
})
}
var orphans = []
for (var id in root.lightsById) {
if (!used[id]) orphans.push(root.lightsById[id])
}
root.roomsWithLights = result
root.orphanLights = orphans
}
function lightClone(light, changes) {
return {
id: light.id,
apiId: light.apiId,
name: light.name,
on: changes.on !== undefined ? changes.on : light.on,
bri: changes.bri !== undefined ? changes.bri : light.bri,
hasBri: light.hasBri,
ct: changes.ct !== undefined ? changes.ct : light.ct,
hasCt: light.hasCt,
ctMin: light.ctMin,
ctMax: light.ctMax,
hue: changes.hue !== undefined ? changes.hue : light.hue,
sat: changes.sat !== undefined ? changes.sat : light.sat,
hasColor: light.hasColor,
colormode: light.colormode,
xy: light.xy ? light.xy.slice() : [],
gamut: light.gamut || {},
pickerOpen: changes.pickerOpen !== undefined ? changes.pickerOpen : light.pickerOpen
}
}
function lightCopy(light, on) {
return root.lightClone(light, { on: on })
}
function setRoomOn(roomId, on) {
var newRooms = []
for (var i = 0; i < root.roomsWithLights.length; i++) {
var room = root.roomsWithLights[i]
newRooms.push({
id: room.id,
apiId: room.apiId,
controlId: room.controlId,
name: room.name,
on: room.id === roomId ? on : room.on,
lightCount: room.lightCount,
lights: room.id === roomId
? room.lights.map(function(light) { return root.lightCopy(light, on) })
: room.lights
})
}
root.roomsWithLights = newRooms
}
function setLightOn(lightId, on) {
var newRooms = []
for (var i = 0; i < root.roomsWithLights.length; i++) {
var room = root.roomsWithLights[i]
newRooms.push({
id: room.id,
apiId: room.apiId,
controlId: room.controlId,
name: room.name,
on: room.on,
lightCount: room.lightCount,
lights: room.lights.map(function(light) {
return light.id === lightId ? root.lightCopy(light, on) : light
})
})
}
root.roomsWithLights = newRooms
root.orphanLights = root.orphanLights.map(function(light) {
return light.id === lightId ? root.lightCopy(light, on) : light
})
}
function patchLights(lightId, changes) {
var newRooms = []
for (var i = 0; i < root.roomsWithLights.length; i++) {
var room = root.roomsWithLights[i]
newRooms.push({
id: room.id,
apiId: room.apiId,
controlId: room.controlId,
name: room.name,
on: room.on,
lightCount: room.lightCount,
lights: room.lights.map(function(light) {
return light.id === lightId ? root.lightClone(light, changes) : light
})
})
}
root.roomsWithLights = newRooms
root.orphanLights = root.orphanLights.map(function(light) {
return light.id === lightId ? root.lightClone(light, changes) : light
})
}
function setLightBri(lightId, bri) {
root.patchLights(lightId, { bri: bri })
}
function setLightCt(lightId, ct) {
root.patchLights(lightId, { ct: ct })
}
function patchLightColor(lightId, hue, sat) {
root.patchLights(lightId, { hue: hue, sat: sat })
}
function lightById(lightId) {
for (var i = 0; i < root.roomsWithLights.length; i++) {
var room = root.roomsWithLights[i]
for (var j = 0; j < room.lights.length; j++) {
if (room.lights[j].id === lightId) return room.lights[j]
}
}
for (var k = 0; k < root.orphanLights.length; k++) {
if (root.orphanLights[k].id === lightId) return root.orphanLights[k]
}
return null
}
function roomById(roomId) {
for (var i = 0; i < root.roomsWithLights.length; i++) {
if (root.roomsWithLights[i].id === roomId) return root.roomsWithLights[i]
}
return null
}
function roomSyncOn(roomId) {
return root.themeSync[roomId] !== false
}
// Effective scene-mode state for a room: per-room override, else the global
// "scene" default from hue-theme.json.
function roomSceneDefault(roomId) {
return root.sceneRooms[roomId] !== undefined ? root.sceneRooms[roomId] : root.sceneDefault
}
// Scene Mode is only offered when the room is synced and has at least two
// color-capable lights (the hook's own threshold for building a scene).
function roomSceneApplies(room) {
return root.roomSyncOn(room.id) && HueApi.roomColorLightCount(room) >= 2
}
function roomExpanded(roomId) {
return root.expandedRooms[roomId] === true
}
function toggleRoomExpanded(roomId) {
var map = JSON.parse(JSON.stringify(root.expandedRooms))
map[roomId] = map[roomId] !== true
root.expandedRooms = map
}
function toggleColorPicker(lightId) {
var light = root.lightById(lightId)
if (light) root.patchLights(lightId, { pickerOpen: !light.pickerOpen })
}
function toggleRoom(roomId, on) {
if (!root.config) return
var room = root.roomById(roomId)
if (!room || !room.controlId) return
root.setRoomOn(roomId, on)
root.runAction(HueApi.apiCmd(["put-group", room.controlId, JSON.stringify({ on: on })]))
root.scheduleRefresh()
}
function toggleLight(lightId, on) {
if (!root.config) return
var light = root.lightById(lightId)
if (!light) return
root.setLightOn(lightId, on)
root.runAction(HueApi.apiCmd(["put-light", light.apiId, JSON.stringify({ on: on })]))
root.scheduleRefresh()
}
function setBrightness(lightId, bri) {
if (!root.config) return
var light = root.lightById(lightId)
if (!light) return
var clamped = Math.max(1, Math.min(254, Math.round(bri)))
root.setLightBri(lightId, clamped)
root.runAction(HueApi.apiCmd(["put-light", light.apiId, JSON.stringify({ bri: clamped })]))
root.scheduleRefresh()
}
function setColorTemperature(lightId, ct) {
if (!root.config) return
var light = root.lightById(lightId)
if (!light) return
var clamped = Math.max(light.ctMin, Math.min(light.ctMax, Math.round(ct)))
root.setLightCt(lightId, clamped)
root.runAction(HueApi.apiCmd(["put-light", light.apiId, JSON.stringify({ ct: clamped })]))
root.scheduleRefresh()
}
function setLightColor(lightId, hue, sat) {
if (!root.config) return
var light = root.lightById(lightId)
if (!light) return
root.patchLightColor(lightId, hue, sat)
root.runAction(HueApi.apiCmd(["put-light", light.apiId, JSON.stringify({ hue: hue, sat: sat })]))
root.scheduleRefresh()
}
function toggleAll(on) {
if (!root.config || root.lightedRoomCount === 0) return
var rooms = root.lightedRooms()
var body = JSON.stringify({ on: on })
for (var i = 0; i < rooms.length; i++) {
if (rooms[i].controlId) root.runAction(HueApi.apiCmd(["put-group", rooms[i].controlId, body]))
}
root.setAllOn(on)
root.scheduleRefresh()
}
function setAllOn(on) {
root.roomsWithLights = root.roomsWithLights.map(function(room) {
if (room.lightCount === 0) return room
return {
id: room.id,
apiId: room.apiId,
controlId: room.controlId,
name: room.name,
on: on,
lightCount: room.lightCount,
lights: room.lights.map(function(light) { return root.lightCopy(light, on) })
}
})
}
function runAction(command) {
root.actionQueue.push(command)
drainActionQueue()
}
function drainActionQueue() {
if (actionProc.running) return
if (root.actionQueue.length === 0) return
var next = root.actionQueue.shift()
actionProc.command = next
actionProc.running = true
}
function scheduleRefresh() {
resyncTimer.restart()
}
property FileView configFile: FileView {
path: Quickshell.env("HOME") + "/.local/state/omarchy/settings/hue.json"
watchChanges: true
printErrors: false
onFileChanged: reload()
onLoaded: {
root.config = HueApi.parseConfig(text())
if (root.config) {
root.config.username = ""
root.refresh()
}
}
onLoadFailed: root.config = null
}
property FileView themeNameFile: FileView {
path: Quickshell.env("HOME") + "/.local/state/omarchy/current/theme.name"
watchChanges: true
printErrors: false
onFileChanged: reload()
onLoaded: root.currentThemeName = String(text()).trim()
}
property var themeSync: ({})
property var sceneRooms: ({})
property bool sceneDefault: false
property FileView themeConfigFile: FileView {
path: Quickshell.env("HOME") + "/.config/omarchy/settings/hue-theme.json"
watchChanges: true
printErrors: false
onFileChanged: reload()
onLoaded: {
try {
var parsed = JSON.parse(text())
root.themeSync = parsed.themeSync || {}
root.sceneRooms = parsed.sceneRooms || {}
root.sceneDefault = parsed.scene === true
} catch (e) {
root.themeSync = {}
root.sceneRooms = {}
root.sceneDefault = false
}
}
onLoadFailed: {
root.themeSync = {}
root.sceneRooms = {}
root.sceneDefault = false
}
}
Timer {
interval: 1500
running: true
onTriggered: configFile.reload()
}
Timer {
interval: 5000
repeat: true
running: root.config === null
onTriggered: configFile.reload()
}
Timer {
id: resyncTimer
interval: 700
onTriggered: root.refresh()
}
Timer {
id: pollTimer
interval: 15000
repeat: true
running: root.config !== null
onTriggered: root.refresh()
}
Process {
id: lightsProc
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: {
var lights = HueApi.parseLights(text)
var byId = {}
for (var i = 0; i < lights.length; i++) byId[lights[i].id] = lights[i]
root.lightsById = byId
root.finishFetch(true)
}
}
onExited: function(exitCode) {
if (exitCode !== 0) root.finishFetch(false)
}
}
Process {
id: groupsProc
stdout: StdioCollector {
waitForEnd: true
onStreamFinished: {
root.rooms = HueApi.parseGroups(text)
root.finishFetch(true)
}
}
onExited: function(exitCode) {
if (exitCode !== 0) root.finishFetch(false)
}
}
Process {
id: actionProc
onExited: function(exitCode) {
root.drainActionQueue()
}
}
KeyboardPanel {
id: panel
anchorItem: root.anchorItem
owner: root.barIdentity
bar: root.bar
open: root.opened
centerOnBar: true
focusTarget: keyCatcher
contentWidth: panel.fittedContentWidth(Style.space(380))
contentHeight: panel.fittedContentHeight(column.implicitHeight)
PanelKeyCatcher {
id: keyCatcher
anchors.fill: parent
onCloseRequested: root.close()
onTabRequested: function(direction) { root.switchPanel(direction) }
Flickable {
id: scroll
anchors.fill: parent
contentWidth: width
contentHeight: column.implicitHeight
clip: true
boundsBehavior: Flickable.StopAtBounds
interactive: contentHeight > height
Column {
id: column
width: scroll.width
spacing: Style.space(6)
Row {
width: parent.width
spacing: Style.space(10)
Text {
anchors.verticalCenter: parent.verticalCenter
text: ""
color: root.bar.foreground
font.family: root.bar.fontFamily
font.pixelSize: Style.font.title
}
Column {
anchors.verticalCenter: parent.verticalCenter
spacing: Style.space(2)
Text {
text: "Hue Lights" + (root.currentThemeName ? " (" + root.currentThemeName + ")" : "")
color: root.bar.foreground
font.family: root.bar.fontFamily
font.pixelSize: Style.font.title
font.bold: true
}
Text {
text: root.statusText
color: Qt.darker(root.bar.foreground, 1.4)
font.family: root.bar.fontFamily
font.pixelSize: Style.font.caption
}
}
}
Rectangle {
width: parent.width
height: Style.spacing.hairline
color: root.bar.foreground
opacity: 0.12
}
Column {
visible: root.config === null
width: parent.width
spacing: Style.space(4)
Text {
width: parent.width
text: "No bridge configured yet."
color: root.bar.foreground
font.family: root.bar.fontFamily
font.pixelSize: Style.font.body
wrapMode: Text.WordWrap
}
Text {
width: parent.width
text: "Press the link button on your Hue bridge, then click below."
color: Qt.darker(root.bar.foreground, 1.4)
font.family: root.bar.fontFamily
font.pixelSize: Style.font.caption
wrapMode: Text.WordWrap
}
Rectangle {
width: parent.width
height: pairButton.implicitHeight + Style.space(16)
radius: Style.space(8)
color: pairButtonMouse.containsMouse ? Qt.lighter(Color.accent, 1.2) : Color.accent
Text {
id: pairButton
anchors.centerIn: parent
text: "Pair with bridge"
color: "#ffffff"
font.family: root.bar.fontFamily
font.pixelSize: Style.font.body
font.bold: true
}
MouseArea {
id: pairButtonMouse
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled: true
onClicked: {
var pairPath = Qt.resolvedUrl("pair.sh").toString().replace("file://", "")
Quickshell.execDetached(["omarchy-launch-terminal", "bash", pairPath])
}
}
}
}
Row {
visible: root.config !== null && root.loading && root.roomCount === 0 && root.orphanLights.length === 0
spacing: Style.space(4)
Text {
text: ""
color: Qt.darker(root.bar.foreground, 1.4)
font.family: root.bar.fontFamily
font.pixelSize: Style.font.body
RotationAnimator on rotation {
running: root.loading
from: 0
to: 360
duration: 800
loops: Animation.Infinite
}
}
Text {
text: "Loading…"
color: Qt.darker(root.bar.foreground, 1.4)
font.family: root.bar.fontFamily
font.pixelSize: Style.font.body
}
}
Text {
visible: root.config !== null && root.lastFetchFailed && !root.loading
width: parent.width
text: "Couldn't reach the bridge. Check the bridge is on and the IP is still valid, then re-run pair.sh."
color: Color.urgent
font.family: root.bar.fontFamily
font.pixelSize: Style.font.caption
wrapMode: Text.WordWrap
}
Text {
visible: root.insecureMode
width: parent.width
text: "TLS verification disabled. Re-run pair.sh to secure the connection."
color: Color.urgent
font.family: root.bar.fontFamily
font.pixelSize: Style.font.caption
wrapMode: Text.WordWrap
}
InlineToggle {
visible: root.config !== null && root.lightedRoomCount > 0
width: parent.width
label: "All lights"
checked: root.allLightsOn
foreground: root.bar.foreground
accent: Color.accent
fontFamily: root.bar.fontFamily
onClicked: root.toggleAll(!root.allLightsOn)
}
Column {
visible: root.config !== null && root.roomCount > 0
width: parent.width
spacing: Style.space(4)
Repeater {
model: root.lightedRooms()
Column {
id: roomColumn
required property var modelData
readonly property bool lightsOpen: root.roomExpanded(modelData.id)
width: parent.width
spacing: Style.space(2)
BorderSurface {
id: roomHeader
width: parent.width
radius: Style.cornerRadius
implicitHeight: Math.max(54, Style.font.subtitle + Style.spacing.huge)
readonly property bool hot: headerMouse.containsMouse || powerTrack.hot
readonly property color roomTint: HueApi.roomColor(roomColumn.modelData)
color: roomHeader.roomTint.a > 0
? (roomHeader.roomTint.r + roomHeader.roomTint.g + roomHeader.roomTint.b === 0
? "#000000"
: Qt.rgba(roomHeader.roomTint.r, roomHeader.roomTint.g, roomHeader.roomTint.b,
roomHeader.hot ? 0.45 : 0.30))
: Style.controlFill(false, roomHeader.hot, root.bar.foreground, Color.accent)
borderSpec: Border.controlSpec(
roomHeader.hot ? "hover-cursor" : "normal",
root.bar.foreground, Color.accent)
Behavior on color { ColorAnimation { duration: 100 } }
activeFocusOnTab: true
Keys.onReturnPressed: root.toggleRoom(roomColumn.modelData.id, !roomColumn.modelData.on)
Keys.onEnterPressed: root.toggleRoom(roomColumn.modelData.id, !roomColumn.modelData.on)
Keys.onSpacePressed: root.toggleRoom(roomColumn.modelData.id, !roomColumn.modelData.on)
MouseArea {
id: headerMouse
anchors.fill: parent
hoverEnabled: true
}
ToggleSwitch {
id: powerTrack
anchors.right: parent.right
anchors.rightMargin: parent.borderRight + Style.spacing.rowPaddingX
anchors.verticalCenter: parent.verticalCenter
checked: roomColumn.modelData.on
foreground: root.bar.foreground
accent: Color.accent
interactive: true
onToggled: root.toggleRoom(roomColumn.modelData.id, !roomColumn.modelData.on)
}
Rectangle {
id: discButton
anchors.right: powerTrack.left
anchors.rightMargin: Style.spacing.rowPaddingX
anchors.verticalCenter: parent.verticalCenter
width: Style.space(22)
height: Style.space(22)
radius: Style.space(5)
color: discMouse.containsMouse || roomColumn.lightsOpen
? Qt.rgba(root.bar.foreground.r, root.bar.foreground.g, root.bar.foreground.b, 0.14)
: Qt.rgba(root.bar.foreground.r, root.bar.foreground.g, root.bar.foreground.b, 0.06)
border.width: 1
border.color: roomColumn.lightsOpen
? Color.accent
: Qt.rgba(root.bar.foreground.r, root.bar.foreground.g, root.bar.foreground.b, 0.28)
Text {
anchors.centerIn: parent
text: "\u25b8"
color: roomColumn.lightsOpen ? Color.accent : Qt.darker(root.bar.foreground, 1.4)
font.family: root.bar.fontFamily
font.pixelSize: Style.font.caption
rotation: roomColumn.lightsOpen ? 90 : 0
Behavior on rotation { NumberAnimation { duration: 120 } }
}
MouseArea {
id: discMouse
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: root.toggleRoomExpanded(roomColumn.modelData.id)
}
}
Text {
anchors.left: parent.left
anchors.leftMargin: parent.borderLeft + Style.spacing.rowPaddingX
anchors.right: discButton.left
anchors.rightMargin: Style.spacing.rowPaddingX
anchors.verticalCenter: parent.verticalCenter
text: roomColumn.modelData.name + " (" + roomColumn.modelData.lightCount + ")"
textFormat: Text.PlainText
color: root.bar.foreground
font.family: root.bar.fontFamily
font.pixelSize: Style.font.subtitle
font.bold: true
elide: Text.ElideRight
}
}
Row {
id: syncRow
visible: modelData.on && roomColumn.lightsOpen
width: parent.width
spacing: Style.space(1)
readonly property bool sceneUsable: root.roomSceneApplies(modelData)
InlineToggle {
width: syncRow.sceneUsable ? (parent.width - parent.spacing) / 2 : parent.width
label: "Theme Sync"
checked: root.themeSync[modelData.id] !== false
foreground: root.bar.foreground
accent: Color.accent
fontFamily: root.bar.fontFamily
onClicked: {
var ts = JSON.parse(JSON.stringify(root.themeSync))
var turningOn = ts[modelData.id] === false
ts[modelData.id] = turningOn
root.themeSync = ts
actionProc.command = HueApi.apiCmd(["write-theme-config", JSON.stringify(ts)])
actionProc.running = true
if (turningOn) {
root.runAction(HueApi.apiCmd(["sync-room", modelData.id]))
}
}
}
InlineToggle {
visible: syncRow.sceneUsable
width: (parent.width - parent.spacing) / 2
label: "Scene Mode"
checked: root.roomSceneDefault(modelData.id)
foreground: root.bar.foreground
accent: Color.accent
fontFamily: root.bar.fontFamily
onClicked: {
var ss = JSON.parse(JSON.stringify(root.sceneRooms))
ss[modelData.id] = !root.roomSceneDefault(modelData.id)
root.sceneRooms = ss
actionProc.command = HueApi.apiCmd(["write-scene-config", JSON.stringify(ss)])
actionProc.running = true
}
}
}
Repeater {
model: modelData.lights
Column {
id: roomLightRow
required property var modelData
readonly property bool themeSynced: root.roomSyncOn(roomColumn.modelData.id)
visible: roomColumn.lightsOpen
width: parent.width
spacing: Style.space(1)
InlineToggle {
width: parent.width
label: modelData.name
titleSize: Style.font.body
rowColor: HueApi.lightColor(modelData)
checked: modelData.on
foreground: Qt.darker(root.bar.foreground, 1.2)
accent: Color.accent
fontFamily: root.bar.fontFamily
onClicked: root.toggleLight(modelData.id, !modelData.on)
}
Row {
visible: modelData.on && modelData.hasColor
width: parent.width - Style.space(24)
anchors.horizontalCenter: parent.horizontalCenter
spacing: Style.space(8)
PanelSlider {
width: roomLightRow.themeSynced ? parent.width : parent.width - Style.space(30)
bar: root.bar
minimum: 1
maximum: 254
integer: true
step: 10
value: modelData.bri
onReleased: function(v) { root.setBrightness(modelData.id, v) }
}
Item {
visible: !roomLightRow.themeSynced
width: Style.space(22)
height: Style.space(22)
Image {
anchors.fill: parent
source: Qt.resolvedUrl("hsv_wheel.png")
fillMode: Image.Stretch
smooth: true
}
Rectangle {
anchors.fill: parent
radius: Style.space(11)
border.width: modelData.pickerOpen ? 2 : 1
border.color: modelData.pickerOpen ? Color.accent : Qt.darker(root.bar.foreground, 1.6)
color: "transparent"
}
MouseArea {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: root.toggleColorPicker(modelData.id)
}
}
}
ColorWheel {
lightOn: modelData.on
hasColor: modelData.hasColor
pickerOpen: modelData.pickerOpen
themeSynced: roomLightRow.themeSynced
initialHue: modelData.hue
initialSat: modelData.sat
onColorSelected: function(hue, sat) { root.setLightColor(modelData.id, hue, sat) }
}
PanelSlider {
visible: modelData.on && modelData.hasCt && !roomLightRow.themeSynced
width: parent.width - Style.space(24)
anchors.horizontalCenter: parent.horizontalCenter
bar: root.bar
minimum: modelData.ctMin
maximum: modelData.ctMax
integer: true
step: 10
value: modelData.ct
onReleased: function(v) { root.setColorTemperature(modelData.id, v) }
}
}
}
}
}
}
Item {
id: emptyRoomsSection
visible: root.config !== null && root.emptyRoomCount > 0
width: parent.width
height: emptyRoomsInner.height + Style.space(16)
property bool expanded: false
Rectangle {
anchors.fill: parent
radius: Style.space(8)
color: Qt.rgba(root.bar.foreground.r, root.bar.foreground.g, root.bar.foreground.b,
headerMouse.containsMouse || emptyRoomsSection.expanded ? 0.10 : 0.05)
border.width: 1
border.color: Qt.rgba(root.bar.foreground.r, root.bar.foreground.g, root.bar.foreground.b,
headerMouse.containsMouse || emptyRoomsSection.expanded ? 0.32 : 0.16)
}
MouseArea {
id: headerMouse
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Style.space(8)
height: headerRow.height
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: emptyRoomsSection.expanded = !emptyRoomsSection.expanded
}
Text {
anchors.right: parent.right
anchors.rightMargin: Style.space(10)
y: Style.space(8) + (headerRow.height - height) / 2
text: "\u25b8"
color: headerMouse.containsMouse ? Color.accent : Qt.darker(root.bar.foreground, 1.4)
font.family: root.bar.fontFamily
font.pixelSize: Style.font.body
rotation: emptyRoomsSection.expanded ? 90 : 0
transformOrigin: Item.Center
Behavior on rotation { NumberAnimation { duration: 120 } }
}
Column {
id: emptyRoomsInner
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: Style.space(8)
spacing: Style.space(6)
Row {
id: headerRow
width: parent.width
spacing: Style.space(6)
Text {
text: "Empty rooms"
color: headerMouse.containsMouse ? Color.accent : root.bar.foreground
font.family: root.bar.fontFamily
font.pixelSize: Style.font.body
font.bold: true
}
Text {
anchors.verticalCenter: parent.verticalCenter
text: "(" + root.emptyRoomCount + ")"