on xenial help sign in
Merge refactor-scopeitem.
d3039f6Michał Sawicz
qml/Components/BaseCarouselDelegate.qml+16
@@ -17,7 +17,23 @@
17import QtQuick 2.0
17import QtQuick 2.0
18import Ubuntu.Components 0.1
18import Ubuntu.Components 0.1
19
19
20+/*!
21+ \brief Base delegate for use with the Carousel component
22+
23+ Use this as the base of your component in a Carousel, the properties
24+ will get updated and signals emitted accordingly.
25+*/
26+
20Item {
27Item {
28+ /// True if this item is currently "focused" in the carousel.
21 property bool explicitlyScaled
29 property bool explicitlyScaled
30+
31+ /// Model data for this delegate.
22 property var model
32 property var model
33+
34+ /// Will be emitted when the item is tapped.
35+ signal clicked
36+
37+ /// Will be emitted when the item is long-pressed.
38+ signal pressAndHold
23}
39}
qml/Components/Carousel.qml+5−14
@@ -52,16 +52,6 @@ Item {
52 /// exposes the distance to the next row (only one row in carousel, so it's the topMargins)
52 /// exposes the distance to the next row (only one row in carousel, so it's the topMargins)
53 readonly property alias verticalSpacing: listView.verticalMargin
53 readonly property alias verticalSpacing: listView.verticalMargin
54
54
55− /// Emitted when the user clicked on an item
56− /// @param index is the index of the clicked item
57− /// @param itemY is y of the clicked delegate
58− signal clicked(int index, real itemY)
59−
60− /// Emitted when the user pressed and held on an item
61− /// @param index is the index of the held item
62− /// @param itemY is y of the held delegate
63− signal pressAndHold(int index, real itemY)
64−
65 implicitHeight: listView.tileHeight * selectedItemScaleFactor
55 implicitHeight: listView.tileHeight * selectedItemScaleFactor
66 opacity: listView.highlightIndex === -1 ? 1 : 0.6
56 opacity: listView.highlightIndex === -1 ? 1 : 0.6
67
57
@@ -167,7 +157,7 @@ Item {
167 /* We're clicking the selected item and
157 /* We're clicking the selected item and
168 we're in the neighbourhood of radius 1 pixel from it.
158 we're in the neighbourhood of radius 1 pixel from it.
169 Let's emit the clicked signal. */
159 Let's emit the clicked signal. */
170− carousel.clicked(index, delegateItem.y)
160+ delegateItem.clicked()
171 return
161 return
172 }
162 }
173
163
@@ -185,7 +175,7 @@ Item {
185 /* We're pressAndHold the selected item and
175 /* We're pressAndHold the selected item and
186 we're in the neighbourhood of radius 1 pixel from it.
176 we're in the neighbourhood of radius 1 pixel from it.
187 Let's emit the pressAndHold signal. */
177 Let's emit the pressAndHold signal. */
188− carousel.pressAndHold(index, delegateItem.y);
178+ delegateItem.pressAndHold();
189 return;
179 return;
190 }
180 }
191
181
@@ -316,8 +306,9 @@ Item {
316 }
306 }
317
307
318 onLoaded: {
308 onLoaded: {
309+ item.objectName = Qt.binding(function() { return "carouselDelegate" + index; });
319− item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; })
310+ item.explicitlyScaled = Qt.binding(function() { return explicitlyScaled; });
320− item.model = Qt.binding(function() { return model; })
311+ item.model = Qt.binding(function() { return model; });
321 }
312 }
322
313
323 MouseArea {
314 MouseArea {
qml/Dash/CardCarousel.qml+3−3
@@ -40,9 +40,6 @@ DashRenderer {
40 cacheBuffer: 1404 // 18px * 13gu * 6
40 cacheBuffer: 1404 // 18px * 13gu * 6
41 model: cardCarousel.model
41 model: cardCarousel.model
42
42
43− onClicked: cardCarousel.clicked(index, null)
44− onPressAndHold: cardCarousel.pressAndHold(index)
45−
46 property real fontScale: 1 / selectedItemScaleFactor
43 property real fontScale: 1 / selectedItemScaleFactor
47 property real headerHeight: cardTool.headerHeight / selectedItemScaleFactor
44 property real headerHeight: cardTool.headerHeight / selectedItemScaleFactor
48
45
@@ -53,6 +50,9 @@ DashRenderer {
53 property var model
50 property var model
54 enabled: false
51 enabled: false
55
52
53+ function clicked() { cardCarousel.clicked(index, model.result) }
54+ function pressAndHold() { cardCarousel.pressAndHold(index, model.result) }
55+
56 sourceComponent: cardTool.cardComponent
56 sourceComponent: cardTool.cardComponent
57 onLoaded: {
57 onLoaded: {
58 item.objectName = "carouselDelegate" + index;
58 item.objectName = "carouselDelegate" + index;
qml/Dash/Dash.qml+15−12
@@ -26,8 +26,6 @@ Showable {
26
26
27 visible: shown
27 visible: shown
28
28
29− property bool searchable: !dashContent.previewOpen && !scopeItem.previewOpen
30−
31 property string showScopeOnLoaded: "clickscope"
29 property string showScopeOnLoaded: "clickscope"
32 property real contentScale: 1.0
30 property real contentScale: 1.0
33
31
@@ -103,7 +101,7 @@ Showable {
103 }
101 }
104 }
102 }
105
103
106− ScopeItem {
104+ GenericScopeView {
107 id: scopeItem
105 id: scopeItem
108 anchors.left: dashContent.right
106 anchors.left: dashContent.right
109 width: parent.width
107 width: parent.width
@@ -111,17 +109,22 @@ Showable {
111 scale: dash.contentScale
109 scale: dash.contentScale
112 clip: scale != 1.0
110 clip: scale != 1.0
113 visible: scope != null
111 visible: scope != null
114− onBack: {
112+ hasBackAction: true
113+ isCurrent: visible
114+ onBackClicked: {
115 closeOverlayScope();
115 closeOverlayScope();
116− }
116+ closePreview();
117− onGotoScope: {
118− // TODO
119− console.log("gotoScope from an openScope scope is not implemented");
120− }
121− onOpenScope: {
122− // TODO
123− console.log("openScope from an openScope scope is not implemented");
124 }
117 }
125
118
119+ Connections {
120+ target: scopeItem.scope
121+ onGotoScope: {
122+ // Note here scopeId is the signal parameter and not the loader property
123+ dashContent.gotoScope(scopeId);
124+ }
125+ onOpenScope: {
126+ dashContent.openScope(scope);
127+ }
128+ }
126 }
129 }
127}
130}
qml/Dash/DashContent.qml+7−21
@@ -26,11 +26,11 @@ Item {
26 property var model: null
26 property var model: null
27 property var scopes: null
27 property var scopes: null
28 readonly property alias currentIndex: dashContentList.currentIndex
28 readonly property alias currentIndex: dashContentList.currentIndex
29− property alias previewOpen: previewListView.open
30
29
31 signal scopeLoaded(string scopeId)
30 signal scopeLoaded(string scopeId)
32 signal gotoScope(string scopeId)
31 signal gotoScope(string scopeId)
33 signal openScope(var scope)
32 signal openScope(var scope)
33+ signal closePreview()
34
34
35 // If we set the current scope index before the scopes have been added,
35 // If we set the current scope index before the scopes have been added,
36 // then we need to wait until the loaded signals gets emitted from the scopes
36 // then we need to wait until the loaded signals gets emitted from the scopes
@@ -80,23 +80,16 @@ Item {
80 dashContentList.currentItem.theScope.closeScope(scope)
80 dashContentList.currentItem.theScope.closeScope(scope)
81 }
81 }
82
82
83− function closePreview() {
84− previewListView.open = false;
85− }
86−
87 Item {
83 Item {
88 id: dashContentListHolder
84 id: dashContentListHolder
89
85
90− x: previewListView.open ? -width : 0
86+ anchors.fill: parent
91− Behavior on x { UbuntuNumberAnimation { } }
92− width: parent.width
93− height: parent.height
94
87
95 ListView {
88 ListView {
96 id: dashContentList
89 id: dashContentList
97 objectName: "dashContentList"
90 objectName: "dashContentList"
98
91
99− interactive: dashContent.scopes.loaded && !previewListView.open && currentItem && !currentItem.moving
92+ interactive: dashContent.scopes.loaded && currentItem && !currentItem.moving
100
93
101 anchors.fill: parent
94 anchors.fill: parent
102 model: dashContent.model
95 model: dashContent.model
@@ -145,7 +138,6 @@ Item {
145
138
146 onLoaded: {
139 onLoaded: {
147 item.objectName = scope.id
140 item.objectName = scope.id
148− item.previewListView = previewListView;
149 item.scope = Qt.binding(function() { return scope })
141 item.scope = Qt.binding(function() { return scope })
150 item.isCurrent = Qt.binding(function() { return visible && ListView.isCurrentItem })
142 item.isCurrent = Qt.binding(function() { return visible && ListView.isCurrentItem })
151 item.title = Qt.binding(function() { return dashContentList.model.get(index).title; })
143 item.title = Qt.binding(function() { return dashContentList.model.get(index).title; })
@@ -161,19 +153,13 @@ Item {
161 dashContent.openScope(scope);
153 dashContent.openScope(scope);
162 }
154 }
163 }
155 }
156+ Connections {
157+ target: dashContent
158+ onClosePreview: if (item) item.closePreview()
159+ }
164
160
165 Component.onDestruction: active = false
161 Component.onDestruction: active = false
166 }
162 }
167 }
163 }
168 }
164 }
169−
170− PreviewListView {
171− id: previewListView
172− objectName: "dashContentPreviewList"
173− visible: x != width
174− scope: dashContentList.currentItem ? dashContentList.currentItem.theScope : null
175− width: parent.width
176− height: parent.height
177− anchors.left: dashContentListHolder.right
178− }
179}
165}
qml/Dash/GenericScopeView.qml+22−3
@@ -29,7 +29,6 @@ FocusScope {
29 property SortFilterProxyModel categories: categoryFilter
29 property SortFilterProxyModel categories: categoryFilter
30 property bool isCurrent: false
30 property bool isCurrent: false
31 property alias moving: categoryView.moving
31 property alias moving: categoryView.moving
32− property Item previewListView: null
33 property string title
32 property string title
34 property bool hasBackAction: false
33 property bool hasBackAction: false
35 property bool enableHeightBehaviorOnNextCreation: false
34 property bool enableHeightBehaviorOnNextCreation: false
@@ -58,6 +57,10 @@ FocusScope {
58 categoryView.showHeader()
57 categoryView.showHeader()
59 }
58 }
60
59
60+ function closePreview() {
61+ previewListView.open = false;
62+ }
63+
61 Binding {
64 Binding {
62 target: scope
65 target: scope
63 property: "isActive"
66 property: "isActive"
@@ -107,7 +110,12 @@ FocusScope {
107 ScopeListView {
110 ScopeListView {
108 id: categoryView
111 id: categoryView
109 objectName: "categoryListView"
112 objectName: "categoryListView"
110− anchors.fill: parent
113+
114+ x: previewListView.open ? -width : 0
115+ Behavior on x { UbuntuNumberAnimation { } }
116+ width: parent.width
117+ height: parent.height
118+
111 model: scopeView.categories
119 model: scopeView.categories
112 forceNoClip: previewListView.open
120 forceNoClip: previewListView.open
113
121
@@ -326,7 +334,7 @@ FocusScope {
326 title: scopeView.title
334 title: scopeView.title
327 showBackButton: scopeView.hasBackAction
335 showBackButton: scopeView.hasBackAction
328 searchEntryEnabled: true
336 searchEntryEnabled: true
329− searchInProgress: scopeView.scope.searchInProgress
337+ searchInProgress: scopeView.scope ? scopeView.scope.searchInProgress : false
330 foregroundColor: scopeView.foregroundColor
338 foregroundColor: scopeView.foregroundColor
331 imageSource: scopeView.scope && scopeView.scope.customizations["page-header"] && scopeView.scope.customizations["page-header"]["logo"] || ""
339 imageSource: scopeView.scope && scopeView.scope.customizations["page-header"] && scopeView.scope.customizations["page-header"]["logo"] || ""
332
340
@@ -343,4 +351,15 @@ FocusScope {
343 onBackClicked: scopeView.backClicked()
351 onBackClicked: scopeView.backClicked()
344 }
352 }
345 }
353 }
354+
355+ PreviewListView {
356+ id: previewListView
357+ objectName: "previewListView"
358+ visible: x != width
359+ scope: scopeView.scope
360+ width: parent.width
361+ height: parent.height
362+ anchors.left: categoryView.right
363+ }
364+
346}
365}
qml/Dash/PreviewListView.qml+3−3
@@ -33,9 +33,9 @@ Item {
33
33
34 PageHeader {
34 PageHeader {
35 id: header
35 id: header
36− objectName: root.objectName + "_pageHeader"
36+ objectName: "pageHeader"
37 width: parent.width
37 width: parent.width
38− title: scope.name
38+ title: scope ? scope.name : ""
39 showBackButton: true
39 showBackButton: true
40 searchEntryEnabled: false
40 searchEntryEnabled: false
41
41
@@ -44,7 +44,7 @@ Item {
44
44
45 ListView {
45 ListView {
46 id: previewListView
46 id: previewListView
47− objectName: root.objectName + "_listView"
47+ objectName: "listView"
48 anchors {
48 anchors {
49 top: header.bottom
49 top: header.bottom
50 bottom: parent.bottom
50 bottom: parent.bottom
qml/Dash/ScopeItem.qmldeleted−71
@@ -1,71 +0,0 @@
1−/*
2− * Copyright (C) 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 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 General Public License for more details.
12− *
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/>.
15− */
16−
17−import QtQuick 2.0
18−import Ubuntu.Components 0.1
19−import Unity 0.2
20−import "../Components"
21−
22−Item {
23− id: root
24−
25− property alias scope: scopeView.scope
26− property alias previewOpen: previewListView.open
27−
28− signal back
29− signal gotoScope(string scopeId)
30− signal openScope(var scope)
31−
32− // TODO see how much code we can share
33− // between here and other Dash parts, it's starting to have
34− // too much duplicated code with the DashDepartments, etc
35−
36− Item {
37− id: scopeViewHolder
38−
39− x: previewListView.open ? -width : 0
40− Behavior on x { UbuntuNumberAnimation { } }
41− width: parent.width
42− height: parent.height
43−
44− GenericScopeView {
45− id: scopeView
46− width: parent.width
47− height: parent.height
48− isCurrent: scope != null
49− title: scope ? scope.name : ""
50− hasBackAction: true
51− previewListView: previewListView
52−
53− onBackClicked: root.back();
54−
55− Connections {
56− target: scopeView.isCurrent ? scope : null
57− onGotoScope: root.gotoScope(scopeId);
58− onOpenScope: root.openScope(scope);
59− }
60− }
61− }
62−
63− PreviewListView {
64− id: previewListView
65− visible: x != width
66− scope: root.scope
67− width: parent.width
68− height: parent.height
69− anchors.left: scopeViewHolder.right
70− }
71−}
tests/qmltests/Components/tst_Carousel.qml+61−9
@@ -27,21 +27,27 @@ Item {
27 Carousel {
27 Carousel {
28 anchors.fill: parent
28 anchors.fill: parent
29 id: carousel
29 id: carousel
30− model: 40
31
30
32 property int createdDelegates: 0
31 property int createdDelegates: 0
33 property int destroyedDelegates: 0
32 property int destroyedDelegates: 0
34
33
34+ itemComponent: Component {
35− itemComponent: BaseCarouselDelegate {
35+ BaseCarouselDelegate {
36− Rectangle {
36+ Rectangle {
37− anchors.fill: parent
37+ anchors.fill: parent
38− border.color: "black"
38+ border.color: "black"
39− color: "red"
39+ color: "red"
40− Component.onCompleted: carousel.createdDelegates++
40+ Component.onCompleted: carousel.createdDelegates++
41− Component.onDestruction: carousel.destroyedDelegates++
41+ Component.onDestruction: carousel.destroyedDelegates++
42+ }
42 }
43 }
43 }
44 }
44 }
45 }
46+
47+ SignalSpy {
48+ id: spy
49+ }
50+
45 UT.UnityTestCase {
51 UT.UnityTestCase {
46 id: root
52 id: root
47 name: "Carousel"
53 name: "Carousel"
@@ -51,6 +57,8 @@ Item {
51 property int itemCount
57 property int itemCount
52 property real tileWidth
58 property real tileWidth
53
59
60+ property Item listView: findChild(carousel, "listView")
61+
54 property real contentWidth: itemCount * tileWidth
62 property real contentWidth: itemCount * tileWidth
55 // following variables are copied from Carousel.qml
63 // following variables are copied from Carousel.qml
56 // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
64 // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
@@ -60,11 +68,25 @@ Item {
60 property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
68 property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
61 property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
69 property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
62
70
71+ function init() {
72+ carousel.model = 40;
73+ waitForRendering(carousel)
74+ listView.positionViewAtBeginning();
75+ }
76+
77+ function cleanup() {
78+ carousel.model = 0;
79+ carousel.createdDelegates = 0;
80+ carousel.destroyedDelegates = 0;
81+ spy.target = null;
82+ spy.signalName = "";
83+ }
84+
63 // This test needs to run first since it tests a corner case condition
85 // This test needs to run first since it tests a corner case condition
64 // to where the carousel is just being created
86 // to where the carousel is just being created
65 // That is why it has a 1 in the name
87 // That is why it has a 1 in the name
66 function test_1onlyNeededItemsCreated() {
88 function test_1onlyNeededItemsCreated() {
67− tryCompare(carousel, "createdDelegates", 10);
89+ tryCompare(carousel, "createdDelegates", 9);
68 compare(carousel.destroyedDelegates, 0);
90 compare(carousel.destroyedDelegates, 0);
69 }
91 }
70
92
@@ -243,5 +265,35 @@ Item {
243 var x = carouselList.getXFromContinuousIndex(carousel.model - 1);
265 var x = carouselList.getXFromContinuousIndex(carousel.model - 1);
244 verify(Math.abs(x - carouselList.contentX) < 1);
266 verify(Math.abs(x - carouselList.contentX) < 1);
245 }
267 }
268+
269+ function test_click() {
270+ var carouselList = findChild(carousel, "listView");
271+ tryCompareFunction(function() { return findChild(carouselList, "carouselDelegate3") ? true : false; }, true);
272+ var carouselItem = findChild(carousel, "carouselDelegate3")
273+ verify(carouselItem, "Could not find delegate");
274+ spy.signalName = "clicked";
275+ spy.target = carouselItem;
276+ mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
277+ tryCompare(carouselList, "moving", false);
278+ tryCompare(carouselItem, "explicitlyScaled", true);
279+ mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
280+ spy.wait();
281+ }
282+
283+ function test_pressAndHold() {
284+ var carouselList = findChild(carousel, "listView");
285+ tryCompareFunction(function() { return findChild(carouselList, "carouselDelegate3") ? true : false; }, true);
286+ var carouselItem = findChild(carousel, "carouselDelegate3")
287+ verify(carouselItem, "Could not find delegate");
288+ spy.signalName = "pressAndHold";
289+ spy.target = carouselItem;
290+ mouseClick(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
291+ tryCompare(carouselList, "moving", false);
292+ tryCompare(carouselItem, "explicitlyScaled", true);
293+ mousePress(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
294+ spy.wait();
295+ mouseRelease(carouselItem, carouselItem.width / 2, carouselItem.height / 2);
296+ }
297+
246 }
298 }
247}
299}
tests/qmltests/Dash/tst_DashContent.qml+2−88
@@ -192,7 +192,8 @@ Item {
192 function test_scope_mapping(data) {
192 function test_scope_mapping(data) {
193 dashContent.setCurrentScopeAtIndex(data.index, true, false);
193 dashContent.setCurrentScopeAtIndex(data.index, true, false);
194 tryCompareFunction(get_current_item_object_name, data.objectName)
194 tryCompareFunction(get_current_item_object_name, data.objectName)
195− var pageHeader = findChild(dashContent, "pageHeader");
195+ var scopeView = findChild(dashContent, data.objectName);
196+ var pageHeader = findChild(scopeView, "pageHeader");
196 compare(pageHeader.title, scopesModel.getScope(data.index).name);
197 compare(pageHeader.title, scopesModel.getScope(data.index).name);
197 }
198 }
198
199
@@ -237,93 +238,6 @@ Item {
237 tryCompareFunction(checkFlickMovingAndNotInteractive, true);
238 tryCompareFunction(checkFlickMovingAndNotInteractive, true);
238 }
239 }
239
240
240− function openPreview() {
241− tryCompareFunction(function() {
242− var filterGrid = findChild(dashContent, "0");
243− if (filterGrid != null) {
244− var tile = findChild(filterGrid, "delegate0");
245− return tile != null;
246− }
247− return false;
248− },
249− true);
250− var tile = findChild(findChild(dashContent, "0"), "delegate0");
251− mouseClick(tile, tile.width / 2, tile.height / 2);
252− var previewListView = findChild(dashContent, "dashContentPreviewList");
253− tryCompare(previewListView, "open", true);
254− tryCompare(previewListView, "x", 0);
255− }
256−
257− function closePreview() {
258− var closePreviewMouseArea = findChild(dashContent, "pageHeader");
259− mouseClick(closePreviewMouseArea, units.gu(2), units.gu(2));
260−
261− var previewListView = findChild(dashContent, "dashContentPreviewList");
262− tryCompare(previewListView, "open", false);
263− }
264−
265− function test_previewOpenClose() {
266− var previewListView = findChild(dashContent, "dashContentPreviewList");
267− tryCompare(previewListView, "open", false);
268−
269− var categoryListView = findChild(dashContent, "categoryListView");
270− categoryListView.positionAtBeginning();
271−
272− openPreview();
273− closePreview();
274− }
275−
276− function test_showPreviewCarousel() {
277− tryCompareFunction(function() {
278− var scope = findChild(dashContent, "MockScope1 loader");
279− if (scope != null) {
280− var dashCategory1 = findChild(scope, "dashCategory1");
281− if (dashCategory1 != null) {
282− var tile = findChild(dashCategory1, "carouselDelegate1");
283− return tile != null;
284− }
285− }
286− return false;
287− },
288− true);
289−
290− var previewListView = findChild(dashContent, "dashContentPreviewList");
291− tryCompare(previewListView, "open", false);
292−
293− var scope = findChild(dashContent, "MockScope1 loader");
294− var dashCategory1 = findChild(scope, "dashCategory1");
295− var tile = findChild(dashCategory1, "carouselDelegate1");
296− mouseClick(tile, tile.width / 2, tile.height / 2);
297− tryCompare(previewListView, "open", true);
298− tryCompare(previewListView, "x", 0);
299−
300− closePreview();
301− }
302−
303− function test_previewCycle() {
304− var categoryListView = findChild(dashContent, "categoryListView");
305− categoryListView.positionAtBeginning();
306−
307− var previewListView = findChild(dashContent, "dashContentPreviewList");
308− tryCompare(previewListView, "open", false);
309− var previewListViewList = findChild(dashContent, "dashContentPreviewList_listView");
310−
311− openPreview();
312−
313− // flick to the next previews
314− tryCompare(previewListView, "count", 15);
315− for (var i = 1; i < previewListView.count; ++i) {
316− mouseFlick(previewListView, previewListView.width - units.gu(1),
317− previewListView.height / 2,
318− units.gu(2),
319− previewListView.height / 2);
320− tryCompare(previewListViewList, "moving", false);
321− tryCompare(previewListView.currentItem, "objectName", "previewItem" + i);
322−
323− }
324− closePreview();
325− }
326−
327 function test_carouselAspectRatio() {
241 function test_carouselAspectRatio() {
328 tryCompareFunction(function() {
242 tryCompareFunction(function() {
329 var scope = findChild(dashContent, "MockScope1 loader");
243 var scope = findChild(dashContent, "MockScope1 loader");
tests/qmltests/Dash/tst_GenericScopeView.qml+90−15
@@ -44,16 +44,17 @@ Item {
44 signal mainStageFocusedApplicationChanged()
44 signal mainStageFocusedApplicationChanged()
45 }
45 }
46
46
47−
48 GenericScopeView {
47 GenericScopeView {
49 id: genericScopeView
48 id: genericScopeView
50 anchors.fill: parent
49 anchors.fill: parent
51− previewListView: previewListView
52
50
53 UT.UnityTestCase {
51 UT.UnityTestCase {
52+ id: testCase
54 name: "GenericScopeView"
53 name: "GenericScopeView"
55 when: scopes.loaded && windowShown
54 when: scopes.loaded && windowShown
56
55
56+ property Item previewListView: findChild(genericScopeView, "previewListView")
57+
57 function init() {
58 function init() {
58 genericScopeView.scope = scopes.getScope(2)
59 genericScopeView.scope = scopes.getScope(2)
59 shell.width = units.gu(120)
60 shell.width = units.gu(120)
@@ -65,24 +66,24 @@ Item {
65 tryCompare(genericScopeView.scope, "isActive", false)
66 tryCompare(genericScopeView.scope, "isActive", false)
66 genericScopeView.isCurrent = true
67 genericScopeView.isCurrent = true
67 tryCompare(genericScopeView.scope, "isActive", true)
68 tryCompare(genericScopeView.scope, "isActive", true)
68− previewListView.open = true
69+ testCase.previewListView.open = true
69 tryCompare(genericScopeView.scope, "isActive", false)
70 tryCompare(genericScopeView.scope, "isActive", false)
70− previewListView.open = false
71+ testCase.previewListView.open = false
71 tryCompare(genericScopeView.scope, "isActive", true)
72 tryCompare(genericScopeView.scope, "isActive", true)
72 genericScopeView.isCurrent = false
73 genericScopeView.isCurrent = false
73 tryCompare(genericScopeView.scope, "isActive", false)
74 tryCompare(genericScopeView.scope, "isActive", false)
74 }
75 }
75
76
76 function test_showDash() {
77 function test_showDash() {
77− previewListView.open = true;
78+ testCase.previewListView.open = true;
78 scopes.getScope(2).showDash();
79 scopes.getScope(2).showDash();
79− tryCompare(previewListView, "open", false);
80+ tryCompare(testCase.previewListView, "open", false);
80 }
81 }
81
82
82 function test_hideDash() {
83 function test_hideDash() {
83− previewListView.open = true;
84+ testCase.previewListView.open = true;
84 scopes.getScope(2).hideDash();
85 scopes.getScope(2).hideDash();
85− tryCompare(previewListView, "open", false);
86+ tryCompare(testCase.previewListView, "open", false);
86 }
87 }
87
88
88 function test_searchQuery() {
89 function test_searchQuery() {
@@ -176,20 +177,94 @@ Item {
176 tryCompare(category, "filtered", true);
177 tryCompare(category, "filtered", true);
177 }
178 }
178
179
180+ function openPreview() {
181+ tryCompareFunction(function() {
182+ var filterGrid = findChild(genericScopeView, "0");
183+ if (filterGrid != null) {
184+ var tile = findChild(filterGrid, "delegate0");
185+ return tile != null;
186+ }
187+ return false;
188+ },
189+ true);
190+ var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
191+ mouseClick(tile, tile.width / 2, tile.height / 2);
192+ tryCompare(testCase.previewListView, "open", true);
193+ tryCompare(testCase.previewListView, "x", 0);
194+ }
195+
196+ function closePreview() {
197+ var closePreviewMouseArea = findChild(genericScopeView, "pageHeader");
198+ mouseClick(closePreviewMouseArea, units.gu(2), units.gu(2));
199+
200+ tryCompare(testCase.previewListView, "open", false);
201+ }
202+
203+ function test_previewOpenClose() {
204+ tryCompare(testCase.previewListView, "open", false);
205+
206+ var categoryListView = findChild(genericScopeView, "categoryListView");
207+ categoryListView.positionAtBeginning();
208+
209+ openPreview();
210+ closePreview();
211+ }
212+
213+ function test_showPreviewCarousel() {
214+ tryCompareFunction(function() {
215+ var dashCategory1 = findChild(genericScopeView, "dashCategory1");
216+ if (dashCategory1 != null) {
217+ var tile = findChild(dashCategory1, "carouselDelegate1");
218+ return tile != null;
219+ }
220+ return false;
221+ },
222+ true);
223+
224+ tryCompare(testCase.previewListView, "open", false);
225+
226+ var dashCategory1 = findChild(genericScopeView, "dashCategory1");
227+ var tile = findChild(dashCategory1, "carouselDelegate1");
228+ mouseClick(tile, tile.width / 2, tile.height / 2);
229+ tryCompare(tile, "explicitlyScaled", true);
230+ mouseClick(tile, tile.width / 2, tile.height / 2);
231+ tryCompare(testCase.previewListView, "open", true);
232+ tryCompare(testCase.previewListView, "x", 0);
233+
234+ closePreview();
235+ }
236+
237+ function test_previewCycle() {
238+ var categoryListView = findChild(genericScopeView, "categoryListView");
239+ categoryListView.positionAtBeginning();
240+
241+ tryCompare(testCase.previewListView, "open", false);
242+ var previewListViewList = findChild(previewListView, "listView");
243+
244+ openPreview();
245+
246+ // flick to the next previews
247+ tryCompare(testCase.previewListView, "count", 15);
248+ for (var i = 1; i < testCase.previewListView.count; ++i) {
249+ mouseFlick(testCase.previewListView, testCase.previewListView.width - units.gu(1),
250+ testCase.previewListView.height / 2,
251+ units.gu(2),
252+ testCase.previewListView.height / 2);
253+ tryCompare(previewListViewList, "moving", false);
254+ tryCompare(testCase.previewListView.currentItem, "objectName", "previewItem" + i);
255+
256+ }
257+ closePreview();
258+ }
259+
179 function test_haeder_logo() {
260 function test_haeder_logo() {
180 genericScopeView.scope = scopes.getScope(3);
261 genericScopeView.scope = scopes.getScope(3);
181
262
182 var image = findChild(genericScopeView, "titleImage");
263 var image = findChild(genericScopeView, "titleImage");
183 verify(image, "Could not find the title image");
264 verify(image, "Could not find the title image");
184 compare(image.source, Qt.resolvedUrl("../Components/tst_PageHeader/logo-ubuntu-orange.svg"), "Title image has the wrong source");
265 compare(image.source, Qt.resolvedUrl("../Components/tst_PageHeader/logo-ubuntu-orange.svg"), "Title image has the wrong source");
266+
185 }
267 }
186 }
268 }
187 }
269 }
188−
189− PreviewListView {
190− id: previewListView
191− anchors.fill: parent
192− visible: false
193− scope: genericScopeView.scope
194− }
195}
270}
tests/qmltests/tst_Shell.qml+1−1
@@ -104,7 +104,7 @@ Item {
104 killApps(ApplicationManager);
104 killApps(ApplicationManager);
105
105
106 var dashContent = findChild(shell, "dashContent");
106 var dashContent = findChild(shell, "dashContent");
107− dashContent.previewOpen = false;
107+ dashContent.closePreview();
108
108
109 var dashHome = findChild(shell, "clickscope loader");
109 var dashHome = findChild(shell, "clickscope loader");
110 swipeUntilScopeViewIsReached(dashHome);
110 swipeUntilScopeViewIsReached(dashHome);