on xenial help sign in
Refactor ScopeItem into GenericScopeView.
bed961fMichał Sawicz
qml/Dash/Dash.qml+14−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,21 @@ 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+ dashContent.gotoScope(scopeId);
123+ }
124+ onOpenScope: {
125+ dashContent.openScope(scope);
126+ }
127+ }
126 }
128 }
127}
129}
qml/Dash/DashContent.qml+7−22
@@ -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,10 +138,8 @@ 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; })
152 dashContent.scopeLoaded(item.scope.id)
143 dashContent.scopeLoaded(item.scope.id)
153 }
144 }
154 Connections {
145 Connections {
@@ -161,19 +152,13 @@ Item {
161 dashContent.openScope(scope);
152 dashContent.openScope(scope);
162 }
153 }
163 }
154 }
155+ Connections {
156+ target: dashContent
157+ onClosePreview: if (item) item.closePreview()
158+ }
164
159
165 Component.onDestruction: active = false
160 Component.onDestruction: active = false
166 }
161 }
167 }
162 }
168 }
163 }
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}
164}
qml/Dash/GenericScopeView.qml+24−5
@@ -29,8 +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
34 property bool hasBackAction: false
32 property bool hasBackAction: false
35 property bool enableHeightBehaviorOnNextCreation: false
33 property bool enableHeightBehaviorOnNextCreation: false
36 property var categoryView: categoryView
34 property var categoryView: categoryView
@@ -55,6 +53,10 @@ FocusScope {
55 categoryView.showHeader()
53 categoryView.showHeader()
56 }
54 }
57
55
56+ function closePreview() {
57+ previewListView.open = false;
58+ }
59+
58 Binding {
60 Binding {
59 target: scope
61 target: scope
60 property: "isActive"
62 property: "isActive"
@@ -98,7 +100,12 @@ FocusScope {
98 ScopeListView {
100 ScopeListView {
99 id: categoryView
101 id: categoryView
100 objectName: "categoryListView"
102 objectName: "categoryListView"
101− anchors.fill: parent
103+
104+ x: previewListView.open ? -width : 0
105+ Behavior on x { UbuntuNumberAnimation { } }
106+ width: parent.width
107+ height: parent.height
108+
102 model: scopeView.categories
109 model: scopeView.categories
103 forceNoClip: previewListView.open
110 forceNoClip: previewListView.open
104
111
@@ -311,11 +318,12 @@ FocusScope {
311
318
312 pageHeader: PageHeader {
319 pageHeader: PageHeader {
313 id: pageHeader
320 id: pageHeader
321+ objectName: "scopePageHeader"
314 width: parent.width
322 width: parent.width
315− title: scopeView.title
323+ title: scopeView.scope ? scopeView.scope.name : ""
316 showBackButton: scopeView.hasBackAction
324 showBackButton: scopeView.hasBackAction
317 searchEntryEnabled: true
325 searchEntryEnabled: true
318− searchInProgress: scopeView.scope.searchInProgress
326+ searchInProgress: scopeView.scope ? scopeView.scope.searchInProgress : false
319
327
320 bottomItem: DashDepartments {
328 bottomItem: DashDepartments {
321 scope: scopeView.scope
329 scope: scopeView.scope
@@ -328,4 +336,15 @@ FocusScope {
328 onBackClicked: scopeView.backClicked()
336 onBackClicked: scopeView.backClicked()
329 }
337 }
330 }
338 }
339+
340+ PreviewListView {
341+ id: previewListView
342+ objectName: "previewListView"
343+ visible: x != width
344+ scope: scopeView.scope
345+ width: parent.width
346+ height: parent.height
347+ anchors.left: categoryView.right
348+ }
349+
331}
350}
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/autopilot/unity8/shell/emulators/dash.py+3−3
@@ -147,7 +147,7 @@ class Dash(emulators.UnityEmulatorBase):
147 all_headers = dashContentList.select_many("QQuickLoader")
147 all_headers = dashContentList.select_many("QQuickLoader")
148 for i in all_headers:
148 for i in all_headers:
149 if i.isCurrent:
149 if i.isCurrent:
150− return i.select_single(objectName="pageHeader")
150+ return i.select_single(objectName="scopePageHeader")
151 return None
151 return None
152
152
153
153
@@ -169,8 +169,8 @@ class GenericScopeView(emulators.UnityEmulatorBase):
169 # Some categories do not show previews, like recent apps.
169 # Some categories do not show previews, like recent apps.
170 # --elopio - 2014-1-14
170 # --elopio - 2014-1-14
171 self.pointing_device.click_object(icon)
171 self.pointing_device.click_object(icon)
172− preview_list = self.get_root_instance().wait_select_single(
172+ preview_list = self.wait_select_single(
173− 'PreviewListView', objectName='dashContentPreviewList')
173+ 'PreviewListView', objectName='previewListView')
174 preview_list.x.wait_for(0)
174 preview_list.x.wait_for(0)
175 return preview_list.select_single(
175 return preview_list.select_single(
176 Preview, objectName='preview{}'.format(preview_list.currentIndex))
176 Preview, objectName='preview{}'.format(preview_list.currentIndex))
tests/qmltests/Dash/tst_DashContent.qml+2−90
@@ -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 scopeView = findChild(dashContent, data.objectName);
195− var pageHeader = findChild(dashContent, "innerPageHeader");
196+ var pageHeader = findChild(scopeView, "innerPageHeader");
196 compare(pageHeader.title, scopesModel.getScope(data.index).name);
197 compare(pageHeader.title, scopesModel.getScope(data.index).name);
197 }
198 }
198
199
@@ -237,95 +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, "innerPageHeader");
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, "carouselDelegate3");
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, "carouselDelegate3");
296− mouseClick(tile, tile.width / 2, tile.height / 2);
297− tryCompare(tile, "explicitlyScaled", true);
298− mouseClick(tile, tile.width / 2, tile.height / 2);
299− tryCompare(previewListView, "open", true);
300− tryCompare(previewListView, "x", 0);
301−
302− closePreview();
303− }
304−
305− function test_previewCycle() {
306− var categoryListView = findChild(dashContent, "categoryListView");
307− categoryListView.positionAtBeginning();
308−
309− var previewListView = findChild(dashContent, "dashContentPreviewList");
310− tryCompare(previewListView, "open", false);
311− var previewListViewList = findChild(dashContent, "dashContentPreviewList_listView");
312−
313− openPreview();
314−
315− // flick to the next previews
316− tryCompare(previewListView, "count", 15);
317− for (var i = 1; i < previewListView.count; ++i) {
318− mouseFlick(previewListView, previewListView.width - units.gu(1),
319− previewListView.height / 2,
320− units.gu(2),
321− previewListView.height / 2);
322− tryCompare(previewListViewList, "moving", false);
323− tryCompare(previewListView.currentItem, "objectName", "previewItem" + i);
324−
325− }
326− closePreview();
327− }
328−
329 function test_carouselAspectRatio() {
241 function test_carouselAspectRatio() {
330 tryCompareFunction(function() {
242 tryCompareFunction(function() {
331 var scope = findChild(dashContent, "MockScope1 loader");
243 var scope = findChild(dashContent, "MockScope1 loader");
tests/qmltests/Dash/tst_GenericScopeView.qml+89−15
@@ -48,16 +48,17 @@ Item {
48 signal mainStageFocusedApplicationChanged()
48 signal mainStageFocusedApplicationChanged()
49 }
49 }
50
50
51−
52 GenericScopeView {
51 GenericScopeView {
53 id: genericScopeView
52 id: genericScopeView
54 anchors.fill: parent
53 anchors.fill: parent
55− previewListView: previewListView
56
54
57 UT.UnityTestCase {
55 UT.UnityTestCase {
56+ id: testCase
58 name: "GenericScopeView"
57 name: "GenericScopeView"
59 when: scopes.loaded && windowShown
58 when: scopes.loaded && windowShown
60
59
60+ property Item previewListView: findChild(genericScopeView, "previewListView")
61+
61 function init() {
62 function init() {
62 genericScopeView.scope = scopes.getScope(2)
63 genericScopeView.scope = scopes.getScope(2)
63 shell.width = units.gu(120)
64 shell.width = units.gu(120)
@@ -69,24 +70,24 @@ Item {
69 tryCompare(genericScopeView.scope, "isActive", false)
70 tryCompare(genericScopeView.scope, "isActive", false)
70 genericScopeView.isCurrent = true
71 genericScopeView.isCurrent = true
71 tryCompare(genericScopeView.scope, "isActive", true)
72 tryCompare(genericScopeView.scope, "isActive", true)
72− previewListView.open = true
73+ testCase.previewListView.open = true
73 tryCompare(genericScopeView.scope, "isActive", false)
74 tryCompare(genericScopeView.scope, "isActive", false)
74− previewListView.open = false
75+ testCase.previewListView.open = false
75 tryCompare(genericScopeView.scope, "isActive", true)
76 tryCompare(genericScopeView.scope, "isActive", true)
76 genericScopeView.isCurrent = false
77 genericScopeView.isCurrent = false
77 tryCompare(genericScopeView.scope, "isActive", false)
78 tryCompare(genericScopeView.scope, "isActive", false)
78 }
79 }
79
80
80 function test_showDash() {
81 function test_showDash() {
81− previewListView.open = true;
82+ testCase.previewListView.open = true;
82 scopes.getScope(2).showDash();
83 scopes.getScope(2).showDash();
83− tryCompare(previewListView, "open", false);
84+ tryCompare(testCase.previewListView, "open", false);
84 }
85 }
85
86
86 function test_hideDash() {
87 function test_hideDash() {
87− previewListView.open = true;
88+ testCase.previewListView.open = true;
88 scopes.getScope(2).hideDash();
89 scopes.getScope(2).hideDash();
89− tryCompare(previewListView, "open", false);
90+ tryCompare(testCase.previewListView, "open", false);
90 }
91 }
91
92
92 function test_searchQuery() {
93 function test_searchQuery() {
@@ -179,13 +180,86 @@ Item {
179 mouseClick(header0, header0.width / 2, header0.height / 2);
180 mouseClick(header0, header0.width / 2, header0.height / 2);
180 tryCompare(category, "filtered", true);
181 tryCompare(category, "filtered", true);
181 }
182 }
182− }
183− }
184
183
185− PreviewListView {
184+ function openPreview() {
185+ tryCompareFunction(function() {
186+ var filterGrid = findChild(genericScopeView, "0");
187+ if (filterGrid != null) {
188+ var tile = findChild(filterGrid, "delegate0");
189+ return tile != null;
190+ }
191+ return false;
192+ },
193+ true);
194+ var tile = findChild(findChild(genericScopeView, "0"), "delegate0");
195+ mouseClick(tile, tile.width / 2, tile.height / 2);
186− id: previewListView
196+ tryCompare(testCase.previewListView, "open", true);
187− anchors.fill: parent
197+ tryCompare(testCase.previewListView, "x", 0);
188− visible: false
198+ }
189− scope: genericScopeView.scope
199+
200+ function closePreview() {
201+ var closePreviewMouseArea = findChild(genericScopeView, "innerPageHeader");
202+ mouseClick(closePreviewMouseArea, units.gu(2), units.gu(2));
203+
204+ tryCompare(testCase.previewListView, "open", false);
205+ }
206+
207+ function test_previewOpenClose() {
208+ tryCompare(testCase.previewListView, "open", false);
209+
210+ var categoryListView = findChild(genericScopeView, "categoryListView");
211+ categoryListView.positionAtBeginning();
212+
213+ openPreview();
214+ closePreview();
215+ }
216+
217+ function test_showPreviewCarousel() {
218+ tryCompareFunction(function() {
219+ var dashCategory1 = findChild(genericScopeView, "dashCategory1");
220+ if (dashCategory1 != null) {
221+ var tile = findChild(dashCategory1, "carouselDelegate1");
222+ return tile != null;
223+ }
224+ return false;
225+ },
226+ true);
227+
228+ tryCompare(testCase.previewListView, "open", false);
229+
230+ var dashCategory1 = findChild(genericScopeView, "dashCategory1");
231+ var tile = findChild(dashCategory1, "carouselDelegate1");
232+ mouseClick(tile, tile.width / 2, tile.height / 2);
233+ tryCompare(tile, "explicitlyScaled", true);
234+ mouseClick(tile, tile.width / 2, tile.height / 2);
235+ tryCompare(testCase.previewListView, "open", true);
236+ tryCompare(testCase.previewListView, "x", 0);
237+
238+ closePreview();
239+ }
240+
241+ function test_previewCycle() {
242+ var categoryListView = findChild(genericScopeView, "categoryListView");
243+ categoryListView.positionAtBeginning();
244+
245+ tryCompare(testCase.previewListView, "open", false);
246+ var previewListViewList = findChild(previewListView, "listView");
247+
248+ openPreview();
249+
250+ // flick to the next previews
251+ tryCompare(testCase.previewListView, "count", 15);
252+ for (var i = 1; i < testCase.previewListView.count; ++i) {
253+ mouseFlick(testCase.previewListView, testCase.previewListView.width - units.gu(1),
254+ testCase.previewListView.height / 2,
255+ units.gu(2),
256+ testCase.previewListView.height / 2);
257+ tryCompare(previewListViewList, "moving", false);
258+ tryCompare(testCase.previewListView.currentItem, "objectName", "previewItem" + i);
259+
260+ }
261+ closePreview();
262+ }
263+ }
190 }
264 }
191}
265}
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);