-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLightControl.qml
More file actions
791 lines (725 loc) · 32.2 KB
/
LightControl.qml
File metadata and controls
791 lines (725 loc) · 32.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
import QtQuick 2.7
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
import QtQuick.Dialogs 1.3
import QtGraphicalEffects 1.0
import LightModel 1.0
RowLayout {
property var currentRenderer: undefined
function connectToRenderer(renderer) {
currentRenderer = renderer
listView.model = renderer.lightModel
}
function humanize(x, precision) {
return x.toFixed(precision).replace(/\.?0*$/, '');
}
function bindControls() {
//=========================
//===== Light type
//=========================
lightType.currentIndex = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? listView.model.getLightProperty(listView.currentIndex, LightModel.LightType) : -1
})
//=========================
//===== Light visibility
//=========================
lightVisibility.checked = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? listView.model.getLightProperty(listView.currentIndex, LightModel.Visibility) : false
})
//=========================
//===== Light pilot mode
//=========================
lightPilotMode.checked = Qt.binding(function() {
return currentRenderer.lightPilotMode
})
//=========================
//===== Light direction
//=========================
directionGridLayout.visible = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? listView.model.getLightProperty(listView.currentIndex, LightModel.LightType) !== Light.PointLight : true
})
directionX.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.Direction).x, 5) : ""
})
directionY.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.Direction).y, 5) : ""
})
directionZ.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.Direction).z, 5) : ""
})
//=========================
//===== Light position
//=========================
positionX.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.Position).x, 5) : ""
})
positionY.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.Position).y, 5) : ""
})
positionZ.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.Position).z, 5) : ""
})
//=========================
//===== Light color
//=========================
colorRectangle.color = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? listView.model.getLightProperty(listView.currentIndex, LightModel.Color) : "black"
})
red.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? Math.floor(listView.model.getLightProperty(listView.currentIndex, LightModel.Color).r * 255) : ""
})
green.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? Math.floor(listView.model.getLightProperty(listView.currentIndex, LightModel.Color).g * 255) : ""
})
blue.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? Math.floor(listView.model.getLightProperty(listView.currentIndex, LightModel.Color).b * 255) : ""
})
//=========================
//===== Light brightness
//=========================
brightness.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.Brightness), 5) : ""
})
//=========================
//===== Light attenuation radius
//=========================
attenuation.visible = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? listView.model.getLightProperty(listView.currentIndex, LightModel.LightType) !== Light.DirectionalLight : true
})
attenuationLabel.visible = Qt.binding(function() { return attenuation.visible })
attenuation.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.AttenuationRadius), 5) : ""
})
//=========================
//===== Light inner cone angle
//=========================
innerConeAngle.visible = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? listView.model.getLightProperty(listView.currentIndex, LightModel.LightType) === Light.SpotLight : true
})
innerConeAngleLabel.visible = Qt.binding(function() { return innerConeAngle.visible })
innerConeAngle.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.InnerConeAngle), 5) : ""
})
//=========================
//===== Light outer cone angle
//=========================
outerConeAngle.visible = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? listView.model.getLightProperty(listView.currentIndex, LightModel.LightType) === Light.SpotLight : true
})
outerConeAngleLabel.visible = Qt.binding(function() { return outerConeAngle.visible })
outerConeAngle.placeholderText = Qt.binding(function() {
var counter = listView.model.updateCounter
return listView.currentItem != undefined? humanize(listView.model.getLightProperty(listView.currentIndex, LightModel.OuterConeAngle), 5) : ""
})
}
Rectangle {
id: lightsCreatedPanel
Layout.preferredWidth: lightPropertiesPanel.width
Layout.preferredHeight: 500
color: "#858585"
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
ListModel {
id: testModel
ListElement {
name: "Sun"
}
ListElement {
name: "Light 1"
}
ListElement {
name: "Light 2"
}
}
ColumnLayout {
spacing: 0
anchors.fill: parent
Rectangle {
id: header
implicitHeight: rowLayout.implicitHeight + 10
color: "#707070"
Layout.fillWidth: true
RowLayout {
id: rowLayout
anchors.top: parent.top
anchors.right: parent.right
anchors.left: parent.left
anchors.margins: 5
TextField {
id: lightName
text: ""
placeholderText: "Light name"
Layout.maximumWidth: 160
Layout.minimumWidth: 160
maximumLength: 20
font.pointSize: 8
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
addButton.clicked()
}
}
Item {
Layout.fillHeight: true
Layout.fillWidth: true
}
Button {
id: addButton
background: Image {
id: addButtonImage
sourceSize.height: 25
sourceSize.width: 25
source: "Button icons/plus.png"
}
Glow {
visible: addButton.hovered || addButton.pressed
color: "#ff88bb88"
radius: 20
samples: 40
anchors.fill: addButton
source: addButtonImage
}
scale: addButton.pressed? 0.9 : 1.0
onClicked: {
if (listView.model.rowCount() < 25 && lightName.text != "")
{
listView.model.append({ name: lightName.text })
lightName.text = ""
}
}
}
Button {
id: removeButton
background: Image {
id: removeButtonImage
sourceSize.height: 25
sourceSize.width: 25
source: "Button icons/minus.png"
}
Glow {
visible: removeButton.hovered || removeButton.pressed
color: "#ffbb8888"
radius: 20
samples: 40
anchors.fill: removeButton
source: removeButtonImage
}
scale: removeButton.pressed? 0.9 : 1.0
onClicked: {
if (listView.currentItem != undefined)
{
listView.model.remove(listView.currentIndex)
}
}
}
}
}
ListView {
id: listView
Layout.fillHeight: true
Layout.fillWidth: true
boundsBehavior: Flickable.StopAtBounds
clip: true
spacing: 1
delegate: Rectangle {
anchors.left: parent.left
anchors.right: parent.right
height: 25
color: "#959595aa"
Flow {
anchors.fill: parent
padding: 5
Text {
text: name
font.pointSize: 8
verticalAlignment: Text.AlignVCenter
}
}
MouseArea {
anchors.fill: parent
onClicked: {
listView.currentIndex = index
currentRenderer.currentLight = index
bindControls()
}
}
}
highlight: Rectangle {
color: "#c5c5c5"
}
}
}
}
GroupBox {
id: lightPropertiesPanel
Layout.alignment: Qt.AlignLeft | Qt.AlignTop
ColumnLayout {
spacing: 10
GridLayout {
flow: GridLayout.TopToBottom
rows: 2
columns: 3
Text {
text: "Light type"
font.pointSize: 8
}
ComboBox {
id: lightType
model: ["Point light", "Directional light", "Spot light"]
currentIndex: -1
onCurrentIndexChanged: {
if (listView.currentItem != undefined)
{
listView.model.setLightProperty(listView.currentIndex, currentIndex, LightModel.LightType)
bindControls()
}
}
}
CheckBox {
id: lightVisibility
text: "Visibile"
Layout.columnSpan: 2
onClicked: {
if (listView.currentItem != undefined)
{
listView.model.setLightProperty(listView.currentIndex, checked, LightModel.Visibility)
}
}
}
Switch {
id: lightPilotMode
text: "Pilot light"
Layout.columnSpan: 2
ToolTip.visible: hovered
ToolTip.delay: 1000
ToolTip.text: "Ustawia pozycję i kierunek aktualnie wybranego światła na podstawie pozycji oraz rotacji kamery.\n" +
"Użyj tej opcji, aby szybciej rozstawić oświetlenie na scenie 3D."
onClicked: {
currentRenderer.lightPilotMode = !currentRenderer.lightPilotMode
}
}
}
GridLayout {
columns: 6
rows: 2
Text {
text: "Position"
padding: 15
Layout.columnSpan: 6
font.pointSize: 8
}
Text {
text: "X"
font.pointSize: 8
}
TextField {
id: positionX
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {}
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousPosition = listView.model.getLightProperty(listView.currentIndex, LightModel.Position)
var x = Number(positionX.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, Qt.vector3d(x, previousPosition.y, previousPosition.z), LightModel.Position)
text = ""
}
}
}
Text {
text: "Y"
font.pointSize: 8
}
TextField {
id: positionY
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {}
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousPosition = listView.model.getLightProperty(listView.currentIndex, LightModel.Position)
var y = Number(positionY.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, Qt.vector3d(previousPosition.x, y, previousPosition.z), LightModel.Position)
text = ""
}
}
}
Text {
text: "Z"
font.pointSize: 8
}
TextField {
id: positionZ
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {}
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousPosition = listView.model.getLightProperty(listView.currentIndex, LightModel.Position)
var z = Number(positionZ.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, Qt.vector3d(previousPosition.x, previousPosition.y, z), LightModel.Position)
text = ""
}
}
}
}
GridLayout {
id: directionGridLayout
columns: 6
rows: 2
Text {
text: "Direction"
Layout.columnSpan: 6
font.pointSize: 8
}
Text {
text: "X"
font.pointSize: 8
}
TextField {
id: directionX
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {}
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousDirection = listView.model.getLightProperty(listView.currentIndex, LightModel.Direction)
var x = Number(directionX.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, Qt.vector3d(x, previousDirection.y, previousDirection.z), LightModel.Direction)
text = ""
}
}
}
Text {
text: "Y"
font.pointSize: 8
}
TextField {
id: directionY
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {}
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousDirection = listView.model.getLightProperty(listView.currentIndex, LightModel.Direction)
var y = Number(directionY.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, Qt.vector3d(previousDirection.x, y, previousDirection.z), LightModel.Direction)
text = ""
}
}
}
Text {
text: "Z"
font.pointSize: 8
}
TextField {
id: directionZ
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {}
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousDirection = listView.model.getLightProperty(listView.currentIndex, LightModel.Direction)
var z = Number(directionZ.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, Qt.vector3d(previousDirection.x, previousDirection.y, z), LightModel.Direction)
text = ""
}
}
}
}
RowLayout {
ColumnLayout {
Text {
text: "Color"
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.columnSpan: 1
font.pointSize: 8
}
Button {
background: Rectangle {
id: colorRectangle
border.width: 1
}
Layout.preferredHeight: 50
Layout.preferredWidth: 50
ToolTip.visible: hovered
ToolTip.delay: 1000
ToolTip.text: "Kliknij lewym przyciskiem myszy,\naby otworzyć narzędzie do wybierania koloru."
onClicked: {
colorDialog.open()
}
}
}
Item {
Layout.preferredWidth: 15
}
GridLayout {
columns: 2
rows: 3
Text {
text: "Red"
font.pointSize: 8
}
TextField {
id: red
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {
top: 255
bottom: 0
}
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousColor = listView.model.getLightProperty(listView.currentIndex, LightModel.Color)
var r = Number(red.text.replace(',', '.')) / 255
listView.model.setLightProperty(listView.currentIndex, Qt.rgba(r, previousColor.g, previousColor.b, 1), LightModel.Color)
text = ""
}
}
}
Text {
text: "Green"
font.pointSize: 8
}
TextField {
id: green
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {
top: 255
bottom: 0
}
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousColor = listView.model.getLightProperty(listView.currentIndex, LightModel.Color)
var g = Number(green.text.replace(',', '.')) / 255
listView.model.setLightProperty(listView.currentIndex, Qt.rgba(previousColor.r, g, previousColor.b, 1), LightModel.Color)
text = ""
}
}
}
Text {
text: "Blue"
font.pointSize: 8
}
TextField {
id: blue
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {
top: 255
bottom: 0
}
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var previousColor = listView.model.getLightProperty(listView.currentIndex, LightModel.Color)
var b = Number(blue.text.replace(',', '.')) / 255
listView.model.setLightProperty(listView.currentIndex, Qt.rgba(previousColor.r, previousColor.g, b, 1), LightModel.Color)
text = ""
}
}
}
}
ColorDialog {
id: colorDialog
title: "Please choose a color"
onCurrentColorChanged: {
if (listView.currentItem != undefined)
{
listView.model.setLightProperty(listView.currentIndex, colorDialog.currentColor, LightModel.Color)
}
}
}
Item {
Layout.preferredWidth: 15
}
ColumnLayout {
spacing: 1
Text {
id: innerConeAngleLabel
text: "Inner cone\nangle"
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.columnSpan: 1
font.pointSize: 8
}
TextField {
id: innerConeAngle
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {
top: 360
bottom: 0
}
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var value = Number(innerConeAngle.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, value, LightModel.InnerConeAngle)
text = ""
}
}
}
Text {
id: outerConeAngleLabel
text: "Outer cone\nangle"
horizontalAlignment: Text.AlignHCenter
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.columnSpan: 1
font.pointSize: 8
}
TextField {
id: outerConeAngle
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {
top: 360
bottom: 0
}
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var value = Number(outerConeAngle.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, value, LightModel.OuterConeAngle)
text = ""
}
}
}
Text {
text: "Brightness"
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.columnSpan: 1
font.pointSize: 8
}
TextField {
id: brightness
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {
bottom: 0
}
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var value = Number(brightness.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, value, LightModel.Brightness)
text = ""
}
}
}
Text {
id: attenuationLabel
text: "Attenuation\nradius"
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
Layout.alignment: Qt.AlignHCenter | Qt.AlignVCenter
Layout.columnSpan: 1
font.pointSize: 8
}
TextField {
id: attenuation
Layout.maximumWidth: 80
Layout.minimumWidth: 80
maximumLength: 10
font.pointSize: 8
validator: DoubleValidator {
bottom: 0
}
inputMethodHints: Qt.ImhFormattedNumbersOnly
selectByMouse: true
font.family: "Arial"
onEditingFinished: {
if (listView.currentItem != undefined)
{
var value = Number(attenuation.text.replace(',', '.'))
listView.model.setLightProperty(listView.currentIndex, value, LightModel.AttenuationRadius)
text = ""
}
}
}
}
}
}
}
}