Merge lp:~mzanetti/ubuntu-ui-toolkit/ubuntulistview into lp:ubuntu-ui-toolkit

Proposed by Michael Zanetti
Status: Merged
Approved by: Zsombor Egri
Approved revision: 954
Merged at revision: 956
Proposed branch: lp:~mzanetti/ubuntu-ui-toolkit/ubuntulistview
Merge into: lp:ubuntu-ui-toolkit
Prerequisite: lp:~mzanetti/ubuntu-ui-toolkit/expandable-and-column
Diff against target: 544 lines (+439/-7)
7 files modified
components.api (+3/-0)
examples/ubuntu-ui-toolkit-gallery/ListItems.qml (+51/-0)
modules/Ubuntu/Components/ListItems/Expandable.qml (+30/-7)
modules/Ubuntu/Components/UbuntuListView.qml (+121/-0)
modules/Ubuntu/Components/qmldir (+1/-0)
modules/Ubuntu/Test/UbuntuTestCase.qml (+35/-0)
tests/unit_x11/tst_components/tst_ubuntulistview.qml (+198/-0)
To merge this branch: bzr merge lp:~mzanetti/ubuntu-ui-toolkit/ubuntulistview
Reviewer Review Type Date Requested Status
Zsombor Egri Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+206161@code.launchpad.net

Commit message

Introduce the almighty UbuntuListView. So far not /that/ mighty tho. Can only deal with Expandables.

To post a comment you must log in.
941. By Michael Zanetti

merge prerequisite branch

942. By Michael Zanetti

add UbuntuListView to the gallery

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

"can only deal with Expandables" - I guess it can also deal with other elements in between, right?

Revision history for this message
Zsombor Egri (zsombi) wrote :

I see you still have the item-based property/function. We agreed that this is not good as when scrolled out of the cacheBuffer, ListView will re-create the item when scrolled back and will no longer be the same instance as the previous one...
Or are you still working on that?

Revision history for this message
Michael Zanetti (mzanetti) wrote :

yep... didn't get to it yet... Had to do unity8 stuff for MWC. Will get to this now.

Revision history for this message
Michael Zanetti (mzanetti) wrote :

> "can only deal with Expandables" - I guess it can also deal with other
> elements in between, right?

Yes, it can. However, in terms of "mightyness" it adds only the Expandables compared with the standard ListView.

943. By Michael Zanetti

change UbuntuListView to work with expandedIndex instead of expandedItem

944. By Michael Zanetti

merge trunk

945. By Michael Zanetti

fix docs

946. By Michael Zanetti

merge prerequisite

947. By Michael Zanetti

remove preliminary from docstring

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
948. By Michael Zanetti

readd tests for UbuntuListView

Revision history for this message
Michael Zanetti (mzanetti) wrote :

Ok. Changed the UbuntuListView to operate on an expandedIndex instead of an expandedItem. Definitely makes more sense this way.

This also touches the ExpandableItem a bit to add support for a parent Column and a parent ListView to it.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
949. By Michael Zanetti

merge prerequistite branch

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

96 + Gives information whether this item is inside an item based container supporting Expandable items, such as ExpandablesColumn
97 + */
98 + readonly property bool isInExpandableColumn: view && view !== undefined && view.hasOwnProperty("expandItem") && view.hasOwnProperty("collapse")

"expandedItem" does no longer exist for the UbuntuListView... Same everywhere.

review: Needs Fixing
Revision history for this message
Zsombor Egri (zsombi) wrote :

> 96 + Gives information whether this item is inside an item based
> container supporting Expandable items, such as ExpandablesColumn
> 97 + */
> 98 + readonly property bool isInExpandableColumn: view && view !==
> undefined && view.hasOwnProperty("expandItem") &&
> view.hasOwnProperty("collapse")
>
> "expandedItem" does no longer exist for the UbuntuListView... Same everywhere.

Aaaah, forget about this :)

950. By Michael Zanetti

added a test for moving expanded item out of the view and bringing it back in.

fix issue with originY not being taken into account which was breaking logic in some circumstances

951. By Michael Zanetti

change UbuntuTestCase::tryCompareFunction to provide an optional timeout parameter

Revision history for this message
Zsombor Egri (zsombi) wrote :

Excellent stuff! Thanks again!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
952. By Michael Zanetti

fix year in test header

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
953. By Michael Zanetti

fix className reference in gallery

954. By Michael Zanetti

merge prerequisite

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

CI@home is all green.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components.api'
--- components.api 2014-02-26 09:47:24 +0000
+++ components.api 2014-02-26 09:47:24 +0000
@@ -567,6 +567,9 @@
567 property Item pageStack567 property Item pageStack
568 property bool opened568 property bool opened
569 property bool locked569 property bool locked
570modules/Ubuntu/Components/UbuntuListView.qml
571ListView
572 property int expandedIndex
570modules/Ubuntu/Components/UbuntuNumberAnimation.qml573modules/Ubuntu/Components/UbuntuNumberAnimation.qml
571NumberAnimation574NumberAnimation
572modules/Ubuntu/Components/UbuntuShape.qml575modules/Ubuntu/Components/UbuntuShape.qml
573576
=== modified file 'examples/ubuntu-ui-toolkit-gallery/ListItems.qml'
--- examples/ubuntu-ui-toolkit-gallery/ListItems.qml 2014-02-26 09:47:24 +0000
+++ examples/ubuntu-ui-toolkit-gallery/ListItems.qml 2014-02-26 09:47:24 +0000
@@ -224,6 +224,57 @@
224 }224 }
225225
226 TemplateSection {226 TemplateSection {
227 title: i18n.tr("UbuntuListView")
228 className: "UbuntuListView"
229
230 ListModel {
231 id: fruitModel
232 ListElement { name: "Orange"; details: "The orange (specifically, the sweet orange) is the fruit of the citrus species Citrus × ​sinensis in the family Rutaceae. The fruit of the Citrus sinensis is called sweet orange to distinguish it from that of the Citrus aurantium, the bitter orange. The orange is a hybrid, possibly between pomelo (Citrus maxima) and mandarin (Citrus reticulata), cultivated since ancient times.\n-\nWikipedia"}
233 ListElement { name: "Apple"; details: "Fruit" }
234 ListElement { name: "Tomato"; details: "The tomato is the edible, often red fruit of the plant Solanum lycopersicum, commonly known as a tomato plant. Both the species and its use as a food originated in Mexico, and spread throughout the world following the Spanish colonization of the Americas. Its many varieties are now widely grown, sometimes in greenhouses in cooler climates. The tomato is consumed in diverse ways, including raw, as an ingredient in many dishes, sauces, salads, and drinks. While it is botanically a fruit, it is considered a vegetable for culinary purposes (as well as under U.S. customs regulations, see Nix v. Hedden), which has caused some confusion. The fruit is rich in lycopene, which may have beneficial health effects. The tomato belongs to the nightshade family (Solanaceae). The plants typically grow to 1–3 meters (3–10 ft) in height and have a weak stem that often sprawls over the ground and vines over other plants. It is a perennial in its native habitat, although often grown outdoors in temperate climates as an annual. An average common tomato weighs approximately 100 grams (4 oz).\n-\nWikipedia" }
235 ListElement { name: "Carrot"; details: "Vegetable" }
236 ListElement { name: "Potato"; details: "Vegetable" }
237 }
238
239 Toolkit.UbuntuListView {
240 id: ubuntuListView
241 anchors { left: parent.left; right: parent.right }
242 height: units.gu(24)
243 model: fruitModel
244 clip: true
245
246 delegate: ListItem.Expandable {
247 id: expandingItem
248
249 expandedHeight: contentColumn.height + units.gu(1)
250
251 onClicked: {
252 ubuntuListView.expandedIndex = index;
253 }
254
255 Column {
256 id: contentColumn
257 anchors { left: parent.left; right: parent.right }
258 Item {
259 anchors { left: parent.left; right: parent.right}
260 height: expandingItem.collapsedHeight
261 Toolkit.Label {
262 anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter}
263 text: model.name
264 }
265 }
266
267 Toolkit.Label {
268 anchors { left: parent.left; right: parent.right }
269 text: model.details
270 wrapMode: Text.WordWrap
271 }
272 }
273 }
274 }
275 }
276
277 TemplateSection {
227 title: i18n.tr("ExpandablesColumn")278 title: i18n.tr("ExpandablesColumn")
228 className: "ExpandablesColumn"279 className: "ExpandablesColumn"
229280
230281
=== modified file 'modules/Ubuntu/Components/ListItems/Expandable.qml'
--- modules/Ubuntu/Components/ListItems/Expandable.qml 2014-02-26 09:47:24 +0000
+++ modules/Ubuntu/Components/ListItems/Expandable.qml 2014-02-26 09:47:24 +0000
@@ -25,7 +25,7 @@
25 components such as buttons. It subclasses \l Empty and thus brings all that25 components such as buttons. It subclasses \l Empty and thus brings all that
26 functionality, but additionally provides means to expand and collapse the item.26 functionality, but additionally provides means to expand and collapse the item.
2727
28 When used together with an UbuntuListView or \l ExpandablesColumn it28 When used together with an \l UbuntuListView or \l ExpandablesColumn it
29 can coordinate with other items in the list to make sure it is scrolled while29 can coordinate with other items in the list to make sure it is scrolled while
30 expanding to be fully visible in the view. Additionally it is made sure that30 expanding to be fully visible in the view. Additionally it is made sure that
31 only one Expandable item is expanded at a time and it is collapsed when the31 only one Expandable item is expanded at a time and it is collapsed when the
@@ -110,19 +110,25 @@
110 property Item view: root.ListView.view ? root.ListView.view : (root.parent.parent.parent.hasOwnProperty("expandItem") ? root.parent.parent.parent : null)110 property Item view: root.ListView.view ? root.ListView.view : (root.parent.parent.parent.hasOwnProperty("expandItem") ? root.parent.parent.parent : null)
111111
112 /*! \internal112 /*! \internal
113 Gives information whether this item is inside a ExpandablesListView or ExpandablesColumn113 Gives information whether this item is inside an item based container supporting Expandable items, such as ExpandablesColumn
114 */114 */
115 readonly property bool isInExpandableList: view && view !== undefined && view.hasOwnProperty("expandItem") && view.hasOwnProperty("collapse")115 readonly property bool isInExpandableColumn: view && view !== undefined && view.hasOwnProperty("expandItem") && view.hasOwnProperty("collapse")
116
117 /*! \internal
118 Gives information whether this item is inside an index based container supporting Expandable items, such as UbuntuListView
119 */
120 readonly property bool isInExpandableListView: view && view !== undefined && view.hasOwnProperty("expandedIndex")
116121
117 /*! \internal122 /*! \internal
118 Gives information if there is another item expanded in the containing ExpandablesListView or ExpandablesColumn123 Gives information if there is another item expanded in the containing ExpandablesListView or ExpandablesColumn
119 */124 */
120 readonly property bool otherExpanded: isInExpandableList && view.expandedItem !== null && view.expandedItem !== undefined && view.expandedItem !== root125 readonly property bool otherExpanded: (isInExpandableColumn && view.expandedItem !== null && view.expandedItem !== undefined && view.expandedItem !== root)
126 || (isInExpandableListView && view.expandedIndex !== -1 && view.expandedIndex !== index)
121127
122 /*! \internal128 /*! \internal
123 Gives information about the maximum expanded height, in case that is limited by the containing ExpandablesListView or ExpandablesColumn129 Gives information about the maximum expanded height, in case that is limited by the containing ExpandablesListView or ExpandablesColumn
124 */130 */
125 readonly property real maxExpandedHeight: isInExpandableList ? Math.min(view.height - collapsedHeight, expandedHeight) : expandedHeight131 readonly property real maxExpandedHeight: (isInExpandableColumn || isInExpandableListView) ? Math.min(view.height - collapsedHeight, expandedHeight) : expandedHeight
126 }132 }
127133
128 states: [134 states: [
@@ -140,13 +146,30 @@
140 }146 }
141 ]147 ]
142148
149 Component.onCompleted: {
150 if (priv.isInExpandableListView && priv.view.expandedIndex == index) {
151 root.expanded = true;
152 }
153 }
154
155 Connections {
156 target: priv.isInExpandableListView ? priv.view : null
157 onExpandedIndexChanged: {
158 if (priv.view.expandedIndex == index) {
159 root.expanded = true;
160 } else if (root.expanded = true) {
161 root.expanded = false;
162 }
163 }
164 }
165
143 /*! \internal */166 /*! \internal */
144 onExpandedChanged: {167 onExpandedChanged: {
145 if (!expanded) {168 if (!expanded) {
146 contentFlickable.contentY = 0;169 contentFlickable.contentY = 0;
147 }170 }
148171
149 if (priv.isInExpandableList) {172 if (priv.isInExpandableColumn) {
150 if (expanded) {173 if (expanded) {
151 priv.view.expandItem(root);174 priv.view.expandItem(root);
152 } else {175 } else {
153176
=== added file 'modules/Ubuntu/Components/UbuntuListView.qml'
--- modules/Ubuntu/Components/UbuntuListView.qml 1970-01-01 00:00:00 +0000
+++ modules/Ubuntu/Components/UbuntuListView.qml 2014-02-26 09:47:24 +0000
@@ -0,0 +1,121 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17import QtQuick 2.0
18import Ubuntu.Components 0.1 as Toolkit
19
20/*!
21 \qmltype UbuntuListView
22 \inqmlmodule Ubuntu.Components 0.1
23 \ingroup ubuntu
24 \brief A ListView with special features tailored for a look and feel fitting the
25 Ubuntu Touch platform.
26 The UbuntuListView works just like a regular ListView, but it adds special features
27 such as expanding/collapsing items (when used together with the Expandable item).
28 It provides features like automatically positioning the expanding item when it
29 expands and collapsing it again when the user taps outside of it.
30
31 Examples:
32 \qml
33 import Ubuntu.Components 0.1
34 import Ubuntu.Components.ListItems 0.1 as ListItem
35
36 Item {
37 ListModel {
38 id: listModel
39 }
40
41 UbuntuListView {
42 id: ubuntuListView
43 anchors { left: parent.left; right: parent.right }
44 height: units.gu(24)
45 model: listModel
46
47 delegate: ListItem.Expandable {
48 id: expandingItem
49
50 expandedHeight: units.gu(30)
51
52 onClicked: {
53 ubuntuListView.expandedIndex = index;
54 }
55 }
56 }
57 }
58 \endqml
59
60 \b{This component is under heavy development.}
61*/
62
63ListView {
64 id: root
65
66 /*!
67 The index of the currently expanded item. -1 if no item is expanded.
68 */
69 property int expandedIndex: -1
70
71 QtObject {
72 id: priv
73
74 function positionViewAtIndexAnimated(expandedIndex) {
75 animation.from = root.contentY;
76 root.currentIndex = expandedIndex;
77 if (expandedIndex == root.count - 1) {
78 root.positionViewAtIndex(expandedIndex, ListView.End);
79 } else {
80 root.positionViewAtIndex(expandedIndex + 1, ListView.End);
81 }
82
83 var effectiveExpandedHeight = Math.min(root.currentItem.expandedHeight, root.height - root.currentItem.collapsedHeight);
84 if (root.contentY - root.originY == 0) {
85 if (((root.currentIndex + 1) * root.currentItem.collapsedHeight) + effectiveExpandedHeight > root.height) {
86 animation.to = ((root.currentIndex + 1) * root.currentItem.collapsedHeight + effectiveExpandedHeight) - root.height + root.originY
87 } else {
88 animation.to = root.originY
89 }
90 } else {
91 animation.to = root.contentY + (effectiveExpandedHeight - root.currentItem.collapsedHeight);
92 }
93 animation.start();
94 }
95 }
96
97 /*!
98 \preliminary
99 Expand the item at the given index.
100 */
101 onExpandedIndexChanged: {
102 if (expandedIndex < 0) {
103 return;
104 }
105 priv.positionViewAtIndexAnimated(expandedIndex, ListView.End)
106 }
107
108 UbuntuNumberAnimation {
109 id: animation
110 target: root
111 property: "contentY"
112 }
113
114 MouseArea {
115 parent: contentItem
116 anchors.fill: parent
117 z: 2
118 enabled: root.expandedIndex != -1
119 onClicked: root.expandedIndex = -1;
120 }
121}
0122
=== modified file 'modules/Ubuntu/Components/qmldir'
--- modules/Ubuntu/Components/qmldir 2014-01-21 18:27:23 +0000
+++ modules/Ubuntu/Components/qmldir 2014-02-26 09:47:24 +0000
@@ -43,6 +43,7 @@
43StyledItem 0.1 StyledItem.qml43StyledItem 0.1 StyledItem.qml
44ColorUtils 0.1 colorUtils.js44ColorUtils 0.1 colorUtils.js
45DateUtils 0.1 dateUtils.js45DateUtils 0.1 dateUtils.js
46UbuntuListView 0.1 UbuntuListView.qml
4647
47internal TextCursor TextCursor.qml48internal TextCursor TextCursor.qml
48internal TextInputPopover TextInputPopover.qml49internal TextInputPopover TextInputPopover.qml
4950
=== modified file 'modules/Ubuntu/Test/UbuntuTestCase.qml'
--- modules/Ubuntu/Test/UbuntuTestCase.qml 2014-02-19 10:49:07 +0000
+++ modules/Ubuntu/Test/UbuntuTestCase.qml 2014-02-26 09:47:24 +0000
@@ -29,6 +29,9 @@
29 This class extends the default QML TestCase class which is available in QtTest 1.0.29 This class extends the default QML TestCase class which is available in QtTest 1.0.
30*/30*/
31TestCase {31TestCase {
32 TestUtil {
33 id:util
34 }
3235
33 /*!36 /*!
34 Find a child from the item based on the objectName.37 Find a child from the item based on the objectName.
@@ -83,5 +86,37 @@
83 mouseMove(item,x + ix,y + iy,stepdelay);86 mouseMove(item,x + ix,y + iy,stepdelay);
84 }87 }
85 }88 }
89
90 /*!
91 Keeps executing a given parameter-less function until it returns the given
92 expected result or the timemout is reached (in which case a test failure
93 is generated)
94 */
95
96 function tryCompareFunction(func, expectedResult, timeout) {
97 var timeSpent = 0
98 var success = false
99 var actualResult
100 if (timeout == undefined) {
101 timeout = 5000;
102 }
103 while (timeSpent < timeout && !success) {
104 actualResult = func()
105 success = qtest_compareInternal(actualResult, expectedResult)
106 if (success === false) {
107 wait(50)
108 timeSpent += 50
109 }
110 }
111
112 var act = qtest_results.stringify(actualResult)
113 var exp = qtest_results.stringify(expectedResult)
114 if (!qtest_results.compare(success,
115 "function returned unexpected result",
116 act, exp,
117 util.callerFile(), util.callerLine())) {
118 throw new Error("QtQuickTest::fail")
119 }
120 }
86} 121}
87122
88123
=== added file 'tests/unit_x11/tst_components/tst_ubuntulistview.qml'
--- tests/unit_x11/tst_components/tst_ubuntulistview.qml 1970-01-01 00:00:00 +0000
+++ tests/unit_x11/tst_components/tst_ubuntulistview.qml 2014-02-26 09:47:24 +0000
@@ -0,0 +1,198 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
16
17import QtQuick 2.0
18import QtTest 1.0
19import Ubuntu.Test 0.1
20import Ubuntu.Components 0.1
21import Ubuntu.Components.ListItems 0.1
22
23Item {
24 width: units.gu(40)
25 height: units.gu(60)
26
27 ListModel {
28 id: dummyModel
29 Component.onCompleted: {
30 for (var i = 0; i < 20; ++i) {
31 dummyModel.append({idx: i});
32 }
33 }
34 }
35
36 UbuntuListView {
37 id: ubuntuListView
38 anchors { left: parent.left; top: parent.top; right: parent.right }
39 height: units.gu(20)
40 clip: true
41 model: dummyModel
42
43 delegate: Expandable {
44 id: expandable
45 objectName: "expandable" + index
46 expandedHeight: contentColumn.height
47
48 onClicked: ubuntuListView.expandedIndex = index
49
50 Column {
51 id: contentColumn
52 anchors { left: parent.left; right: parent.right; top: parent.top }
53 Rectangle {
54 anchors { left: parent.left; right: parent.right}
55 id: collapsedRect
56 color: index % 2 == 0 ? "khaki" : "blue"
57 height: expandable.collapsedHeight
58 }
59 Rectangle {
60 anchors { left: parent.left; right: parent.right }
61 height: units.gu(40)
62 color: "orange"
63 }
64 }
65 }
66 }
67
68 UbuntuTestCase {
69 name: "UbuntuListView"
70 when: windowShown
71
72 function initTestCase() {
73 tryCompare(dummyModel, "count", 20);
74 }
75
76 function init() {
77 waitForRendering(ubuntuListView);
78 }
79
80 function expandItem(item) {
81 var index = ubuntuListView.indexAt(item.x, item.y);
82 ubuntuListView.expandedIndex = index;
83 var targetHeight = Math.min(item.expandedHeight, ubuntuListView.height - item.collapsedHeight);
84 tryCompare(item, "height", targetHeight);
85 }
86
87 function collapse() {
88 if (ubuntuListView.expandedIndex == -1) {
89 return;
90 }
91
92 var expandedItem = findChild(ubuntuListView, "expandable" + ubuntuListView.expandedIndex);
93 ubuntuListView.expandedIndex = -1;
94 tryCompare(expandedItem, "height", expandedItem.collapsedHeight);
95 }
96
97 function test_expandedItem() {
98 var item = findChild(ubuntuListView, "expandable1");
99 expandItem(item);
100
101 // expandedItem needs to point to the expanded item
102 compare(ubuntuListView.expandedIndex, 1);
103 // item must be expanded now
104 compare(item.expanded, true);
105
106 collapse();
107
108 // expandedItem must be unset after collapsing
109 compare(ubuntuListView.expandedIndex, -1);
110 }
111
112 function test_noScrollingNeeded() {
113 var item = findChild(ubuntuListView, "expandable1");
114 fuzzyCompare(ubuntuListView.mapFromItem(item).y, item.collapsedHeight, .5);
115
116 expandItem(item);
117 waitForRendering(ubuntuListView);
118
119 fuzzyCompare(ubuntuListView.mapFromItem(item).y, item.collapsedHeight, .5);
120 }
121
122 function test_scrollToTop() {
123 ubuntuListView.height = units.gu(30);
124 ubuntuListView.positionViewAtIndex(0, ListView.Beginning)
125
126 var item = findChild(ubuntuListView, "expandable1");
127 fuzzyCompare(ubuntuListView.mapFromItem(item).y, item.collapsedHeight, 1);
128
129 expandItem(item);
130
131 fuzzyCompare(ubuntuListView.mapFromItem(item).y, 0, .5);
132 }
133
134 function test_scrollIntoView() {
135 var item = findChild(ubuntuListView, "expandable9");
136 expandItem(item);
137 waitForRendering(ubuntuListView);
138
139 // The item must be scrolled upwards, leaving space for one other item at the bottom
140 fuzzyCompare(ubuntuListView.mapFromItem(item).y, ubuntuListView.height - item.collapsedHeight - item.expandedHeight, 1);
141 }
142
143 function test_collapseByClickingOutside() {
144 // expand item 0
145 var item = findChild(ubuntuListView, "expandable0");
146 expandItem(item);
147
148 // click on item 1
149 var item1 = findChild(ubuntuListView, "expandable1");
150 mouseClick(item1, item1.width / 2, item1.height / 2);
151
152 // make sure item1 is collapsed
153 tryCompare(item, "expanded", false);
154 }
155
156 function test_dimOthers() {
157 var item = findChild(ubuntuListView, "expandable1");
158 expandItem(item);
159
160 for (var i = 0; i < ubuntuListView.contentItem.children.length; ++i) {
161 var childItem = ubuntuListView.contentItem.children[i];
162 if (childItem.hasOwnProperty("expanded")) {
163 compare(childItem.opacity, childItem.expanded ? 1 : .5)
164 }
165
166 }
167 }
168
169 function test_destroyAndRecreateExpanded() {
170 var item = findChild(ubuntuListView, "expandable1");
171 expandItem(item);
172
173 // scroll the list to the bottom
174 ubuntuListView.currentIndex = 0;
175 ubuntuListView.positionViewAtIndex(ubuntuListView.count -1, ListView.End);
176
177 // make sure the item is eventually destroyed
178 tryCompareFunction(function() { return findChild(ubuntuListView, "expandable1") == null;}, true)
179
180 // scroll the list back up
181 ubuntuListView.positionViewAtIndex(0, ListView.Beginning)
182
183 // wait until the item is recreated.
184 tryCompareFunction(function() { return findChild(ubuntuListView, "expandable1") != null; }, true);
185 item = findChild(ubuntuListView, "expandable1");
186 compare(item.expanded, true);
187
188 }
189
190 function cleanup() {
191 // Restore listview height
192 ubuntuListView.height = units.gu(60);
193 collapse();
194 // scroll the ListView back to top
195 ubuntuListView.positionViewAtIndex(0, ListView.Beginning);
196 }
197 }
198}

Subscribers

People subscribed via source and target branches

to status/vote changes: