2
* Copyright 2015 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Author: Andrea Bernabei <andrea.bernabei@canonical.com>
21
import Ubuntu.Test 1.0
22
import Ubuntu.Components 1.3
23
import Ubuntu.Components.Styles 1.3
24
import QtQml.Models 2.1
45
//these lists define the slots that we expect to be part of the layout
46
//process, and the order in which we expect them to be positioned in the
47
//layout. This is to avoid complicating the layout logic by adding conditions
48
//to the method which tests the position of the slots. If we want to
49
//test that a !visible slot is ignored during the relayout, for instance,
50
//we have to remove it from these lists before we call checkSlotsPosition(layout).
51
//The same applies to changes in the position of a slot.
52
readonly property var leadingSlots: []
53
readonly property var trailingSlots: []
57
readonly property var leadingSlots: []
58
readonly property var trailingSlots: []
63
subtitle.text: "test2"
65
readonly property var leadingSlots: []
66
readonly property var trailingSlots: []
70
readonly property var leadingSlots: [layoutOneLeading_leading1]
71
readonly property var trailingSlots: []
72
Item { id: layoutOneLeading_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(3); height: units.gu(2) }
76
readonly property var leadingSlots: []
77
readonly property var trailingSlots: [layoutOneTrailing_trailing1]
78
Item { id: layoutOneTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(2) }
81
id: layoutOneLeadingOneTrailing
82
readonly property var leadingSlots: [layoutOneLeadingOneTrailing_leading1]
83
readonly property var trailingSlots: [layoutOneLeadingOneTrailing_trailing1]
84
Item { id: layoutOneLeadingOneTrailing_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(10); height: units.gu(20) }
85
Item { id: layoutOneLeadingOneTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(5) }
89
readonly property var leadingSlots: []
90
readonly property var trailingSlots: [layoutTwoTrailing_trailing1, layoutTwoTrailing_trailing2]
91
Item { id: layoutTwoTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(3) }
92
Item { id: layoutTwoTrailing_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(2) }
95
id: layoutOneLeadingTwoTrailing
96
readonly property var leadingSlots: [layoutOneLeadingTwoTrailing_leading1]
97
readonly property var trailingSlots: [layoutOneLeadingTwoTrailing_trailing1, layoutOneLeadingTwoTrailing_trailing2]
98
Item { id: layoutOneLeadingTwoTrailing_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(3); height: units.gu(1) }
99
Item { id: layoutOneLeadingTwoTrailing_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(4); height: units.gu(9) }
100
Item { id: layoutOneLeadingTwoTrailing_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(6) }
103
id: layoutCustomSlotsPadding
104
readonly property var leadingSlots: [layoutCustomSlotsPadding_leading1]
105
readonly property var trailingSlots: [layoutCustomSlotsPadding_trailing1, layoutCustomSlotsPadding_trailing2]
107
id: layoutCustomSlotsPadding_leading1;
108
SlotsLayout.position: SlotsLayout.Leading;
109
SlotsLayout.padding.top: units.gu(30)
110
SlotsLayout.padding.bottom: units.gu(2)
115
id: layoutCustomSlotsPadding_trailing1;
116
SlotsLayout.position: SlotsLayout.Trailing;
117
SlotsLayout.padding.top: units.gu(30)
118
SlotsLayout.padding.bottom: units.gu(2)
123
id: layoutCustomSlotsPadding_trailing2;
124
SlotsLayout.position: SlotsLayout.Trailing;
125
SlotsLayout.padding {
127
trailing: units.gu(5)
136
id: layoutCustomPadding
137
readonly property var leadingSlots: [layoutCustomPadding_leading1]
138
readonly property var trailingSlots: [layoutCustomPadding_trailing1, layoutCustomPadding_trailing2]
143
trailing: units.gu(4)
145
Item { id: layoutCustomPadding_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(6); height: units.gu(3) }
146
Item { id: layoutCustomPadding_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(7) }
147
Item { id: layoutCustomPadding_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(9) }
150
id: layoutTestChangeSlotsSize
151
readonly property var leadingSlots: [layoutTestChangeSlotsSize_leading1]
152
readonly property var trailingSlots: []
158
Item { id: layoutTestChangeSlotsSize_leading1; SlotsLayout.position: SlotsLayout.Leading; width: units.gu(10); height: 38.5/*units.gu(3.1222)*/ }
161
id: layoutTestMainSlotSize
163
readonly property var leadingSlots: []
164
readonly property var trailingSlots: [layoutTestMainSlotSize_trailing1]
166
Item { id: layoutTestMainSlotSize_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(1); height: units.gu(3) }
169
id: layoutTestSmallerTopBottomPadding
170
readonly property var leadingSlots: [layoutTestSmallerTopBottomPadding_leading1]
171
readonly property var trailingSlots: []
173
subtitle.text: "test2"
174
summary.text: "test3"
175
Item { id: layoutTestSmallerTopBottomPadding_leading1; SlotsLayout.position: SlotsLayout.Leading;
176
width: units.gu(1); height: Math.max(parent.mainSlot.height, units.gu(4)) }
179
id: layoutTestChangeSlotPosition
180
property var leadingSlots: [layoutTestChangeSlotPosition_leading]
181
property var trailingSlots: []
183
subtitle.text: "test2"
184
summary.text: "test3"
185
Item { id: layoutTestChangeSlotPosition_leading; SlotsLayout.position: SlotsLayout.Leading;
186
width: units.gu(4); height: units.gu(4) }
189
id: layoutTestSlotVisibilityChange
190
property var leadingSlots: [layoutTestSlotVisibilityChange_leading]
191
readonly property var trailingSlots: []
193
subtitle.text: "test2"
194
summary.text: "test3"
195
//it has to be taller than mainSlot, so that when we make the slot invisible we can test
196
//implicitHeight changes
197
Item { id: layoutTestSlotVisibilityChange_leading; SlotsLayout.position: SlotsLayout.Leading;
198
width: units.gu(4); height: parent.mainSlot.height+10 }
201
//let's test if the layout respects SlotsLayout.position even if that doesn't follow
203
id: layoutTestRelativePositioning
204
//these lists hold the slots in the order we want them to be positioned
205
readonly property var leadingSlots: [layoutTestRelativePositioning_leading1]
206
readonly property var trailingSlots: [layoutTestRelativePositioning_trailing2, layoutTestRelativePositioning_trailing1]
207
Item { id: layoutTestRelativePositioning_leading1; SlotsLayout.position: SlotsLayout.Leading-3; width: units.gu(6); height: units.gu(3) }
208
Item { id: layoutTestRelativePositioning_trailing1; SlotsLayout.position: SlotsLayout.Last; width: units.gu(1); height: units.gu(7) }
209
Item { id: layoutTestRelativePositioning_trailing2; SlotsLayout.position: SlotsLayout.Last-2; width: units.gu(3); height: units.gu(9) }
212
id: layoutTestRelativePositioning2
213
readonly property var leadingSlots: [layoutTestRelativePositioning2_leading1]
214
readonly property var trailingSlots: [layoutTestRelativePositioning2_trailing2, layoutTestRelativePositioning2_trailing1]
215
Item { id: layoutTestRelativePositioning2_leading1; SlotsLayout.position: SlotsLayout.Leading-3; width: units.gu(6); height: units.gu(3) }
216
Item { id: layoutTestRelativePositioning2_trailing1; SlotsLayout.position: SlotsLayout.Trailing+1; width: units.gu(1); height: units.gu(7) }
217
Item { id: layoutTestRelativePositioning2_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(9) }
220
id: layoutTestNullSizeSlots
221
readonly property var leadingSlots: []
222
property var trailingSlots: [layoutNullSizeSlots_trailing1, layoutNullSizeSlots_trailing2]
224
//we will reset the slot which is taller than mainSlot and test height and positions
225
Item { id: layoutNullSizeSlots_trailing1; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(5); height: parent.mainSlot.height+20 }
226
Item { id: layoutNullSizeSlots_trailing2; SlotsLayout.position: SlotsLayout.Trailing; width: units.gu(3); height: units.gu(4) }
229
id: layoutTestOverrideVerticalPositioning
230
readonly property var leadingSlots: []
231
readonly property var trailingSlots: [layoutTestOverrideVerticalPositioning_trailing1,
232
layoutTestOverrideVerticalPositioning_trailing2]
234
//we will reset the slot which is taller than mainSlot and test height and positions
236
id: layoutTestOverrideVerticalPositioning_trailing1;
237
SlotsLayout.position: SlotsLayout.Trailing;
242
id: layoutTestOverrideVerticalPositioning_trailing2;
243
SlotsLayout.overrideVerticalPositioning: true
244
SlotsLayout.position: SlotsLayout.Trailing;
245
anchors.bottom: parent.bottom
247
height: parent.mainSlot.height+10
251
id: layoutTestIgnoreSomeChangesOnMainSlot
252
readonly property var leadingSlots: [layoutTestIgnoreSomeChangesOnMainSlot_leading1]
253
readonly property var trailingSlots: []
255
//we will reset the slot which is taller than mainSlot and test height and positions
257
id: layoutTestIgnoreSomeChangesOnMainSlot_leading1;
258
SlotsLayout.position: SlotsLayout.Leading;
260
height: parent.mainSlot.height + 50
264
id: layoutTestMainSlotAttachedProps
265
readonly property var leadingSlots: [layoutTestMainSlotAttachedProps_leading1]
266
readonly property var trailingSlots: []
268
//we will reset the slot which is taller than mainSlot and test height and positions
270
id: layoutTestMainSlotAttachedProps_leading1;
271
SlotsLayout.position: SlotsLayout.Leading;
273
height: parent.mainSlot.height + 50
277
id: layoutTestDefaultSlotsAttachedProps
278
readonly property var leadingSlots: []
279
property var trailingSlots: [layoutTestDefaultSlotsAttachedProps_trailing1]
280
Item { id: layoutTestDefaultSlotsAttachedProps_trailing1 }
282
//UCLabel initially had REVISION 1 around textSize Q_PROPERTY
283
//That breaks initialization of textSize from QML when done on
284
//the UCLabels we created from C++! (changing textSize works from JS, fyi)
285
//This component makes sure we don't break this usecase again in the future
287
id: layoutTestCustomTextSizeInitializationFromQml
289
title.textSize: Label.XLarge
297
function warningMsg(msg) {
298
return testUtil.callerFile() + ": " + msg
302
//when we have at least one slot which is taller than mainSlot and taller than 4GU,
303
//we want the top and bottom padding to be 1GU instead of 2GU
304
property real topBottomPaddingThreshold: units.gu(4)
305
property real smallerTopBottomPadding: units.gu(1)
306
property real tallerTopBottomPadding: units.gu(2)
308
function standardTestsData() {
310
{ tag: "Empty", item: layout },
311
{ tag: "Labels", item: layoutLabels },
312
{ tag: "One leading slot", item: layoutOneLeading },
313
{ tag: "One trailing slot", item: layoutOneTrailing },
314
{ tag: "One leading, one trailing slots", item: layoutOneLeadingOneTrailing },
315
{ tag: "Two trailing", item: layoutTwoTrailing },
316
{ tag: "One leading, two trailing slots", item: layoutOneLeadingTwoTrailing },
317
{ tag: "One leading, two trailing slots with custom paddings", item: layoutCustomSlotsPadding },
321
//This excludes mainSlot and the slots which have overrideVerticalPositioning enabled!
322
function maxSlotsHeight(item) {
325
for (i = 0; i < item.leadingSlots.length; ++i) {
326
var slot = item.leadingSlots[i]
327
if (!slot.SlotsLayout.overrideVerticalPositioning) {
328
maxHeight = Math.max(slot.height + slot.SlotsLayout.padding.top
329
+ slot.SlotsLayout.padding.bottom, maxHeight)
332
for (i = 0; i < item.trailingSlots.length; ++i) {
333
var currSlot = item.trailingSlots[i]
334
if (!currSlot.SlotsLayout.overrideVerticalPositioning) {
335
maxHeight = Math.max(currSlot.height + currSlot.SlotsLayout.padding.top
336
+ currSlot.SlotsLayout.padding.bottom, maxHeight)
342
function expectedImplicitHeight(item) {
343
var height = maxSlotsHeight(item)
344
if (item.mainSlot !== null) {
345
height = Math.max(height, item.mainSlot.height
346
+ item.mainSlot.SlotsLayout.padding.top
347
+ item.mainSlot.SlotsLayout.padding.bottom)
349
return height + item.padding.top + item.padding.bottom
352
//otherwise center the slots vertically
353
function mustAlignSlotsToTop(item) {
354
if (item.mainSlot === null) {
357
return maxSlotsHeight(item) < (item.mainSlot.height
358
+ item.mainSlot.SlotsLayout.padding.top
359
+ item.mainSlot.SlotsLayout.padding.bottom)
361
function useSmallerTopBottomPadding(item) {
362
return !mustAlignSlotsToTop(item)
363
&& maxSlotsHeight(item) > topBottomPaddingThreshold
366
function checkDefaultPadding(item) {
367
if (useSmallerTopBottomPadding(item)) {
368
compare(item.padding.top, smallerTopBottomPadding, "Default smaller top padding")
369
compare(item.padding.bottom, smallerTopBottomPadding, "Default smaller bottom padding")
371
compare(item.padding.top, tallerTopBottomPadding, "Default top padding")
372
compare(item.padding.bottom, tallerTopBottomPadding, "Default bottom padding")
374
compare(item.padding.leading, units.gu(1), "Default leading padding")
375
compare(item.padding.trailing, units.gu(1), "Default trailing padding")
378
function checkImplicitSize(item) {
379
compare(item.implicitHeight, expectedImplicitHeight(item), "Implicit height check")
380
compare(item.implicitWidth, column.width, "Fill parent's width")
383
//this functions takes a layouts and checks that the slots in the lists
384
//"leadingSlots" and "trailingSlots" are following the visual rules
385
//NOTE: THIS METHOD DOESN'T IGNORE ANY SLOT (because of visibility or similar).
386
//slots which are expected to be ignored by the cpp implementation should be
387
//removed from "leadingSlots" and "trailingSlots" before calling this method
388
function checkSlotsPosition(item) {
390
slots = slots.concat(item.leadingSlots)
391
if (item.mainSlot !== null) {
392
slots = slots.concat(item.mainSlot)
394
slots = slots.concat(item.trailingSlots)
396
var expectedX = item.padding.leading;
398
for (i = 0; i < slots.length; ++i) {
401
expectedX += slot.SlotsLayout.padding.leading
402
compare(slot.x, expectedX, "Slot's horizontal position")
403
expectedX += slot.width
404
expectedX += slot.SlotsLayout.padding.trailing
406
//mainSlot ignores the value of its overrideVerticalPositioning
407
if (slot.SlotsLayout.overrideVerticalPositioning && slot !== item.mainSlot) {
408
//NOTE: we're assuming the test item doesn't set any custom anchor!!
409
compare(slot.y, 0, "Override vertical positioning: vertical position")
411
if (mustAlignSlotsToTop(item)) {
412
compare(slot.anchors.top, item.top,
413
"Automatic vertical positioning: top anchor, \"aligned to the top\" positioning mode")
414
compare(slot.anchors.topMargin, item.padding.top + slot.SlotsLayout.padding.top,
415
"Automatic vertical positioning: topMargin, \"aligned to the top\" positioning mode")
417
compare(slot.anchors.verticalCenter, item.verticalCenter,
418
"Automatic vertical positioning: verticalCenter anchor, \"vertically centered\" positioning mode ")
419
compare(slot.anchors.verticalCenterOffset,
420
(item.padding.top - item.padding.bottom
421
+ slot.SlotsLayout.padding.top - slot.SlotsLayout.padding.bottom) / 2.0,
422
"Automatic vertical positioning: verticalCenterOffset, \"vertically centered\" positioning mode ")
428
function test_contentPadding_data() {
429
return standardTestsData()
431
function test_contentPadding(data) {
432
checkDefaultPadding(data.item)
435
function test_implicitSize_data() {
436
return standardTestsData()
438
function test_implicitSize(data) {
439
checkImplicitSize(data.item)
442
function test_layout_data(){
443
return standardTestsData()
445
function test_layout(data) {
446
checkSlotsPosition(data.item)
449
function test_customPadding_data(){
451
{ tag: "Custom padding", item: layoutCustomPadding },
454
function test_customPadding(data) {
455
compare(data.item.padding.top, units.gu(1), "Custom padding top")
456
compare(data.item.padding.bottom, units.gu(2), "Custom padding bottom")
457
compare(data.item.padding.leading, units.gu(3), "Custom padding leading")
458
compare(data.item.padding.trailing, units.gu(4), "Custom padding trailing")
459
compare(data.item.implicitHeight, expectedImplicitHeight(data.item),
460
"Implicit height with custom padding")
463
var newLeadingSlotHeight = data.item.height + units.gu(2)
464
layoutCustomPadding.leadingSlots[0].height = newLeadingSlotHeight;
465
compare(data.item.leadingSlots[0].height, newLeadingSlotHeight, "Leading slot height update")
467
//check that the padding stays the same, but the height changes
468
compare(data.item.padding.top, units.gu(1), "Custom padding top")
469
compare(data.item.padding.bottom, units.gu(2), "Custom padding bottom")
470
compare(data.item.padding.leading, units.gu(3), "Custom padding leading")
471
compare(data.item.padding.trailing, units.gu(4), "Custom padding trailing")
472
compare(data.item.implicitHeight, newLeadingSlotHeight + data.item.padding.top + data.item.padding.bottom,
473
"Implicit height with custom padding after relayout")
474
compare(expectedImplicitHeight(data.item), newLeadingSlotHeight + data.item.padding.top + data.item.padding.bottom,
475
"expectedImplicitHeight test")
477
//check that slots are still in the right position
478
checkSlotsPosition(data.item)
481
function test_relayoutAfterChangingSlotsSize() {
482
checkSlotsPosition(layoutTestChangeSlotsSize)
484
layoutTestChangeSlotsSize.leadingSlots[0].width = units.gu(12)
485
compare(layoutTestChangeSlotsSize.leadingSlots[0].width, units.gu(12), "Change slot's width")
486
checkSlotsPosition(layoutTestChangeSlotsSize)
488
layoutTestChangeSlotsSize.leadingSlots[0].height = layoutTestChangeSlotsSize.mainSlot.height
489
compare(layoutTestChangeSlotsSize.leadingSlots[0].height,
490
layoutTestChangeSlotsSize.mainSlot.height, "Change slot's height")
491
compare(layoutTestChangeSlotsSize.implicitHeight,
492
layoutTestChangeSlotsSize.mainSlot.height
493
+ layoutTestChangeSlotsSize.padding.top
494
+ layoutTestChangeSlotsSize.padding.bottom,
495
"Layout's implicit height check after slot's height change")
496
checkSlotsPosition(layoutTestChangeSlotsSize)
497
checkImplicitSize(layoutTestChangeSlotsSize)
500
function test_mainSlotSize() {
501
compare(layoutTestMainSlotSize.mainSlot.width,
502
layoutTestMainSlotSize.width
503
- layoutTestMainSlotSize.padding.leading - layoutTestMainSlotSize.padding.trailing
504
- layoutTestMainSlotSize.trailingSlots[0].width
505
- layoutTestMainSlotSize.trailingSlots[0].SlotsLayout.padding.leading
506
- layoutTestMainSlotSize.trailingSlots[0].SlotsLayout.padding.trailing
507
- layoutTestMainSlotSize.mainSlot.SlotsLayout.padding.leading
508
- layoutTestMainSlotSize.mainSlot.SlotsLayout.padding.trailing,
511
compare(layoutTestMainSlotSize.mainSlot.height,
512
layoutTestMainSlotSize.title.height,
513
"Main slot's height, title only")
515
layoutTestMainSlotSize.subtitle.text = "Test here"
516
compare(layoutTestMainSlotSize.mainSlot.height,
517
layoutTestMainSlotSize.subtitle.y + layoutTestMainSlotSize.subtitle.height,
518
"Main slot's height, title+subtitle")
520
layoutTestMainSlotSize.summary.text = "Test here"
521
compare(layoutTestMainSlotSize.mainSlot.height,
522
layoutTestMainSlotSize.summary.y + layoutTestMainSlotSize.summary.height,
523
"Main slot's height, title+subtitle+summary")
525
checkSlotsPosition(layoutTestMainSlotSize)
528
function test_changeSlotPosition() {
529
checkSlotsPosition(layoutTestChangeSlotPosition)
530
layoutTestChangeSlotPosition.leadingSlots[0].SlotsLayout.position = SlotsLayout.Trailing
531
compare(layoutTestChangeSlotPosition.leadingSlots[0].SlotsLayout.position, SlotsLayout.Trailing, "Slot's position change to Trailing")
533
layoutTestChangeSlotPosition.trailingSlots = [layoutTestChangeSlotPosition.leadingSlots[0]]
534
layoutTestChangeSlotPosition.leadingSlots = []
535
compare(layoutTestChangeSlotPosition.leadingSlots.length, 0, "Change slot's position, leading slots array")
536
compare(layoutTestChangeSlotPosition.trailingSlots.length, 1, "Change slot's position, trailing slots array")
537
checkSlotsPosition(layoutTestChangeSlotPosition)
539
layoutTestChangeSlotPosition.trailingSlots[0].SlotsLayout.position = SlotsLayout.First
540
compare(layoutTestChangeSlotPosition.trailingSlots[0].SlotsLayout.position, SlotsLayout.First, "Slot's position change to First")
541
layoutTestChangeSlotPosition.leadingSlots = [layoutTestChangeSlotPosition.trailingSlots[0]]
542
layoutTestChangeSlotPosition.trailingSlots = []
543
compare(layoutTestChangeSlotPosition.leadingSlots.length, 1, "Change slot's position, leading slots array")
544
compare(layoutTestChangeSlotPosition.trailingSlots.length, 0, "Change slot's position, trailing slots array")
545
checkSlotsPosition(layoutTestChangeSlotPosition)
548
function test_slotVisibilityChange() {
549
layoutTestSlotVisibilityChange.leadingSlots[0].visible = false
550
compare(layoutTestSlotVisibilityChange.leadingSlots[0].visible, false, "Slot's visibility, false")
551
var tmpSlot = layoutTestSlotVisibilityChange.leadingSlots[0]
552
layoutTestSlotVisibilityChange.leadingSlots = []
553
compare(layoutTestSlotVisibilityChange.leadingSlots.length, 0, "Slot's visibility, fake leading slots count")
554
compare(layoutTestSlotVisibilityChange.trailingSlots.length, 0, "Slot's visibility, fake trailing slots count")
556
checkSlotsPosition(layoutTestSlotVisibilityChange)
557
checkImplicitSize(layoutTestSlotVisibilityChange)
559
layoutTestSlotVisibilityChange.leadingSlots = [tmpSlot]
560
layoutTestSlotVisibilityChange.leadingSlots[0].visible = true
561
compare(layoutTestSlotVisibilityChange.leadingSlots[0].visible, true, "Slot's visibility, true")
562
compare(layoutTestSlotVisibilityChange.mainSlot.height
563
< layoutTestSlotVisibilityChange.leadingSlots[0].height, true, "Visibility test, slot's height")
564
checkSlotsPosition(layoutTestSlotVisibilityChange)
565
checkImplicitSize(layoutTestSlotVisibilityChange)
569
function test_relativePositioning_data(){
571
{ tag: "Relative positioning 1", item: layoutTestRelativePositioning },
572
{ tag: "Relative positioning 2", item: layoutTestRelativePositioning2 }
575
function test_relativePositioning(data) {
576
checkSlotsPosition(data.item)
579
function test_nullSizeSlots() {
580
compare(layoutTestNullSizeSlots.trailingSlots.length, 2, "Null size slot test, fake trailing slots list")
581
checkSlotsPosition(layoutTestNullSizeSlots)
582
checkImplicitSize(layoutTestNullSizeSlots)
584
layoutTestNullSizeSlots.trailingSlots[0].height = 0
585
compare(layoutTestNullSizeSlots.trailingSlots[0].height, 0, "Null size slot test, slot's height")
586
//remove that slot from the list of slots we expect to be laid out
587
var tmpSlot = layoutTestNullSizeSlots.trailingSlots[0]
588
layoutTestNullSizeSlots.trailingSlots = [layoutTestNullSizeSlots.trailingSlots[1]]
589
compare(layoutTestNullSizeSlots.trailingSlots.length, 1, "Null size slot test, fake trailing slots list")
590
checkSlotsPosition(layoutTestNullSizeSlots)
591
checkImplicitSize(layoutTestNullSizeSlots)
593
layoutTestNullSizeSlots.trailingSlots[0].width = 0
594
compare(layoutTestNullSizeSlots.trailingSlots[0].width, 0, "Null size slot test, slot's width")
595
var tmpSlot2 = layoutTestNullSizeSlots.trailingSlots[0]
596
layoutTestNullSizeSlots.trailingSlots = []
597
compare(layoutTestNullSizeSlots.trailingSlots.length, 0, "Null size slot test, fake trailing slots list")
598
checkSlotsPosition(layoutTestNullSizeSlots)
599
checkImplicitSize(layoutTestNullSizeSlots)
601
//bring the first slot back
603
compare(tmpSlot.height, 300, "Null size slot test, slot's height")
604
layoutTestNullSizeSlots.trailingSlots = [tmpSlot]
605
compare(layoutTestNullSizeSlots.trailingSlots.length, 1, "Null size slot test, fake trailing slots list")
606
checkSlotsPosition(layoutTestNullSizeSlots)
607
checkImplicitSize(layoutTestNullSizeSlots)
609
//bring the second slot back
611
compare(tmpSlot2.width, 22, "Null size slot test, slot's width")
612
layoutTestNullSizeSlots.trailingSlots = [tmpSlot, tmpSlot2]
613
compare(layoutTestNullSizeSlots.trailingSlots.length, 2, "Null size slot test, fake trailing slots list")
614
checkSlotsPosition(layoutTestNullSizeSlots)
615
checkImplicitSize(layoutTestNullSizeSlots)
618
function test_overrideVerticalPositioning() {
619
//we expect the component to reset the vertical anchors when overrideVerticalPositioning changes value
620
compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].anchors.bottom,
621
layoutTestOverrideVerticalPositioning.bottom,
622
"Override vertical positioning test, initial slot's bottom anchor")
623
compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning,
624
true, "Override vertical positioning test, attached-property's initial value")
625
compare(layoutTestOverrideVerticalPositioning.trailingSlots.length, 2,
626
"Override vertical positioning test, fake trailing slots list")
627
layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning = false
628
compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning,
629
false, "Override vertical positioning test, attached-property's new value, false")
630
checkSlotsPosition(layoutTestOverrideVerticalPositioning)
631
checkImplicitSize(layoutTestOverrideVerticalPositioning)
633
layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning = true
634
compare(layoutTestOverrideVerticalPositioning.trailingSlots[1].SlotsLayout.overrideVerticalPositioning,
635
true, "Override vertical positioning test, attached-property's new value, true")
636
checkSlotsPosition(layoutTestOverrideVerticalPositioning)
637
checkImplicitSize(layoutTestOverrideVerticalPositioning)
640
function test_ignoreSomeChangesOnMainSlot() {
641
compare(layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots.length, 1,
642
"Ignore some changes on main slot test, fake trailing slots list")
643
compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.overrideVerticalPositioning,
644
false, "Ignore some changes on main slot test, default override value")
645
//we want main slot to be vertically centered, to check if disabling overrideVerticalPositioning
646
//will cause a change in its position
647
compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.height
648
< maxSlotsHeight(layoutTestIgnoreSomeChangesOnMainSlot), true,
649
"Ignore some changes on main slot test, slot's height")
650
checkSlotsPosition(layoutTestIgnoreSomeChangesOnMainSlot)
651
checkImplicitSize(layoutTestIgnoreSomeChangesOnMainSlot)
653
//this shouldn't trigger a relayout
654
layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.overrideVerticalPositioning = true
655
compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.overrideVerticalPositioning,
656
true, "Ignore some changes on main slot test, new override value")
657
//let's force a relayout, just to make sure changing overrideVerticalPositioning
658
//didn't have any effect on mainSlot
659
layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots[0].height += 100
660
checkSlotsPosition(layoutTestIgnoreSomeChangesOnMainSlot)
661
checkImplicitSize(layoutTestIgnoreSomeChangesOnMainSlot)
663
//let's try to force positioning mainSlot *before* a leading slot. This must fail
664
layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.position =
665
layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots[0].SlotsLayout.position - 5
666
compare(layoutTestIgnoreSomeChangesOnMainSlot.mainSlot.SlotsLayout.position,
667
layoutTestIgnoreSomeChangesOnMainSlot.leadingSlots[0].SlotsLayout.position - 5,
668
"Ignore some changes on main slot test, change mainSlot's position")
669
checkSlotsPosition(layoutTestIgnoreSomeChangesOnMainSlot)
670
checkImplicitSize(layoutTestIgnoreSomeChangesOnMainSlot)
673
function test_changeAttachedPropertiesInMainSlot() {
674
checkSlotsPosition(layoutTestMainSlotAttachedProps)
675
checkImplicitSize(layoutTestMainSlotAttachedProps)
676
var mainSlot = layoutTestMainSlotAttachedProps.mainSlot
678
mainSlot.SlotsLayout.padding.top = 300
679
compare(layoutTestMainSlotAttachedProps.mainSlot.SlotsLayout.padding.top, 300,
680
"Change mainSlot's attached props test, padding.top")
681
checkSlotsPosition(layoutTestMainSlotAttachedProps)
682
checkImplicitSize(layoutTestMainSlotAttachedProps)
684
mainSlot.SlotsLayout.padding.bottom = 180
685
compare(mainSlot.SlotsLayout.padding.bottom, 180,
686
"Change mainSlot's attached props test, padding.bottom")
687
checkSlotsPosition(layoutTestMainSlotAttachedProps)
688
checkImplicitSize(layoutTestMainSlotAttachedProps)
691
function test_defaultSlotsAttachedProps() {
692
var slot = layoutTestDefaultSlotsAttachedProps.trailingSlots[0]
693
compare(slot.SlotsLayout.position, SlotsLayout.Trailing,
694
"Default slots attached props, position")
695
compare(slot.SlotsLayout.overrideVerticalPositioning, false,
696
"Default slots attached props, overrideVerticalPositioning")
697
compare(slot.SlotsLayout.padding.top, 0,
698
"Default slots attached props, padding.top")
699
compare(slot.SlotsLayout.padding.bottom, 0,
700
"Default slots attached props, padding.bottom")
701
compare(slot.SlotsLayout.padding.leading, units.gu(1),
702
"Default slots attached props, padding.leading")
703
compare(slot.SlotsLayout.padding.trailing, units.gu(1),
704
"Default slots attached props, padding.trailing")
707
function checkLabelsY(listitemlayout) {
708
compare(listitemlayout.title.y, 0,
709
"Default labels positioning, title's y")
711
//we don't care about having the correct Y if the label
712
//is empty or not visible anyway
713
if (listitemlayout.subtitle.text !== ""
714
&& listitemlayout.subtitle.visible) {
715
if (listitemlayout.title.text === "" ||
716
!listitemlayout.title.visible) {
717
compare(listitemlayout.subtitle.y, 0,
718
"Default labels positioning, subtitle's y")
720
compare(listitemlayout.subtitle.y,
721
listitemlayout.title.baselineOffset + units.dp(4),
722
"Default labels positioning, subtitle's y")
726
//we don't care about having the correct Y if the label
727
//is empty or not visible anyway
728
if (listitemlayout.summary.text !== ""
729
&& listitemlayout.summary.visible) {
730
if (listitemlayout.subtitle.text === "" ||
731
!listitemlayout.subtitle.visible) {
732
if (listitemlayout.title.text === "" ||
733
!listitemlayout.title.visible) {
734
compare(listitemlayout.summary.y, 0,
735
"Default labels positioning, summary's y")
737
compare(listitemlayout.summary.y, listitemlayout.title.baselineOffset + units.dp(4),
738
"Default labels positioning, summary's y")
741
compare(listitemlayout.summary.y, listitemlayout.subtitle.y + listitemlayout.subtitle.height,
742
"Default labels positioning, summary's y")
747
function test_defaultMainSlotHeight() {
748
var titleText = layoutLabels.title.text
749
var subtitleText = layoutLabels.subtitle.text
750
var summaryText = layoutLabels.summary.text
752
compare(titleText.length > 0, true, "Default labels positioning, title length")
753
compare(subtitleText.length > 0, true, "Default labels positioning, subtitle length")
754
compare(summaryText.length > 0, true, "Default labels positioning, summary length")
755
checkLabelsY(layoutLabels)
757
var initialHeight = layoutLabels.mainSlot.height
758
compare(initialHeight, layoutLabels.summary.y + layoutLabels.summary.height,
759
"Default labels positioning, mainSlot's height")
761
//setting text to " " (note, it's NOT empty) should have the same effect as setting it to "blabla"
762
layoutLabels.summary.text = " "
763
compare(layoutLabels.summary.text, " ", "Default labels positioning, summary 1 whitespace text")
764
compare(layoutLabels.mainSlot.height, initialHeight,
765
"Default labels positioning, mainSlot's height")
766
checkLabelsY(layoutLabels)
768
//empty text -> we ignore summary in the height computation
769
layoutLabels.summary.text = ""
770
compare(layoutLabels.summary.text, "", "Default labels positioning, empty summary text")
771
compare(layoutLabels.mainSlot.height, layoutLabels.subtitle.y + layoutLabels.subtitle.height,
772
"Default labels positioning, mainSlot's height")
773
checkLabelsY(layoutLabels)
775
layoutLabels.subtitle.text = ""
776
compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
777
compare(layoutLabels.mainSlot.height, layoutLabels.title.y + layoutLabels.title.height,
778
"Default labels positioning, mainSlot's height")
779
checkLabelsY(layoutLabels)
781
//all labels are empty now
782
layoutLabels.title.text = ""
783
compare(layoutLabels.title.text, "", "Default labels positioning, empty title text")
784
compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
785
compare(layoutLabels.summary.text, "", "Default labels positioning, empty summary text")
786
compare(layoutLabels.mainSlot.height, 0,
787
"Default labels positioning, mainSlot's height")
788
checkLabelsY(layoutLabels)
790
//try title and summary, skipping subtitle
791
layoutLabels.title.text = "test"
792
layoutLabels.summary.text = "test"
793
compare(layoutLabels.title.text, "test", "Default labels positioning, empty title text")
794
compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
795
compare(layoutLabels.summary.text, "test", "Default labels positioning, empty summary text")
796
compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
797
"Default labels positioning, mainSlot's height")
798
checkLabelsY(layoutLabels)
800
//let's try with summary only
801
layoutLabels.title.text = ""
802
compare(layoutLabels.title.text, "", "Default labels positioning, empty title text")
803
compare(layoutLabels.subtitle.text, "", "Default labels positioning, empty subtitle text")
804
compare(layoutLabels.summary.text, "test", "Default labels positioning, empty summary text")
805
compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
806
"Default labels positioning, mainSlot's height")
807
checkLabelsY(layoutLabels)
809
//try to set all texts and test positions again
810
layoutLabels.title.text = titleText
811
layoutLabels.subtitle.text = subtitleText
812
layoutLabels.summary.text = summaryText
813
compare(layoutLabels.mainSlot.height, initialHeight,
814
"Default labels positioning, mainSlot's height")
815
checkLabelsY(layoutLabels)
818
function test_fontsizeChange() {
819
var initialHeight = layoutLabels.mainSlot.height
820
compare(layoutLabels.title.textSize, Label.Medium, "Labels textSize change, default title textsize")
821
compare(layoutLabels.subtitle.textSize, Label.Small, "Labels textSize change, default subtitle textsize")
822
compare(layoutLabels.summary.textSize, Label.Small, "Labels textSize change, default summary textsize")
824
compare(layoutLabels.title.text.length > 0, true, "Default labels positioning, title length")
825
compare(layoutLabels.subtitle.text.length > 0, true, "Default labels positioning, subtitle length")
826
compare(layoutLabels.summary.text.length > 0, true, "Default labels positioning, summary length")
827
compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
828
"Default labels positioning, main slot height")
830
layoutLabels.title.textSize = Label.XLarge
831
compare(layoutLabels.title.textSize, Label.XLarge, "Labels textSize change, new title textsize")
832
compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
833
"Default labels positioning, main slot height")
835
layoutLabels.subtitle.textSize = Label.XLarge
836
compare(layoutLabels.subtitle.textSize, Label.XLarge, "Labels textSize change, new subtitle textsize")
837
compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
838
"Default labels positioning, main slot height")
840
layoutLabels.summary.textSize = Label.XLarge
841
compare(layoutLabels.summary.textSize, Label.XLarge, "Labels textSize change, new summary textsize")
842
compare(layoutLabels.mainSlot.height, layoutLabels.summary.y + layoutLabels.summary.height,
843
"Default labels positioning, main slot height")
846
Label {id: customMainSlot }
847
function test_warningOnAttemptToChangeListItemLayoutMainSlot() {
848
ignoreWarning(warningFormat(60, 9, "QML ListItemLayout: Setting a different mainSlot on ListItemLayout is not supported. Please use SlotsLayout instead."))
849
layoutLabels.mainSlot = customMainSlot
854
id: layoutTestQmlContextComponent
856
id: layoutTestQmlContext
857
title.text: "<html><body><p dir='ltr'>TEST <img align=absmiddle height=\"10\" width=\"10\" src=\"file:///test.png\" /> </p></body></html>"
858
title.textFormat: Text.RichText
859
subtitle.text: "<html><body><p dir='ltr'>TEST <img align=absmiddle height=\"10\" width=\"10\" src=\"file:///test.png\" /> </p></body></html>"
860
subtitle.textFormat: Text.RichText
861
summary.text: "<html><body><p dir='ltr'>TEST <img align=absmiddle height=\"10\" width=\"10\" src=\"file:///test.png\" /> </p></body></html>"
862
summary.textFormat: Text.RichText
866
//this will make the test segfault if there is a regression
867
function test_defaultLabelsQmlContext() {
868
ignoreWarning(warningMsg("QML Label: Cannot open: file:///test.png"))
869
var obj = layoutTestQmlContextComponent.createObject(main)
870
//wait for rendering otherwise we will not get the "cannot find file" warning
871
//because the img is loaded async
872
waitForRendering(obj)
873
compare(obj !== null, true, "QML ListItemLayout: testing labels' QML context.")