-
Notifications
You must be signed in to change notification settings - Fork 23
/
Settings.qml
1725 lines (1549 loc) · 85.3 KB
/
Settings.qml
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 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
import QtQuick.Controls.Styles 1.4
import QtQuick.Controls.Universal 2.12
import QtGraphicalEffects 1.12
import Qt.labs.settings 1.0
import AndroidNative 1.0 as AN
LauncherPage {
id: settingsPage
anchors.fill: parent
topPadding: mainView.innerSpacing
function updateAvailablePlugins() {
pluginSettingsItemColumn.loadAvailablePlugins()
}
Flickable {
anchors.fill: parent
contentWidth: parent.width
contentHeight: settingsColumn.height
Column {
id: settingsColumn
width: parent.width
function closeAllItemsExcept(item) {
if (item !== newsSettingsItemColumn && newsSettingsItemColumn.newsCheckboxes.length > 0) {
newsSettingsItemColumn.menuState = false
newsSettingsItemColumn.destroyCheckboxes()
}
if (item !== sourceSettingsItemColumn && sourceSettingsItemColumn.checkboxes.length > 0) {
sourceSettingsItemColumn.menuState = false
sourceSettingsItemColumn.destroyCheckboxes()
}
if (item !== shortcutSettingsItemColumn && shortcutSettingsItemColumn.checkboxes.length > 0) {
shortcutSettingsItemColumn.menuState = false
shortcutSettingsItemColumn.destroyCheckboxes()
}
if (item !== searchSettingsItemColumn && searchSettingsItemColumn.checkboxes.length > 0) {
searchSettingsItemColumn.menuState = false
searchSettingsItemColumn.destroyCheckboxes()
}
if (item !== designSettingsItemColumn && designSettingsItemColumn.checkboxes.length > 0) {
designSettingsItemColumn.menuState = false
designSettingsItemColumn.destroyCheckboxes()
}
if (item !== pluginSettingsItemColumn && pluginSettingsItemColumn.checkboxes.length > 0) {
pluginSettingsItemColumn.menuState = false
pluginSettingsItemColumn.destroyCheckboxes()
}
if (item !== resetSettingsItemColumn && resetSettingsItemColumn.menuState) {
resetSettingsItemColumn.menuState = false
}
}
Label {
id: headerLabel
padding: mainView.innerSpacing
width: parent.width - 2 * mainView.innerSpacing
text: qsTr("Settings")
font.pointSize: mainView.headerFontSize
font.weight: Font.Black
bottomPadding: mainView.innerSpacing
}
MouseArea {
id: themeSettingsItem
width: parent.width
implicitHeight: themeSettingsItemColumn.height
preventStealing: true
property var selectedMenuItem: themeSettingsItemTitle
property bool menuState: false
property double labelOpacity: 0.0
Column {
id: themeSettingsItemColumn
width: parent.width
Label {
id: themeSettingsItemTitle
property var theme: themeSettings.theme
padding: mainView.innerSpacing
width: parent.width
text: qsTr("Dark Mode")
font.pointSize: mainView.largeFontSize
font.weight: themeSettingsItem.menuState ? Font.Black : Font.Normal
color: themeSettingsItem.menuState ? "white" : Universal.foreground
background: Rectangle {
anchors.fill: parent
color: themeSettingsItem.menuState === true ? mainView.accentColor : "transparent"
}
Component.onCompleted: {
theme = themeSettings.theme
switch (themeSettings.theme) {
case mainView.theme.Dark:
text = qsTr("Dark Mode")
break
case mainView.theme.Light:
text = qsTr("Light Mode")
break
case mainView.theme.Translucent:
text = qsTr("Translucent Mode")
break
default:
console.log("Settings | Unknown theme selected: " + mainView.theme)
}
}
}
HighlightButton {
id: darkModeOption
property var theme: mainView.theme.Dark
leftPadding: mainView.innerSpacing
rightPadding: mainView.innerSpacing
bottomPadding: mainView.innerSpacing
width: parent.width
visible: themeSettingsItem.menuState
text: qsTr("Dark Mode")
boldText: themeSettingsItem.selectedMenuItem === darkModeOption
textColor: "white"
textOpacity: themeSettingsItem.labelOpacity
backgroundColor: themeSettingsItem.menuState ? mainView.accentColor : "transparent"
fontPointSize: mainView.mediumFontSize
}
HighlightButton {
id: lightModeOption
property var theme: mainView.theme.Light
leftPadding: mainView.innerSpacing
rightPadding: mainView.innerSpacing
bottomPadding: mainView.innerSpacing
width: parent.width
visible: themeSettingsItem.menuState
text: qsTr("Light Mode")
boldText: themeSettingsItem.selectedMenuItem === lightModeOption
textColor: "white"
textOpacity: themeSettingsItem.labelOpacity
backgroundColor: themeSettingsItem.menuState ? mainView.accentColor : "transparent"
fontPointSize: mainView.mediumFontSize
}
HighlightButton {
id: translucentModeOption
property var theme: mainView.theme.Translucent
leftPadding: mainView.innerSpacing
rightPadding: mainView.innerSpacing
bottomPadding: mainView.innerSpacing * 2
width: parent.width
visible: themeSettingsItem.menuState
text: qsTr("Translucent Mode")
boldText: themeSettingsItem.selectedMenuItem === translucentModeOption
textColor: "white"
textOpacity: themeSettingsItem.labelOpacity
backgroundColor: themeSettingsItem.menuState ? mainView.accentColor : "transparent"
fontPointSize: mainView.mediumFontSize
}
}
Behavior on implicitHeight {
NumberAnimation {
duration: 250.
onRunningChanged: {
if (!running && themeSettingsItem.menuState) {
console.log("Settings | Switch on mode options labels")
themeSettingsItem.labelOpacity = 1.0
} else if (running && !themeSettingsItem.menuState) {
console.log("Settings | Switch off mode option labels")
themeSettingsItem.labelOpacity = 0.0
}
}
}
}
Behavior on labelOpacity {
NumberAnimation {
duration: 250
}
}
onEntered: {
console.log("Settings | mouse entered")
preventStealing = !preventStealing
menuState = true
}
onCanceled: {
console.log("Settings | mouse cancelled")
preventStealing = !preventStealing
menuState = false
executeSelection()
}
onExited: {
console.log("Settings | mouse exited")
preventStealing = !preventStealing
menuState = false
executeSelection()
}
onMouseYChanged: {
var firstPoint = mapFromItem(darkModeOption, 0, 0)
var secondPoint = mapFromItem(lightModeOption, 0, 0)
var thirdPoint = mapFromItem(translucentModeOption, 0, 0)
var selectedItem
if (mouseY > firstPoint.y && mouseY < firstPoint.y + darkModeOption.height) {
selectedItem = darkModeOption
} else if (mouseY > secondPoint.y && mouseY < secondPoint.y + lightModeOption.height) {
selectedItem = lightModeOption
} else if (mouseY > thirdPoint.y && mouseY < thirdPoint.y + translucentModeOption.height) {
selectedItem = translucentModeOption
} else {
selectedItem = themeSettingsItemTitle
}
if (selectedMenuItem !== selectedItem) {
selectedMenuItem = selectedItem
if (selectedMenuItem !== themeSettingsItemTitle && mainView.useVibration) {
AN.SystemDispatcher.dispatch("volla.launcher.vibrationAction", {"duration": mainView.vibrationDuration})
}
}
}
function executeSelection() {
console.log("Settings | Current mode: " + Universal.theme + ", " + themeSettings.theme)
console.log("Settings | Execute mode selection: " + selectedMenuItem.text + ", " + selectedMenuItem.theme)
if (themeSettings.theme !== selectedMenuItem.theme && selectedMenuItem !== themeSettingsItemTitle) {
themeSettingsItemTitle.text = selectedMenuItem.text
themeSettings.theme = selectedMenuItem.theme
if (themeSettings.sync) {
themeSettings.sync()
}
switch (themeSettings.theme) {
case mainView.theme.Dark:
console.log("Setting | Enable dark mode")
mainView.switchTheme(mainView.theme.Dark, true)
break
case mainView.theme.Light:
console.log("Setting | Enable light mode")
mainView.switchTheme(mainView.theme.Light, true)
break
case mainView.theme.Translucent:
console.log("Setting | Enable translucent mode")
mainView.switchTheme(mainView.theme.Translucent, true)
break
default:
console.log("Settings | Unknown theme selected: " + themeSettings.theme)
}
selectedMenuItem = themeSettingsItemTitle
}
}
Settings {
id: themeSettings
property int theme: mainView.theme.Dark
}
}
MouseArea {
id: securitySettingsItem
width: parent.width
implicitHeight: securitySettingsItemColumn.height
preventStealing: true
property var selectedMenuItem: securitySettingsItemTitle
property bool menuState: false
property double labelOpacity: 0.0
Column {
id: securitySettingsItemColumn
width: parent.width
Button {
id: securitySettingsItemTitle
property var isActiveSecurityMode: false
enabled: false
padding: mainView.innerSpacing
width: parent.width
text: qsTr("Security mode is OFF")
contentItem: Row {
Text {
text: securitySettingsItemTitle.text
width: parent.width - securitySettingsItemTitleIcon.width - mainView.innerSpacing
font.pointSize: mainView.largeFontSize
font.weight: securitySettingsItem.menuState ? Font.Black : Font.Normal
color: securitySettingsItem.menuState ? "white" : Universal.foreground
}
Image {
id: securitySettingsItemTitleIcon
source: Qt.resolvedUrl("icons/[email protected]")
visible: false
ColorOverlay {
anchors.fill: securitySettingsItemTitleIcon
source: securitySettingsItemTitleIcon
color: mainView.fontColor
}
}
}
background: Rectangle {
anchors.fill: parent
color: securitySettingsItem.menuState === true ? mainView.accentColor : "transparent"
}
onTextChanged: {
securitySettingsItemTitleIcon.visible = text === securityModeOnOption.text
}
}
Button {
id: securityModeOffOption
property var isActiveSecurityMode: false
leftPadding: mainView.innerSpacing
rightPadding: mainView.innerSpacing
bottomPadding: mainView.innerSpacing
width: parent.width
visible: securitySettingsItem.menuState
text: qsTr("Security mode is OFF")
contentItem: Text {
text: securityModeOffOption.text
font.pointSize: mainView.mediumFontSize
font.weight: securitySettingsItem.selectedMenuItem === securityModeOffOption ? Font.Black : Font.Normal
color: "white"
opacity: securitySettingsItem.labelOpacity
}
background: Rectangle {
anchors.fill: parent
color: securitySettingsItem.menuState ? mainView.accentColor : "transparent"
}
}
Button {
id: securityModeOnOption
property var isActiveSecurityMode: true
leftPadding: mainView.innerSpacing
rightPadding: mainView.innerSpacing
bottomPadding: mainView.innerSpacing
width: parent.width
visible: securitySettingsItem.menuState
text: qsTr("Security mode is ON")
contentItem: Row {
Text {
text: securityModeOnOption.text
width: parent.width - securityModeOnOptionIcon.width - mainView.innerSpacing
font.pointSize: mainView.mediumFontSize
font.weight: securitySettingsItem.selectedMenuItem === securityModeOnOption ? Font.Black : Font.Normal
color: "white"
opacity: securitySettingsItem.labelOpacity
}
Image {
id: securityModeOnOptionIcon
source: Qt.resolvedUrl("icons/[email protected]")
}
}
background: Rectangle {
anchors.fill: parent
color: securitySettingsItem.menuState ? mainView.accentColor : "transparent"
}
}
}
Behavior on implicitHeight {
NumberAnimation {
duration: 250.
onRunningChanged: {
if (!running && securitySettingsItem.menuState) {
console.log("Settings | Switch on security options labels")
securitySettingsItem.labelOpacity = 1.0
} else if (running && !securitySettingsItem.menuState) {
console.log("Settings | Switch off security option labels")
securitySettingsItem.labelOpacity = 0.0
}
}
}
}
Behavior on labelOpacity {
NumberAnimation {
duration: 250
}
}
onEntered: {
console.log("Settings | mouse entered")
preventStealing = !preventStealing
menuState = true
}
onCanceled: {
console.log("Settings | mouse cancelled")
preventStealing = !preventStealing
menuState = false
executeSelection()
}
onExited: {
console.log("Settings | mouse exited")
preventStealing = !preventStealing
menuState = false
executeSelection()
}
onMouseYChanged: {
var firstPoint = mapFromItem(securityModeOffOption, 0, 0)
var secondPoint = mapFromItem(securityModeOnOption, 0, 0)
var selectedItem
if (mouseY > firstPoint.y && mouseY < firstPoint.y + securityModeOffOption.height) {
selectedItem = securityModeOffOption
} else if (mouseY > secondPoint.y && mouseY < secondPoint.y + securityModeOnOption.height) {
selectedItem = securityModeOnOption
} else {
selectedItem = securitySettingsItemTitle
}
if (selectedMenuItem !== selectedItem) {
selectedMenuItem = selectedItem
if (selectedMenuItem !== securitySettingsItemTitle && mainView.useVibration) {
AN.SystemDispatcher.dispatch("volla.launcher.vibrationAction", {"duration": mainView.vibrationDuration})
}
}
}
function executeSelection() {
console.log("Settings | Execute mode selection: " + selectedMenuItem.text)
if (securitySettingsItemTitle.text !== selectedMenuItem.text) {
if (selectedMenuItem.text === securityModeOnOption.text) {
// Check, if password is set
AN.SystemDispatcher.dispatch("volla.launcher.checkSecurityPasswordAction", {})
} else if (selectedMenuItem.text === securityModeOffOption.text) {
passwordDialog.backgroundColor = mainView.fontColor.toString() === "white" || mainView.fontColor.toString() === "#ffffff"
? "#292929" : "#CCCCCC"
passwordDialog.definePasswordMode = false
passwordDialog.isPasswordSet = true
passwordDialog.open()
}
}
}
Dialog {
id: passwordDialog
anchors.centerIn: parent
width: parent.width - mainView.innerSpacing * 4
modal: true
dim: false
property var backgroundColor: "#292929"
property bool definePasswordMode: false
property bool isPasswordSet: false
onOpened: {
passwordField.text = ""
confirmationField.text = ""
height: dialogTitle.height + passwordField.height +
dialogLabel.height + confirmationField.height +
keepPasswordCheckBox.height + okButton.height +
mainView.innerSpacing * 2
}
background: Rectangle {
anchors.fill: parent
color: passwordDialog.backgroundColor
border.color: "transparent"
radius: mainView.innerSpacing / 2
}
enter: Transition {
NumberAnimation { property: "opacity"; from: 0.0; to: 1.0 }
}
exit: Transition {
NumberAnimation { property: "opacity"; from: 1.0; to: 0.0 }
}
contentItem: Column {
id: dialogColumn
Label {
id: dialogTitle
text: qsTr("Enter password")
color: mainView.fontColor
font.pointSize: mainView.mediumFontSize
bottomPadding: mainView.innerSpacing
background: Rectangle {
color: "transparent"
border.color: "transparent"
}
}
TextField {
id: passwordField
echoMode: TextField.Password
width: parent.width
color: mainView.fontColor
placeholderTextColor: "darkgrey"
font.pointSize: mainView.mediumFontSize
background: Rectangle {
color: mainView.fontColor.toString() === "white" || mainView.fontColor.toString() === "#ffffff"
? "black" : "white"
border.color: "transparent"
}
}
Label {
id: dialogLabel
text: qsTr("Repeat password")
color: mainView.fontColor
topPadding: mainView.innerSpacing
bottomPadding: mainView.innerSpacing
font.pointSize: mainView.mediumFontSize
visible: passwordDialog.definePasswordMode
background: Rectangle {
color: "transparent"
border.color: "transparent"
}
}
TextField {
id: confirmationField
echoMode: TextField.Password
width: parent.width
color: mainView.fontColor
placeholderTextColor: "darkgrey"
font.pointSize: mainView.mediumFontSize
visible: passwordDialog.definePasswordMode
background: Rectangle {
color: mainView.fontColor.toString() === "white" || mainView.fontColor.toString() === "#ffffff"
? "black" : "white"
border.color: "transparent"
}
}
CheckBox {
id: keepPasswordCheckBox
width: parent.width
topPadding: mainView.innerSpacing
text: qsTr("Keep existing Password")
checked: passwordDialog.isPasswordSet
visible: passwordDialog.definePasswordMode
contentItem: Text {
text: keepPasswordCheckBox.text
wrapMode: Text.WordWrap
width: parent.width - leftPadding
leftPadding: 2 * mainView.innerSpacing
color: mainView.fontColor
font.pointSize: mainView.mediumFontSize
}
}
Row {
width: parent.width
topPadding: mainView.innerSpacing
spacing: mainView.innerSpacing
Button {
id: cancelButton
flat: true
padding: mainView.innerSpacing / 2
width: parent.width / 2 - mainView.innerSpacing / 2
text: qsTr("Cancel")
contentItem: Text {
text: cancelButton.text
color: mainView.fontColor
font.pointSize: mainView.mediumFontSize
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {
color: "transparent"
border.color: "gray"
}
onClicked: {
securitySettingsItem.selectedMenuItem = securitySettingsItemTitle
passwordDialog.close()
}
}
Button {
id: okButton
width: parent.width / 2 - mainView.innerSpacing / 2
padding: mainView.innerSpacing / 2
flat: true
text: qsTr("Ok")
contentItem: Text {
text: okButton.text
color: mainView.fontColor
font.pointSize: mainView.mediumFontSize
horizontalAlignment: Text.AlignHCenter
}
background: Rectangle {
color: "transparent"
border.color: "gray"
}
onClicked: {
if (passwordDialog.definePasswordMode && !keepPasswordCheckBox.checked
&& passwordField.text !== confirmationField.text) {
mainView.showToast(qsTr("Wrong password confirmation"))
} else if (passwordDialog.definePasswordMode && !keepPasswordCheckBox.checked
&& passwordField.text.length < 5) {
mainView.showToast(qsTr("Password needs at least four characters or numbers"))
} else {
AN.SystemDispatcher.dispatch(
"volla.launcher.securityModeAction",
{"password": passwordField.text,
"keepPassword": keepPasswordCheckBox.checked,
"activate": securitySettingsItem.selectedMenuItem === securityModeOnOption})
passwordDialog.close()
}
}
}
}
}
}
Connections {
target: AN.SystemDispatcher
onDispatched: {
if (type === "volla.launcher.securityModeResponse") {
if (message["succeeded"]) {
securitySettingsItemTitle.text = securitySettingsItem.selectedMenuItem.text
securitySettingsItemTitle.isActiveSecurityMode = securitySettingsItem.selectedMenuItem.isActiveSecurityMode
securitySettingsItem.selectedMenuItem = securitySettingsItemTitle
AN.SystemDispatcher.dispatch("volla.launcher.appCountAction", {})
} else {
securitySettingsItem.selectedMenuItem = securitySettingsItemTitle
mainView.showToast(qsTr("Wrong password"))
}
} else if (type === "volla.launcher.securityStateResponse") {
console.log("Settings | Security state: " + message["isActive"] + ", " + message["error"])
securitySettingsItemTitle.text = message["isActive"] ? securityModeOnOption.text
: securityModeOffOption.text
securitySettingsItem.visible = message["error"] === undefined && message["isInstalled"] && message["isAvailable"]
} else if (type === "volla.launcher.checkSecurityPasswordResponse") {
console.log("Settings | Password is set: " + message["isPasswordSet"])
passwordDialog.backgroundColor = mainView.fontColor.toString() === "white" || mainView.fontColor.toString() === "#ffffff"
? "#292929" : "#CCCCCC"
passwordDialog.definePasswordMode = true
passwordDialog.isPasswordSet = message["isPasswordSet"]
passwordDialog.open()
}
}
}
}
Item {
id: newsSettingsItem
width: parent.width
implicitHeight: newsSettingsItemColumn.height
Column {
id: newsSettingsItemColumn
width: parent.width
property bool menuState: false
property var newsCheckboxes: new Array
HighlightButton {
id: newsSettingsItemTitle
width: parent.width
padding: mainView.innerSpacing
text: qsTr("News Channels")
boldText: newsSettingsItemColumn.menuState
onClicked: {
newsSettingsItemColumn.menuState = !newsSettingsItemColumn.menuState
if (newsSettingsItemColumn.menuState) {
console.log("Settings | Will create new checkboxes")
newsSettingsItemColumn.createCheckboxes()
settingsColumn.closeAllItemsExcept(newsSettingsItemColumn)
} else {
console.log("Settings | Will destroy new checkboxes")
newsSettingsItemColumn.destroyCheckboxes()
}
}
}
function createCheckboxes() {
var cannels = mainView.getFeeds()
for (var i = 0; i < cannels.length; i++) {
var component = Qt.createComponent("/Checkbox.qml", newsSettingsItemColumn)
var properties = { "actionId": cannels[i]["id"],
"text": cannels[i]["name"], "activeCheckbox": false, "checked": cannels[i]["activated"],
"labelFontSize": mainView.mediumFontSize, "circleSize": mainView.largeFontSize,
"leftPadding": mainView.innerSpacing, "rightPadding": mainView.innerSpacing,
"bottomPadding": mainView.innerSpacing / 2, "topPadding": mainView.innerSpacing / 2,
"hasRemoveButton": true, "accentColor": mainView.accentColor }
var object = component.createObject(newsSettingsItemColumn, properties)
object.activeCheckbox = true
newsSettingsItemColumn.newsCheckboxes.push(object)
}
console.log("Settings News checkboxes created")
}
function destroyCheckboxes() {
for (var i = 0; i < newsSettingsItemColumn.newsCheckboxes.length; i++) {
var checkbox = newsSettingsItemColumn.newsCheckboxes[i]
checkbox.destroy()
}
newsSettingsItemColumn.newsCheckboxes = new Array
}
function updateSettings(channelId, active) {
console.log("Settings | Update settings for " + channelId + ", " + active)
mainView.updateFeed(channelId, active, mainView.settingsAction.UPDATE)
}
function removeSettings(channelId) {
console.log("Settings | Remove settings for " + channelId)
mainView.updateFeed(channelId, false, mainView.settingsAction.REMOVE)
for (var i = 0; i < newsSettingsItemColumn.newsCheckboxes.length; i++) {
var checkbox = newsSettingsItemColumn.newsCheckboxes[i]
if (checkbox.actionId === channelId) {
newsCheckboxes.splice(i, 1)
checkbox.destroy()
}
}
}
}
Behavior on implicitHeight {
NumberAnimation {
duration: 250.0
}
}
}
Item {
id: shortcutSettingsItem
width: parent.width
implicitHeight: shortcutSettingsItemColumn.height
Column {
id: shortcutSettingsItemColumn
width: parent.width
property bool menuState: false
property var checkboxes: new Array
HighlightButton {
id: shortcutSettingsItemButton
width: parent.width
padding: mainView.innerSpacing
text: qsTr("Shortcuts")
boldText: shortcutSettingsItemColumn.menuState
onClicked: {
shortcutSettingsItemColumn.menuState = !shortcutSettingsItemColumn.menuState
if (shortcutSettingsItemColumn.menuState) {
console.log("Settings | Will create checkboxes")
shortcutSettingsItemColumn.createCheckboxes()
settingsColumn.closeAllItemsExcept(shortcutSettingsItemColumn)
} else {
console.log("Settings | Will destroy checkboxes")
shortcutSettingsItemColumn.destroyCheckboxes()
}
}
}
function createCheckboxes() {
var shortcuts = mainView.getActions()
for (var i = 0; i < shortcuts.length; i++) {
var component = Qt.createComponent("/Checkbox.qml", shortcutSettingsItemColumn)
var properties = { "actionId": shortcuts[i]["id"],
"text": shortcuts[i]["name"], "checked": shortcuts[i]["activated"],
"labelFontSize": mainView.mediumFontSize, "circleSize": mainView.largeFontSize,
"leftPadding": mainView.innerSpacing, "rightPadding": mainView.innerSpacing,
"bottomPadding": mainView.innerSpacing / 2, "topPadding": mainView.innerSpacing / 2,
"hasRemoveButton": getFilteredShortcuts(mainView.defaultActions, "id", shortcuts[i]["id"]).length === 0,
"accentColor": mainView.accentColor }
var object = component.createObject(shortcutSettingsItemColumn, properties)
object.activeCheckbox = true
shortcutSettingsItemColumn.checkboxes.push(object)
}
addButton.visible = true
console.log("Settings | Checkboxes created")
}
function addCheckbox(actionId, label) {
var component = Qt.createComponent("/Checkbox.qml", shortcutSettingsItemColumn)
var properties = { "actionId": actionId, "text": label, "checked": true,
"labelFontSize": mainView.mediumFontSize, "circleSize": mainView.largeFontSize,
"leftPadding": mainView.innerSpacing, "rightPadding": mainView.innerSpacing,
"bottomPadding": mainView.innerSpacing / 2, "topPadding": mainView.innerSpacing / 2,
"hasRemoveButton": true, "accentColor": mainView.accentColor }
var object = component.createObject(shortcutSettingsItemColumn, properties)
object.activeCheckbox = true
shortcutSettingsItemColumn.checkboxes.push(object)
}
function getFilteredShortcuts(array, key, value) {
return array.filter(function(e) {
return e[key] === value;
});
}
function destroyCheckboxes() {
for (var i = 0; i < shortcutSettingsItemColumn.checkboxes.length; i++) {
var checkbox = shortcutSettingsItemColumn.checkboxes[i]
checkbox.destroy()
}
addButton.visible = false
shortcutSettingsItemColumn.checkboxes = new Array
}
function updateSettings(actionId, active) {
console.log("Settings | Update settings for " + actionId + ", " + active)
mainView.updateAction(actionId, active, mainView.settingsAction.UPDATE)
}
function removeSettings(actionId) {
console.log("Settings | Remove settings for " + actionId)
mainView.updateAction(actionId, false, mainView.settingsAction.REMOVE)
for (var i = 0; i < shortcutSettingsItemColumn.checkboxes.length; i++) {
var checkbox = shortcutSettingsItemColumn.checkboxes[i]
if (checkbox.actionId === actionId) {
checkboxes.splice(i, 1)
checkbox.destroy()
}
}
}
}
Behavior on implicitHeight {
NumberAnimation {
duration: 250.0
}
}
}
Button {
id: addButton
leftPadding: mainView.innerSpacing + 6.0
rightPadding: mainView.innerSpacing
bottomPadding: mainView.innerSpacing / 2
flat: true
text: "+"
font.pointSize: mainView.largeFontSize
visible: false
onClicked: {
appMenuModel.setData(mainView.getApps())
appMenu.popup(settingsPage)
}
Menu {
id: appMenu
property double fontSize: mainView.largeFontSoze / 72 * Screen.pixelDensity * 25.4
background: Rectangle {
implicitHeight: contentItem.height
implicitWidth: 200
color: mainView.accentColor
radius: mainView.innerSpacing
}
contentItem: ListView {
id: appList
delegate: Button {
width: parent.width
leftPadding: mainView.innerSpacing
rightPadding: mainView.innerSpacing
topPadding: mainView.innerSpacing
bottomPadding: index === appMenuModel.count - 1 ? mainView.innerSpacing : 0
flat: true
contentItem: Text {
text: model.label
color: mainView.fontColor
font.pointSize: mainView.mediumFontSize
elide: Text.ElideRight
}
background: Rectangle {
anchors.fill: parent
color: "transparent"
}
onClicked: {
console.log("Settings | App " + model["label"] + " selected for shortcuts");
mainView.updateAction(
model["package"], true, mainView.settingsAction.CREATE,
{"id": model["package"], "name": qsTr("Open") + " " + model["label"], "activated": true} )
appMenuModel.append(
{"id": model["package"], "name": qsTr("Open") + " " + model["label"], "activated": true} )
var component = Qt.createComponent("/Checkbox.qml", shortcutSettingsItemColumn)
var properties = { "actionId": model["package"],
"text": qsTr("Open") + " " + model["label"], "checked": true,
"labelFontSize": mainView.mediumFontSize, "circleSize": mainView.largeFontSize,
"leftPadding": mainView.innerSpacing, "rightPadding": mainView.innerSpacing,
"bottomPadding": mainView.innerSpacing / 2, "topPadding": mainView.innerSpacing / 2,
"hasRemoveButton": true, "accentColor": mainView.accentColor }
var object = component.createObject(shortcutSettingsItemColumn, properties)
shortcutSettingsItemColumn.checkboxes.push(object)
appMenu.close()
}
}
model: appMenuModel
}
}
ListModel {
id: appMenuModel
function setData(data) {
console.log("Settings | Menu size is " + data.length)
clear()
for (var i = 0; i < data.length; i++) {
append(data[i])
}
}
}
}
Item {
id: sourceSettingsItem
width: parent.width
implicitHeight: sourceSettingsItemColumn.height
visible: true
Column {
id: sourceSettingsItemColumn
width: parent.width
property bool menuState: false
property var checkboxes: new Array
HighlightButton {
id: sourceSettingsItemButton
width: parent.width
padding: mainView.innerSpacing
boldText: sourceSettingsItemColumn.menuState
text: qsTr("Source settings")
onClicked: {
sourceSettingsItemColumn.menuState = !sourceSettingsItemColumn.menuState
if (sourceSettingsItemColumn.menuState) {
console.log("Settings | Will create checkboxes")
sourceSettingsItemColumn.createCheckboxes()
settingsColumn.closeAllItemsExcept(sourceSettingsItemColumn)
} else {
console.log("Settings | Will destroy checkboxes")
sourceSettingsItemColumn.destroyCheckboxes()
}
}
}
function createCheckboxes() {
var component = Qt.createComponent("/Checkbox.qml", sourceSettingsItemColumn)
var properties = { "actionId": "signal",
"text": qsTr("Signal"), "checked": sourceSettings.signalIsActivated,
"labelFontSize": mainView.mediumFontSize, "circleSize": mainView.largeFontSize,
"leftPadding": mainView.innerSpacing, "rightPadding": mainView.innerSpacing,
"bottomPadding": mainView.innerSpacing / 2, "topPadding": mainView.innerSpacing / 2,
"accentColor": mainView.accentColor}
var object = component.createObject(sourceSettingsItemColumn, properties)
object.activeCheckbox = true
sourceSettingsItemColumn.checkboxes.push(object)
}
function destroyCheckboxes() {
for (var i = 0; i < sourceSettingsItemColumn.checkboxes.length; i++) {
var checkbox = sourceSettingsItemColumn.checkboxes[i]
checkbox.destroy()
}
sourceSettingsItemColumn.checkboxes = new Array
}
function updateSettings(actionId, active) {
console.log("Settings | Update settings for " + actionId + ", " + active)
if (actionId === "signal") {
AN.SystemDispatcher.dispatch("volla.launcher.signalEnable", { "enableSignal": active})
mainView.updateSettings("activateSignal", active)
sourceSettings.signalIsActivated = active
mainView.isActiveSignal = active
}
}
Settings {
id: sourceSettings
property bool signalIsActivated: false
}
Connections {
target: AN.SystemDispatcher