2
* Copyright 2013 Canonical Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU 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 General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
import "../../../Components"
21
import Ubuntu.Components.ListItems 0.1 as ListItem
22
import Ubuntu.Components 0.1
23
import Unity.Test 0.1 as UT
26
width: flowRect.width + controls.width
33
anchors.top: parent.top
34
anchors.right: parent.right
35
ListItem.ValueSelector {
36
id: maxColumnsSelector
37
text: "maximumNumberOfColumns"
38
values: [2,4,8,13,1000]
41
ListItem.ValueSelector {
42
id: minHSpacingSelector
43
text: "minHorizontalSpacing"
44
values: [0,units.gu(2),units.gu(8),units.gu(25)]
51
ListElement { name: "A" }
52
ListElement { name: "B" }
53
ListElement { name: "C" }
54
ListElement { name: "D" }
55
ListElement { name: "E" }
56
ListElement { name: "F" }
57
ListElement { name: "G" }
58
ListElement { name: "H" }
59
ListElement { name: "I" }
60
ListElement { name: "J" }
61
ListElement { name: "K" }
62
ListElement { name: "L" }
63
ListElement { name: "M" }
64
ListElement { name: "N" }
65
ListElement { name: "O" }
66
ListElement { name: "P" }
67
ListElement { name: "Q" }
68
ListElement { name: "R" }
69
ListElement { name: "S" }
70
ListElement { name: "T" }
71
ListElement { name: "U" }
79
anchors.top: parent.top
80
anchors.left: parent.left
86
secondModel: fakeModel
87
minimumHorizontalSpacing:
88
minHSpacingSelector.values[minHSpacingSelector.selectedIndex]
89
verticalSpacing: units.gu(2)
90
maximumNumberOfColumns:
91
maxColumnsSelector.values[maxColumnsSelector.selectedIndex]
92
referenceDelegateWidth: units.gu(6)
95
// So that it can be identified by test code
96
property bool isFlowDelegate: true
101
// IMPORTANT: always use flow's cellWidth and cellHeight here to get
102
// ResponsiveFlowView's intended result
103
width: flow.cellWidth
104
height: flow.cellHeight
108
anchors.centerIn: parent
112
anchors.centerIn: parent
117
Text { x:0; y:0; text:"(" + parent.x + ", " + parent.y + ")"}
123
name: "ResponsiveFlowView"
126
function test_maximumNumberOfColumns_data() {
127
var data = new Array()
129
data.push({selectedIndex: 0, maxColumnCount:2, columnCount: 2})
130
data.push({selectedIndex: 1, maxColumnCount:4, columnCount: 4})
131
data.push({selectedIndex: 2, maxColumnCount:8, columnCount: 8})
132
data.push({selectedIndex: 4, maxColumnCount:1000, columnCount: 13})
137
/* Change ResponsiveFlowView's maximumNumberOfColumns property and check
138
that the resulting number of columns matches expectations */
139
function test_maximumNumberOfColumns(data) {
140
minHSpacingSelector.selectedIndex = 0
143
compare(maxColumnsSelector.values[data.selectedIndex], data.maxColumnCount)
144
compare(minHSpacingSelector.values[0], 0)
146
maxColumnsSelector.selectedIndex = data.selectedIndex
147
tryCompareFunction(countFlowDelegatesOnFirstRow, data.columnCount);
148
compare(flow.columns, data.columnCount)
151
function test_minimumHorizontalSpacing_data() {
152
var data = new Array()
154
data.push({selectedIndex: 0, minHSpacing:0, columnCount: 13})
155
data.push({selectedIndex: 1, minHSpacing:units.gu(2), columnCount: 9})
156
data.push({selectedIndex: 2, minHSpacing:units.gu(8), columnCount: 5})
157
data.push({selectedIndex: 3, minHSpacing:units.gu(25), columnCount: 2})
162
/* Change ResponsiveFlowView's minimumHorizontalSpacing property and check
163
that the resulting number of columns matches expectations */
164
function test_minimumHorizontalSpacing(data) {
165
maxColumnsSelector.selectedIndex = 4
168
compare(maxColumnsSelector.values[4], 1000)
169
compare(minHSpacingSelector.values[data.selectedIndex], data.minHSpacing)
171
minHSpacingSelector.selectedIndex = data.selectedIndex
172
tryCompareFunction(countFlowDelegatesOnFirstRow, data.columnCount);
173
compare(flow.columns, data.columnCount)
176
function countFlowDelegatesOnFirstRow() {
177
return __countFlowDelegatesOnFirstRow(flow.visibleChildren, 0)
180
function __countFlowDelegatesOnFirstRow(objList, total) {
181
for (var i = 0; i < objList.length; ++i) {
182
var child = objList[i];
183
if (child.isFlowDelegate !== undefined && child.y === 0) {
186
total = __countFlowDelegatesOnFirstRow(child.visibleChildren, total)