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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
|
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.4
import QtTest 1.0
import QtQuick.Controls 2.2
import QtQuick.Templates 2.2 as T
TestCase {
id: testCase
width: 400
height: 400
visible: true
when: windowShown
name: "Popup"
ApplicationWindow {
id: applicationWindow
width: 480
height: 360
}
Component {
id: popupTemplate
T.Popup { }
}
Component {
id: popupControl
Popup { }
}
Component {
id: rect
Rectangle { }
}
Component {
id: signalSpy
SignalSpy { }
}
function test_padding() {
var control = createTemporaryObject(popupTemplate, testCase)
verify(control)
var paddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "paddingChanged"})
verify(paddingSpy.valid)
var topPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "topPaddingChanged"})
verify(topPaddingSpy.valid)
var leftPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "leftPaddingChanged"})
verify(leftPaddingSpy.valid)
var rightPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "rightPaddingChanged"})
verify(rightPaddingSpy.valid)
var bottomPaddingSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "bottomPaddingChanged"})
verify(bottomPaddingSpy.valid)
var paddingChanges = 0
var topPaddingChanges = 0
var leftPaddingChanges = 0
var rightPaddingChanges = 0
var bottomPaddingChanges = 0
compare(control.padding, 0)
compare(control.topPadding, 0)
compare(control.leftPadding, 0)
compare(control.rightPadding, 0)
compare(control.bottomPadding, 0)
compare(control.availableWidth, 0)
compare(control.availableHeight, 0)
control.width = 100
control.height = 100
control.padding = 10
compare(control.padding, 10)
compare(control.topPadding, 10)
compare(control.leftPadding, 10)
compare(control.rightPadding, 10)
compare(control.bottomPadding, 10)
compare(paddingSpy.count, ++paddingChanges)
compare(topPaddingSpy.count, ++topPaddingChanges)
compare(leftPaddingSpy.count, ++leftPaddingChanges)
compare(rightPaddingSpy.count, ++rightPaddingChanges)
compare(bottomPaddingSpy.count, ++bottomPaddingChanges)
control.topPadding = 20
compare(control.padding, 10)
compare(control.topPadding, 20)
compare(control.leftPadding, 10)
compare(control.rightPadding, 10)
compare(control.bottomPadding, 10)
compare(paddingSpy.count, paddingChanges)
compare(topPaddingSpy.count, ++topPaddingChanges)
compare(leftPaddingSpy.count, leftPaddingChanges)
compare(rightPaddingSpy.count, rightPaddingChanges)
compare(bottomPaddingSpy.count, bottomPaddingChanges)
control.leftPadding = 30
compare(control.padding, 10)
compare(control.topPadding, 20)
compare(control.leftPadding, 30)
compare(control.rightPadding, 10)
compare(control.bottomPadding, 10)
compare(paddingSpy.count, paddingChanges)
compare(topPaddingSpy.count, topPaddingChanges)
compare(leftPaddingSpy.count, ++leftPaddingChanges)
compare(rightPaddingSpy.count, rightPaddingChanges)
compare(bottomPaddingSpy.count, bottomPaddingChanges)
control.rightPadding = 40
compare(control.padding, 10)
compare(control.topPadding, 20)
compare(control.leftPadding, 30)
compare(control.rightPadding, 40)
compare(control.bottomPadding, 10)
compare(paddingSpy.count, paddingChanges)
compare(topPaddingSpy.count, topPaddingChanges)
compare(leftPaddingSpy.count, leftPaddingChanges)
compare(rightPaddingSpy.count, ++rightPaddingChanges)
compare(bottomPaddingSpy.count, bottomPaddingChanges)
control.bottomPadding = 50
compare(control.padding, 10)
compare(control.topPadding, 20)
compare(control.leftPadding, 30)
compare(control.rightPadding, 40)
compare(control.bottomPadding, 50)
compare(paddingSpy.count, paddingChanges)
compare(topPaddingSpy.count, topPaddingChanges)
compare(leftPaddingSpy.count, leftPaddingChanges)
compare(rightPaddingSpy.count, rightPaddingChanges)
compare(bottomPaddingSpy.count, ++bottomPaddingChanges)
control.padding = 60
compare(control.padding, 60)
compare(control.topPadding, 20)
compare(control.leftPadding, 30)
compare(control.rightPadding, 40)
compare(control.bottomPadding, 50)
compare(paddingSpy.count, ++paddingChanges)
compare(topPaddingSpy.count, topPaddingChanges)
compare(leftPaddingSpy.count, leftPaddingChanges)
compare(rightPaddingSpy.count, rightPaddingChanges)
compare(bottomPaddingSpy.count, bottomPaddingChanges)
}
function test_availableSize() {
var control = createTemporaryObject(popupTemplate, testCase)
verify(control)
var availableWidthSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableWidthChanged"})
verify(availableWidthSpy.valid)
var availableHeightSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "availableHeightChanged"})
verify(availableHeightSpy.valid)
var availableWidthChanges = 0
var availableHeightChanges = 0
control.width = 100
compare(control.availableWidth, 100)
compare(availableWidthSpy.count, ++availableWidthChanges)
compare(availableHeightSpy.count, availableHeightChanges)
control.height = 100
compare(control.availableHeight, 100)
compare(availableWidthSpy.count, availableWidthChanges)
compare(availableHeightSpy.count, ++availableHeightChanges)
control.padding = 10
compare(control.availableWidth, 80)
compare(control.availableHeight, 80)
compare(availableWidthSpy.count, ++availableWidthChanges)
compare(availableHeightSpy.count, ++availableHeightChanges)
control.topPadding = 20
compare(control.availableWidth, 80)
compare(control.availableHeight, 70)
compare(availableWidthSpy.count, availableWidthChanges)
compare(availableHeightSpy.count, ++availableHeightChanges)
control.leftPadding = 30
compare(control.availableWidth, 60)
compare(control.availableHeight, 70)
compare(availableWidthSpy.count, ++availableWidthChanges)
compare(availableHeightSpy.count, availableHeightChanges)
control.rightPadding = 40
compare(control.availableWidth, 30)
compare(control.availableHeight, 70)
compare(availableWidthSpy.count, ++availableWidthChanges)
compare(availableHeightSpy.count, availableHeightChanges)
control.bottomPadding = 50
compare(control.availableWidth, 30)
compare(control.availableHeight, 30)
compare(availableWidthSpy.count, availableWidthChanges)
compare(availableHeightSpy.count, ++availableHeightChanges)
control.padding = 60
compare(control.availableWidth, 30)
compare(control.availableHeight, 30)
compare(availableWidthSpy.count, availableWidthChanges)
compare(availableHeightSpy.count, availableHeightChanges)
control.width = 0
compare(control.availableWidth, 0)
compare(availableWidthSpy.count, ++availableWidthChanges)
compare(availableHeightSpy.count, availableHeightChanges)
control.height = 0
compare(control.availableHeight, 0)
compare(availableWidthSpy.count, availableWidthChanges)
compare(availableHeightSpy.count, ++availableHeightChanges)
}
function test_position() {
var control = createTemporaryObject(popupControl, testCase, {visible: true, leftMargin: 10, topMargin: 20, width: 100, height: 100})
verify(control)
verify(control.visible)
var xSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "xChanged"})
verify(xSpy.valid)
var ySpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "yChanged"})
verify(ySpy.valid)
// moving outside margins does not trigger change notifiers
control.x = -100
compare(control.x, 10)
compare(control.y, 20)
compare(xSpy.count, 0)
compare(ySpy.count, 0)
control.y = -200
compare(control.x, 10)
compare(control.y, 20)
compare(xSpy.count, 0)
compare(ySpy.count, 0)
// moving within margins triggers change notifiers
control.x = 30
compare(control.x, 30)
compare(control.y, 20)
compare(xSpy.count, 1)
compare(ySpy.count, 0)
control.y = 40
compare(control.x, 30)
compare(control.y, 40)
compare(xSpy.count, 1)
compare(ySpy.count, 1)
// re-parent and reset the position
control.parent = createTemporaryObject(rect, testCase, {color: "red", width: 100, height: 100})
control.x = 0
control.y = 0
compare(xSpy.count, 2)
compare(ySpy.count, 2)
// moving parent outside margins triggers change notifiers
control.parent.x = -50
compare(control.x, 50 + control.leftMargin)
compare(xSpy.count, 3)
compare(ySpy.count, 2)
control.parent.y = -60
compare(control.y, 60 + control.topMargin)
compare(xSpy.count, 3)
compare(ySpy.count, 3)
}
function test_resetSize() {
var control = createTemporaryObject(popupControl, testCase, {visible: true, margins: 0})
verify(control)
control.width = control.implicitWidth = testCase.width + 10
control.height = control.implicitHeight = testCase.height + 10
compare(control.width, testCase.width + 10)
compare(control.height, testCase.height + 10)
control.width = undefined
control.height = undefined
compare(control.width, testCase.width)
compare(control.height, testCase.height)
}
function test_negativeMargins() {
var control = createTemporaryObject(popupControl, testCase, {implicitWidth: testCase.width, implicitHeight: testCase.height})
verify(control)
control.open()
verify(control.visible)
compare(control.x, 0)
compare(control.y, 0)
compare(control.margins, -1)
compare(control.topMargin, -1)
compare(control.leftMargin, -1)
compare(control.rightMargin, -1)
compare(control.bottomMargin, -1)
control.x = -10
control.y = -10
compare(control.x, 0)
compare(control.y, 0)
}
function test_margins() {
var control = createTemporaryObject(popupControl, testCase, {width: 100, height: 100})
verify(control)
control.open()
verify(control.visible)
control.margins = 10
compare(control.margins, 10)
compare(control.topMargin, 10)
compare(control.leftMargin, 10)
compare(control.rightMargin, 10)
compare(control.bottomMargin, 10)
compare(control.contentItem.parent.x, 10)
compare(control.contentItem.parent.y, 10)
control.topMargin = 20
compare(control.margins, 10)
compare(control.topMargin, 20)
compare(control.leftMargin, 10)
compare(control.rightMargin, 10)
compare(control.bottomMargin, 10)
compare(control.contentItem.parent.x, 10)
compare(control.contentItem.parent.y, 20)
control.leftMargin = 20
compare(control.margins, 10)
compare(control.topMargin, 20)
compare(control.leftMargin, 20)
compare(control.rightMargin, 10)
compare(control.bottomMargin, 10)
compare(control.contentItem.parent.x, 20)
compare(control.contentItem.parent.y, 20)
control.x = testCase.width
control.y = testCase.height
compare(control.contentItem.parent.x, testCase.width - control.width - 10)
compare(control.contentItem.parent.y, testCase.height - control.height - 10)
control.rightMargin = 20
compare(control.margins, 10)
compare(control.topMargin, 20)
compare(control.leftMargin, 20)
compare(control.rightMargin, 20)
compare(control.bottomMargin, 10)
compare(control.contentItem.parent.x, testCase.width - control.width - 20)
compare(control.contentItem.parent.y, testCase.height - control.height - 10)
control.bottomMargin = 20
compare(control.margins, 10)
compare(control.topMargin, 20)
compare(control.leftMargin, 20)
compare(control.rightMargin, 20)
compare(control.bottomMargin, 20)
compare(control.contentItem.parent.x, testCase.width - control.width - 20)
compare(control.contentItem.parent.y, testCase.height - control.height - 20)
control.margins = undefined
compare(control.margins, -1)
control.bottomMargin = undefined
compare(control.bottomMargin, -1)
compare(control.contentItem.parent.x, testCase.width - control.width - 20)
compare(control.contentItem.parent.y, testCase.height)
control.rightMargin = undefined
compare(control.rightMargin, -1)
compare(control.contentItem.parent.x, testCase.width)
compare(control.contentItem.parent.y, testCase.height)
control.x = -testCase.width
control.y = -testCase.height
compare(control.contentItem.parent.x, 20)
compare(control.contentItem.parent.y, 20)
control.topMargin = undefined
compare(control.topMargin, -1)
compare(control.contentItem.parent.x, 20)
compare(control.contentItem.parent.y, -testCase.height)
control.leftMargin = undefined
compare(control.leftMargin, -1)
compare(control.contentItem.parent.x, -testCase.width)
compare(control.contentItem.parent.y, -testCase.height)
}
function test_background() {
var control = createTemporaryObject(popupTemplate, testCase)
verify(control)
control.background = rect.createObject(testCase)
// background has no x or width set, so its width follows control's width
control.width = 320
compare(control.background.width, control.width)
// background has no y or height set, so its height follows control's height
compare(control.background.height, control.height)
control.height = 240
// has width => width does not follow
control.background.width /= 2
control.width += 20
verify(control.background.width !== control.width)
// reset width => width follows again
control.background.width = undefined
control.width += 20
compare(control.background.width, control.width)
// has x => width does not follow
control.background.x = 10
control.width += 20
verify(control.background.width !== control.width)
// has height => height does not follow
control.background.height /= 2
control.height -= 20
verify(control.background.height !== control.height)
// reset height => height follows again
control.background.height = undefined
control.height -= 20
compare(control.background.height, control.height)
// has y => height does not follow
control.background.y = 10
control.height -= 20
verify(control.background.height !== control.height)
}
function getChild(control, objname, idx) {
var index = idx
for (var i = index+1; i < control.children.length; i++)
{
if (control.children[i].objectName === objname) {
index = i
break
}
}
return index
}
Component {
id: component
ApplicationWindow {
id: _window
width: 400
height: 400
visible: true
font.pixelSize: 40
property alias pane: _pane
property alias popup: _popup
property SignalSpy fontspy: SignalSpy { target: _window; signalName: "fontChanged" }
Pane {
id: _pane
property alias button: _button
font.pixelSize: 30
property SignalSpy fontspy: SignalSpy { target: _pane; signalName: "fontChanged" }
Column {
Button {
id: _button
text: "Button"
font.pixelSize: 20
property SignalSpy fontspy: SignalSpy { target: _button; signalName: "fontChanged" }
Popup {
id: _popup
property alias button: _button2
property alias listview: _listview
y: _button.height
implicitHeight: Math.min(396, _listview.contentHeight)
property SignalSpy fontspy: SignalSpy { target: _popup; signalName: "fontChanged" }
contentItem: Column {
Button {
id: _button2
text: "Button"
property SignalSpy fontspy: SignalSpy { target: _button2; signalName: "fontChanged" }
}
ListView {
id: _listview
height: _button.height * 20
model: 2
delegate: Button {
id: _button3
objectName: "delegate"
width: _button.width
height: _button.height
text: "N: " + index
checkable: true
autoExclusive: true
property SignalSpy fontspy: SignalSpy { target: _button3; signalName: "fontChanged" }
}
}
}
}
}
}
}
}
}
function test_font() { // QTBUG_50984, QTBUG-51696
var window = createTemporaryObject(component, testCase)
verify(window)
compare(window.font.pixelSize, 40)
compare(window.pane.font.pixelSize, 30)
compare(window.pane.button.font.pixelSize, 20)
compare(window.popup.font.pixelSize, 40)
compare(window.popup.button.font.pixelSize, 40)
var idx1 = getChild(window.popup.listview.contentItem, "delegate", -1)
compare(window.popup.listview.contentItem.children[idx1].font.pixelSize, 40)
var idx2 = getChild(window.popup.listview.contentItem, "delegate", idx1)
compare(window.popup.listview.contentItem.children[idx2].font.pixelSize, 40)
window.pane.button.font.pixelSize = 30
compare(window.font.pixelSize, 40)
compare(window.fontspy.count, 0)
compare(window.pane.font.pixelSize, 30)
compare(window.pane.fontspy.count, 0)
compare(window.pane.button.font.pixelSize, 30)
compare(window.pane.button.fontspy.count, 1)
compare(window.popup.font.pixelSize, 40)
compare(window.popup.fontspy.count, 0)
compare(window.popup.button.font.pixelSize, 40)
compare(window.popup.button.fontspy.count, 0)
compare(window.popup.listview.contentItem.children[idx1].font.pixelSize, 40)
compare(window.popup.listview.contentItem.children[idx1].fontspy.count, 0)
compare(window.popup.listview.contentItem.children[idx2].font.pixelSize, 40)
compare(window.popup.listview.contentItem.children[idx2].fontspy.count, 0)
window.font.pixelSize = 50
compare(window.font.pixelSize, 50)
compare(window.fontspy.count, 1)
compare(window.pane.font.pixelSize, 30)
compare(window.pane.fontspy.count, 0)
compare(window.pane.button.font.pixelSize, 30)
compare(window.pane.button.fontspy.count, 1)
compare(window.popup.font.pixelSize, 50)
compare(window.popup.fontspy.count, 1)
compare(window.popup.button.font.pixelSize, 50)
compare(window.popup.button.fontspy.count, 1)
compare(window.popup.listview.contentItem.children[idx1].font.pixelSize, 50)
compare(window.popup.listview.contentItem.children[idx1].fontspy.count, 1)
compare(window.popup.listview.contentItem.children[idx2].font.pixelSize, 50)
compare(window.popup.listview.contentItem.children[idx2].fontspy.count, 1)
window.popup.button.font.pixelSize = 10
compare(window.font.pixelSize, 50)
compare(window.fontspy.count, 1)
compare(window.pane.font.pixelSize, 30)
compare(window.pane.fontspy.count, 0)
compare(window.pane.button.font.pixelSize, 30)
compare(window.pane.button.fontspy.count, 1)
compare(window.popup.font.pixelSize, 50)
compare(window.popup.fontspy.count, 1)
compare(window.popup.button.font.pixelSize, 10)
compare(window.popup.button.fontspy.count, 2)
compare(window.popup.listview.contentItem.children[idx1].font.pixelSize, 50)
compare(window.popup.listview.contentItem.children[idx1].fontspy.count, 1)
compare(window.popup.listview.contentItem.children[idx2].font.pixelSize, 50)
compare(window.popup.listview.contentItem.children[idx2].fontspy.count, 1)
window.popup.font.pixelSize = 60
compare(window.font.pixelSize, 50)
compare(window.fontspy.count, 1)
compare(window.pane.font.pixelSize, 30)
compare(window.pane.fontspy.count, 0)
compare(window.pane.button.font.pixelSize, 30)
compare(window.pane.button.fontspy.count, 1)
compare(window.popup.font.pixelSize, 60)
compare(window.popup.fontspy.count, 2)
compare(window.popup.button.font.pixelSize, 10)
compare(window.popup.button.fontspy.count, 2)
compare(window.popup.listview.contentItem.children[idx1].font.pixelSize, 60)
compare(window.popup.listview.contentItem.children[idx1].fontspy.count, 2)
compare(window.popup.listview.contentItem.children[idx2].font.pixelSize, 60)
compare(window.popup.listview.contentItem.children[idx2].fontspy.count, 2)
}
Component {
id: localeComponent
Pane {
property alias button: _button
property alias popup: _popup
locale: Qt.locale("en_US")
Column {
Button {
id: _button
text: "Button"
locale: Qt.locale("nb_NO")
Popup {
id: _popup
property alias button1: _button1
property alias button2: _button2
y: _button.height
locale: Qt.locale("fi_FI")
implicitHeight: Math.min(396, _column.contentHeight)
contentItem: Column {
id: _column
Button {
id: _button1
text: "Button 1"
objectName: "1"
}
Button {
id: _button2
text: "Button 2"
locale: Qt.locale("nb_NO")
objectName: "2"
}
}
}
}
}
}
}
function test_locale() { // QTBUG_50984
// test looking up natural locale from ancestors
var control = createTemporaryObject(localeComponent, applicationWindow.contentItem)
verify(control)
compare(control.locale.name, "en_US")
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, "fi_FI")
compare(control.popup.button1.locale.name, "fi_FI")
compare(control.popup.button2.locale.name, "nb_NO")
control.ApplicationWindow.window.locale = undefined
}
Component {
id: localeChangeComponent
Pane {
id: _pane
property alias button: _button
property alias popup: _popup
property SignalSpy localespy: SignalSpy {
target: _pane
signalName: "localeChanged"
}
property SignalSpy mirrorspy: SignalSpy {
target: _pane
signalName: "mirroredChanged"
}
Column {
Button {
id: _button
text: "Button"
property SignalSpy localespy: SignalSpy {
target: _button
signalName: "localeChanged"
}
property SignalSpy mirrorspy: SignalSpy {
target: _button
signalName: "mirroredChanged"
}
Popup {
id: _popup
property alias button1: _button1
property alias button2: _button2
y: _button.height
implicitHeight: Math.min(396, _column.contentHeight)
property SignalSpy localespy: SignalSpy {
target: _popup
signalName: "localeChanged"
}
contentItem: Column {
id: _column
Button {
id: _button1
text: "Button 1"
property SignalSpy localespy: SignalSpy {
target: _button1
signalName: "localeChanged"
}
property SignalSpy mirrorspy: SignalSpy {
target: _button1
signalName: "mirroredChanged"
}
}
Button {
id: _button2
text: "Button 2"
property SignalSpy localespy: SignalSpy {
target: _button2
signalName: "localeChanged"
}
property SignalSpy mirrorspy: SignalSpy {
target: _button2
signalName: "mirroredChanged"
}
}
}
}
}
}
}
}
function test_locale_changes() { // QTBUG_50984
// test default locale and locale inheritance
var control = createTemporaryObject(localeChangeComponent, applicationWindow.contentItem)
verify(control)
var defaultLocale = Qt.locale()
compare(control.ApplicationWindow.window.locale.name, defaultLocale.name)
compare(control.locale.name, defaultLocale.name)
compare(control.button.locale.name, defaultLocale.name)
compare(control.popup.locale.name, defaultLocale.name)
compare(control.popup.button1.locale.name, defaultLocale.name)
compare(control.popup.button2.locale.name, defaultLocale.name)
control.ApplicationWindow.window.locale = Qt.locale("nb_NO")
compare(control.ApplicationWindow.window.locale.name, "nb_NO")
compare(control.locale.name, "nb_NO")
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, "nb_NO")
compare(control.popup.button1.locale.name, "nb_NO")
compare(control.popup.button2.locale.name, "nb_NO")
compare(control.localespy.count, 1)
compare(control.button.localespy.count, 1)
compare(control.popup.localespy.count, 1)
compare(control.popup.button1.localespy.count, 1)
compare(control.popup.button2.localespy.count, 1)
control.ApplicationWindow.window.locale = undefined
compare(control.ApplicationWindow.window.locale.name, defaultLocale.name)
compare(control.locale.name, defaultLocale.name)
compare(control.button.locale.name, defaultLocale.name)
compare(control.popup.locale.name, defaultLocale.name)
compare(control.popup.button1.locale.name, defaultLocale.name)
compare(control.popup.button2.locale.name, defaultLocale.name)
compare(control.localespy.count, 2)
compare(control.button.localespy.count, 2)
compare(control.popup.localespy.count, 2)
compare(control.popup.button1.localespy.count, 2)
compare(control.popup.button2.localespy.count, 2)
control.locale = Qt.locale("ar_EG")
compare(control.ApplicationWindow.window.locale.name, defaultLocale.name)
compare(control.locale.name, "ar_EG")
compare(control.button.locale.name, "ar_EG")
compare(control.popup.locale.name, defaultLocale.name)
compare(control.popup.button1.locale.name, defaultLocale.name)
compare(control.popup.button2.locale.name, defaultLocale.name)
compare(control.localespy.count, 3)
compare(control.mirrorspy.count, 1)
compare(control.button.localespy.count, 3)
compare(control.button.mirrorspy.count, 1)
compare(control.popup.localespy.count, 2)
compare(control.popup.button1.localespy.count, 2)
compare(control.popup.button2.localespy.count, 2)
control.ApplicationWindow.window.locale = Qt.locale("ar_EG")
compare(control.ApplicationWindow.window.locale.name, "ar_EG")
compare(control.locale.name, "ar_EG")
compare(control.button.locale.name, "ar_EG")
compare(control.popup.locale.name, "ar_EG")
compare(control.popup.button1.locale.name, "ar_EG")
compare(control.popup.button2.locale.name, "ar_EG")
compare(control.localespy.count, 3)
compare(control.mirrorspy.count, 1)
compare(control.button.localespy.count, 3)
compare(control.button.mirrorspy.count, 1)
compare(control.popup.localespy.count, 3)
compare(control.popup.button1.localespy.count, 3)
compare(control.popup.button1.mirrorspy.count, 1)
compare(control.popup.button2.localespy.count, 3)
compare(control.popup.button2.mirrorspy.count, 1)
control.button.locale = Qt.locale("nb_NO")
compare(control.ApplicationWindow.window.locale.name, "ar_EG")
compare(control.locale.name, "ar_EG")
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, "ar_EG")
compare(control.popup.button1.locale.name, "ar_EG")
compare(control.popup.button2.locale.name, "ar_EG")
compare(control.localespy.count, 3)
compare(control.mirrorspy.count, 1)
compare(control.button.localespy.count, 4)
compare(control.button.mirrorspy.count, 2)
compare(control.popup.localespy.count, 3)
compare(control.popup.button1.localespy.count, 3)
compare(control.popup.button2.localespy.count, 3)
control.locale = undefined
compare(control.ApplicationWindow.window.locale.name, "ar_EG")
compare(control.locale.name, "ar_EG")
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, "ar_EG")
compare(control.popup.button1.locale.name, "ar_EG")
compare(control.popup.button2.locale.name, "ar_EG")
compare(control.localespy.count, 3)
compare(control.mirrorspy.count, 1)
compare(control.button.localespy.count, 4)
compare(control.button.mirrorspy.count, 2)
compare(control.popup.localespy.count, 3)
compare(control.popup.button1.localespy.count, 3)
compare(control.popup.button2.localespy.count, 3)
control.popup.button1.locale = Qt.locale("nb_NO")
compare(control.ApplicationWindow.window.locale.name, "ar_EG")
compare(control.locale.name, "ar_EG")
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, "ar_EG")
compare(control.popup.button1.locale.name, "nb_NO")
compare(control.popup.button2.locale.name, "ar_EG")
compare(control.localespy.count, 3)
compare(control.mirrorspy.count, 1)
compare(control.button.localespy.count, 4)
compare(control.button.mirrorspy.count, 2)
compare(control.popup.localespy.count, 3)
compare(control.popup.button1.localespy.count, 4)
compare(control.popup.button1.mirrorspy.count, 2)
compare(control.popup.button2.localespy.count, 3)
compare(control.popup.button2.mirrorspy.count, 1)
control.popup.locale = Qt.locale("fi_FI")
compare(control.ApplicationWindow.window.locale.name, "ar_EG")
compare(control.locale.name, "ar_EG")
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, "fi_FI")
compare(control.popup.button1.locale.name, "nb_NO")
compare(control.popup.button2.locale.name, "fi_FI")
compare(control.localespy.count, 3)
compare(control.mirrorspy.count, 1)
compare(control.button.localespy.count, 4)
compare(control.button.mirrorspy.count, 2)
compare(control.popup.localespy.count, 4)
compare(control.popup.button1.localespy.count, 4)
compare(control.popup.button1.mirrorspy.count, 2)
compare(control.popup.button2.localespy.count, 4)
compare(control.popup.button2.mirrorspy.count, 2)
control.ApplicationWindow.window.locale = undefined
compare(control.ApplicationWindow.window.locale.name, defaultLocale.name)
compare(control.locale.name, defaultLocale.name)
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, "fi_FI")
compare(control.popup.button1.locale.name, "nb_NO")
compare(control.popup.button2.locale.name, "fi_FI")
compare(control.localespy.count, 4)
compare(control.mirrorspy.count, 2)
compare(control.button.localespy.count, 4)
compare(control.button.mirrorspy.count, 2)
compare(control.popup.localespy.count, 4)
compare(control.popup.button1.localespy.count, 4)
compare(control.popup.button1.mirrorspy.count, 2)
compare(control.popup.button2.localespy.count, 4)
compare(control.popup.button2.mirrorspy.count, 2)
control.popup.locale = undefined
compare(control.ApplicationWindow.window.locale.name, defaultLocale.name)
compare(control.locale.name, defaultLocale.name)
compare(control.button.locale.name, "nb_NO")
compare(control.popup.locale.name, defaultLocale.name)
compare(control.popup.button1.locale.name, "nb_NO")
compare(control.popup.button2.locale.name, defaultLocale.name)
compare(control.localespy.count, 4)
compare(control.mirrorspy.count, 2)
compare(control.button.localespy.count, 4)
compare(control.button.mirrorspy.count, 2)
compare(control.popup.localespy.count, 5)
compare(control.popup.button1.localespy.count, 4)
compare(control.popup.button1.mirrorspy.count, 2)
compare(control.popup.button2.localespy.count, 5)
compare(control.popup.button2.mirrorspy.count, 2)
}
function test_size() {
var control = createTemporaryObject(popupControl, testCase)
verify(control)
var openedSpy = createTemporaryObject(signalSpy, testCase, {target: control, signalName: "opened"})
verify(openedSpy.valid)
control.open()
openedSpy.wait()
compare(openedSpy.count, 1)
verify(control.visible)
// implicit size of the content
control.contentItem.implicitWidth = 10
compare(control.implicitWidth, 10 + control.leftPadding + control.rightPadding)
compare(control.width, control.implicitWidth)
compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
control.contentItem.implicitHeight = 20
compare(control.implicitHeight, 20 + control.topPadding + control.bottomPadding)
compare(control.height, control.implicitHeight)
compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
// implicit size of the popup
control.implicitWidth = 30
compare(control.implicitWidth, 30)
compare(control.width, 30)
compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
control.implicitHeight = 40
compare(control.implicitHeight, 40)
compare(control.height, 40)
compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
// set explicit size
control.width = 50
compare(control.implicitWidth, 30)
compare(control.width, 50)
compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
control.height = 60
compare(control.implicitHeight, 40)
compare(control.height, 60)
compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
// reset explicit size
control.width = undefined
compare(control.implicitWidth, 30)
compare(control.width, 30)
compare(control.contentItem.width, control.width - control.leftPadding - control.rightPadding)
control.height = undefined
compare(control.implicitHeight, 40)
compare(control.height, 40)
compare(control.contentItem.height, control.height - control.topPadding - control.bottomPadding)
}
function test_visible() {
var control = createTemporaryObject(popupTemplate, testCase, {visible: true})
verify(control)
// QTBUG-51989
tryCompare(control, "visible", true)
// QTBUG-55347
control.parent = null
verify(!control.visible)
}
Component {
id: overlayTest
ApplicationWindow {
property alias firstDrawer: firstDrawer
property alias secondDrawer: secondDrawer
property alias modalPopup: modalPopup
property alias modelessPopup: modelessPopup
property alias plainPopup: plainPopup
property alias modalPopupWithoutDim: modalPopupWithoutDim
visible: true
Drawer {
z: 0
id: firstDrawer
}
Drawer {
z: 1
id: secondDrawer
}
Popup {
id: modalPopup
z: 2
modal: true
exit: Transition { PauseAnimation { duration: 200 } }
}
Popup {
id: modelessPopup
z: 3
dim: true
exit: Transition { PauseAnimation { duration: 200 } }
}
Popup {
id: plainPopup
z: 4
enter: Transition { PauseAnimation { duration: 200 } }
exit: Transition { PauseAnimation { duration: 200 } }
}
Popup {
id: modalPopupWithoutDim
z: 5
dim: false
modal: true
exit: Transition { PauseAnimation { duration: 200 } }
}
}
}
function indexOf(array, item) {
for (var idx = 0; idx < array.length; ++idx) {
if (item === array[idx])
return idx;
}
return -1
}
function findOverlay(window, popup) {
var item = popup.contentItem.parent
var idx = indexOf(window.overlay.children, item)
return window.overlay.children[idx - 1]
}
function test_overlay() {
var window = createTemporaryObject(overlayTest, testCase)
verify(window)
window.requestActivate()
tryCompare(window, "active", true)
compare(window.overlay.children.length, 0)
var firstOverlay = findOverlay(window, window.firstDrawer)
verify(!firstOverlay)
window.firstDrawer.open()
compare(window.overlay.children.length, 2) // 1 drawer + 1 overlay
firstOverlay = findOverlay(window, window.firstDrawer)
verify(firstOverlay)
compare(firstOverlay.z, window.firstDrawer.z)
compare(indexOf(window.overlay.children, firstOverlay),
indexOf(window.overlay.children, window.firstDrawer.contentItem.parent) - 1)
tryCompare(firstOverlay, "opacity", 1.0)
var secondOverlay = findOverlay(window, window.secondDrawer)
verify(!secondOverlay)
window.secondDrawer.open()
compare(window.overlay.children.length, 4) // 2 drawers + 2 overlays
secondOverlay = findOverlay(window, window.secondDrawer)
verify(secondOverlay)
compare(secondOverlay.z, window.secondDrawer.z)
compare(indexOf(window.overlay.children, secondOverlay),
indexOf(window.overlay.children, window.secondDrawer.contentItem.parent) - 1)
tryCompare(secondOverlay, "opacity", 1.0)
window.firstDrawer.close()
tryCompare(window.firstDrawer, "visible", false)
firstOverlay = findOverlay(window, window.firstDrawer)
verify(!firstOverlay)
compare(window.overlay.children.length, 2) // 1 drawer + 1 overlay
window.secondDrawer.close()
tryCompare(window.secondDrawer, "visible", false)
secondOverlay = findOverlay(window, window.secondDrawer)
verify(!secondOverlay)
compare(window.overlay.children.length, 0)
var modalOverlay = findOverlay(window, window.modalPopup)
verify(!modalOverlay)
window.modalPopup.open()
modalOverlay = findOverlay(window, window.modalPopup)
verify(modalOverlay)
compare(modalOverlay.z, window.modalPopup.z)
compare(window.modalPopup.visible, true)
tryCompare(modalOverlay, "opacity", 1.0)
compare(window.overlay.children.length, 2) // 1 popup + 1 overlay
var modelessOverlay = findOverlay(window, window.modelessPopup)
verify(!modelessOverlay)
window.modelessPopup.open()
modelessOverlay = findOverlay(window, window.modelessPopup)
verify(modelessOverlay)
compare(modelessOverlay.z, window.modelessPopup.z)
compare(window.modelessPopup.visible, true)
tryCompare(modelessOverlay, "opacity", 1.0)
compare(window.overlay.children.length, 4) // 2 popups + 2 overlays
window.modelessPopup.close()
tryCompare(window.modelessPopup, "visible", false)
modelessOverlay = findOverlay(window, window.modelessPopup)
verify(!modelessOverlay)
compare(window.overlay.children.length, 2) // 1 popup + 1 overlay
compare(window.modalPopup.visible, true)
compare(modalOverlay.opacity, 1.0)
window.modalPopup.close()
tryCompare(window.modalPopup, "visible", false)
modalOverlay = findOverlay(window, window.modalPopup)
verify(!modalOverlay)
compare(window.overlay.children.length, 0)
window.plainPopup.open()
tryCompare(window.plainPopup, "visible", true)
compare(window.overlay.children.length, 1) // only popup added, no overlays involved
window.plainPopup.modal = true
compare(window.overlay.children.length, 2) // overlay added
window.plainPopup.close()
tryCompare(window.plainPopup, "visible", false)
compare(window.overlay.children.length, 0) // popup + overlay removed
window.modalPopupWithoutDim.open()
tryCompare(window.modalPopupWithoutDim, "visible", true)
compare(window.overlay.children.length, 1) // only popup added, no overlays involved
window.modalPopupWithoutDim.dim = true
compare(window.overlay.children.length, 2) // overlay added
window.modalPopupWithoutDim.close()
tryCompare(window.modalPopupWithoutDim, "visible", false)
compare(window.overlay.children.length, 0) // popup + overlay removed
}
function test_attached_applicationwindow() {
var control = createTemporaryObject(popupControl, applicationWindow.contentItem)
verify(control)
var child = rect.createObject(control.contentItem)
compare(control.ApplicationWindow.window, applicationWindow)
compare(control.contentItem.ApplicationWindow.window, applicationWindow)
compare(child.ApplicationWindow.window, applicationWindow)
control.parent = null
compare(control.ApplicationWindow.window, null)
compare(control.contentItem.ApplicationWindow.window, null)
compare(child.ApplicationWindow.window, null)
}
SignalSpy {
id: openedSpy
signalName: "opened"
}
SignalSpy {
id: closedSpy
signalName: "closed"
}
Component {
id: pausePopup
Popup {
enter: Transition { PauseAnimation { duration: 200 } }
exit: Transition { PauseAnimation { duration: 200 } }
}
}
function test_openedClosed() {
var control = createTemporaryObject(pausePopup, testCase)
verify(control)
openedSpy.target = control
closedSpy.target = control
control.open()
compare(control.visible, true)
compare(openedSpy.count, 0)
tryCompare(openedSpy, "count", 1)
compare(closedSpy.count, 0)
control.close()
compare(openedSpy.count, 1)
compare(closedSpy.count, 0)
tryCompare(closedSpy, "count", 1)
compare(control.visible, false)
}
Component {
id: xyBindingLoop
ApplicationWindow {
id: window
width: 360
height: 360
visible: true
property alias popup: popup
Popup {
id: popup
visible: true
x: (parent.width - width) / 2
y: (parent.height - height) / 2
Label {
text: "Content"
anchors.fill: parent
}
}
}
}
function test_xyBindingLoop() {
var window = createTemporaryObject(xyBindingLoop, testCase)
var control = window.popup
waitForRendering(control.contentItem)
compare(control.x, (control.parent.width - control.width) / 2)
compare(control.y, (control.parent.height - control.height) / 2)
}
function test_windowParent() {
var control = createTemporaryObject(popupControl, applicationWindow, {width: 100, height: 100})
verify(control)
control.open()
verify(control.visible)
}
}
|