on xenial help sign in
Refactor ScopeItem into GenericScopeView.

Approved by: Michael Zanetti, Michael Zanetti

commitbed961f1dddd78bdd65b555d9d2d7671e3b12e48 authorMichał Sawicz <michal.sawicz@canonical.com> dateWed 9 Jul 2014, 19:43 (12 years ago) parentfbcec32e464597
9 files changed+143−222
qml/Dash/Dash.qml+14−12 qml/Dash/DashContent.qml+7−22 qml/Dash/GenericScopeView.qml+24−5 qml/Dash/PreviewListView.qml+3−3 qml/Dash/ScopeItem.qml−71 tests/autopilot/unity8/shell/emulators/dash.py+3−3 tests/qmltests/Dash/tst_DashContent.qml+2−90 tests/qmltests/Dash/tst_GenericScopeView.qml+89−15 tests/qmltests/tst_Shell.qml+1−1
qml/Dash/Dash.qml+14−12
@@ -26,8 +26,6 @@ Showable {
2626
2727 visible: shown
2828
29− property bool searchable: !dashContent.previewOpen && !scopeItem.previewOpen
30−
3129 property string showScopeOnLoaded: "clickscope"
3230 property real contentScale: 1.0
3331
@@ -103,7 +101,7 @@ Showable {
103101 }
104102 }
105103
106− ScopeItem {
104+ GenericScopeView {
107105 id: scopeItem
108106 anchors.left: dashContent.right
109107 width: parent.width
@@ -111,17 +109,21 @@ Showable {
111109 scale: dash.contentScale
112110 clip: scale != 1.0
113111 visible: scope != null
114− onBack: {
112+ hasBackAction: true
113+ isCurrent: visible
114+ onBackClicked: {
115115 closeOverlayScope();
116− }
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");
116+ closePreview();
124117 }
125118
119+ Connections {
120+ target: scopeItem.scope
121+ onGotoScope: {
122+ dashContent.gotoScope(scopeId);
123+ }
124+ onOpenScope: {
125+ dashContent.openScope(scope);
126+ }
127+ }
126128 }
127129}
qml/Dash/DashContent.qml+7−22
@@ -26,11 +26,11 @@ Item {
2626 property var model: null
2727 property var scopes: null
2828 readonly property alias currentIndex: dashContentList.currentIndex
29− property alias previewOpen: previewListView.open
3029
3130 signal scopeLoaded(string scopeId)
3231 signal gotoScope(string scopeId)
3332 signal openScope(var scope)
33+ signal closePreview()
3434
3535 // If we set the current scope index before the scopes have been added,
3636 // then we need to wait until the loaded signals gets emitted from the scopes
@@ -80,23 +80,16 @@ Item {
8080 dashContentList.currentItem.theScope.closeScope(scope)
8181 }
8282
83− function closePreview() {
84− previewListView.open = false;
85− }
86−
8783 Item {
8884 id: dashContentListHolder
8985
90− x: previewListView.open ? -width : 0
91− Behavior on x { UbuntuNumberAnimation { } }
92− width: parent.width
93− height: parent.height
86+ anchors.fill: parent
9487
9588 ListView {
9689 id: dashContentList
9790 objectName: "dashContentList"
9891
99− interactive: dashContent.scopes.loaded && !previewListView.open && currentItem && !currentItem.moving
92+ interactive: dashContent.scopes.loaded && currentItem && !currentItem.moving
10093
10194 anchors.fill: parent
10295 model: dashContent.model
@@ -145,10 +138,8 @@ Item {
145138
146139 onLoaded: {
147140 item.objectName = scope.id
148− item.previewListView = previewListView;
149141 item.scope = Qt.binding(function() { return scope })
150142 item.isCurrent = Qt.binding(function() { return visible && ListView.isCurrentItem })
151− item.title = Qt.binding(function() { return dashContentList.model.get(index).title; })
152143 dashContent.scopeLoaded(item.scope.id)
153144 }
154145 Connections {
@@ -161,19 +152,13 @@ Item {
161152 dashContent.openScope(scope);
162153 }
163154 }
155+ Connections {
156+ target: dashContent
157+ onClosePreview: if (item) item.closePreview()
158+ }
164159
165160 Component.onDestruction: active = false
166161 }
167162 }
168163 }
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− }
179164}
qml/Dash/GenericScopeView.qml+24−5
@@ -29,8 +29,6 @@ FocusScope {
2929 property SortFilterProxyModel categories: categoryFilter
3030 property bool isCurrent: false
3131 property alias moving: categoryView.moving
32− property Item previewListView: null
33− property string title
3432 property bool hasBackAction: false
3533 property bool enableHeightBehaviorOnNextCreation: false
3634 property var categoryView: categoryView
@@ -55,6 +53,10 @@ FocusScope {
5553 categoryView.showHeader()
5654 }
5755
56+ function closePreview() {
57+ previewListView.open = false;
58+ }
59+
5860 Binding {
5961 target: scope
6062 property: "isActive"
@@ -98,7 +100,12 @@ FocusScope {
98100 ScopeListView {
99101 id: categoryView
100102 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+
102109 model: scopeView.categories
103110 forceNoClip: previewListView.open
104111
@@ -311,11 +318,12 @@ FocusScope {
311318
312319 pageHeader: PageHeader {
313320 id: pageHeader
321+ objectName: "scopePageHeader"
314322 width: parent.width
315− title: scopeView.title
323+ title: scopeView.scope ? scopeView.scope.name : ""
316324 showBackButton: scopeView.hasBackAction
317325 searchEntryEnabled: true
318− searchInProgress: scopeView.scope.searchInProgress
326+ searchInProgress: scopeView.scope ? scopeView.scope.searchInProgress : false
319327
320328 bottomItem: DashDepartments {
321329 scope: scopeView.scope
@@ -328,4 +336,15 @@ FocusScope {
328336 onBackClicked: scopeView.backClicked()
329337 }
330338 }
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+
331350}
qml/Dash/PreviewListView.qml+3−3
@@ -33,9 +33,9 @@ Item {
3333
3434 PageHeader {
3535 id: header
36− objectName: root.objectName + "_pageHeader"
36+ objectName: "pageHeader"
3737 width: parent.width
38− title: scope.name
38+ title: scope ? scope.name : ""
3939 showBackButton: true
4040 searchEntryEnabled: false
4141
@@ -44,7 +44,7 @@ Item {
4444
4545 ListView {
4646 id: previewListView
47− objectName: root.objectName + "_listView"
47+ objectName: "listView"
4848 anchors {
4949 top: header.bottom
5050 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):
147147 all_headers = dashContentList.select_many("QQuickLoader")
148148 for i in all_headers:
149149 if i.isCurrent:
150− return i.select_single(objectName="pageHeader")
150+ return i.select_single(objectName="scopePageHeader")
151151 return None
152152
153153
@@ -169,8 +169,8 @@ class GenericScopeView(emulators.UnityEmulatorBase):
169169 # Some categories do not show previews, like recent apps.
170170 # --elopio - 2014-1-14
171171 self.pointing_device.click_object(icon)
172− preview_list = self.get_root_instance().wait_select_single(
173− 'PreviewListView', objectName='dashContentPreviewList')
172+ preview_list = self.wait_select_single(
173+ 'PreviewListView', objectName='previewListView')
174174 preview_list.x.wait_for(0)
175175 return preview_list.select_single(
176176 Preview, objectName='preview{}'.format(preview_list.currentIndex))
tests/qmltests/Dash/tst_DashContent.qml+2−90
@@ -192,7 +192,8 @@ Item {
192192 function test_scope_mapping(data) {
193193 dashContent.setCurrentScopeAtIndex(data.index, true, false);
194194 tryCompareFunction(get_current_item_object_name, data.objectName)
195− var pageHeader = findChild(dashContent, "innerPageHeader");
195+ var scopeView = findChild(dashContent, data.objectName);
196+ var pageHeader = findChild(scopeView, "innerPageHeader");
196197 compare(pageHeader.title, scopesModel.getScope(data.index).name);
197198 }
198199
@@ -237,95 +238,6 @@ Item {
237238 tryCompareFunction(checkFlickMovingAndNotInteractive, true);
238239 }
239240
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−
329241 function test_carouselAspectRatio() {
330242 tryCompareFunction(function() {
331243 var scope = findChild(dashContent, "MockScope1 loader");
tests/qmltests/Dash/tst_GenericScopeView.qml+89−15
@@ -48,16 +48,17 @@ Item {
4848 signal mainStageFocusedApplicationChanged()
4949 }
5050
51−
5251 GenericScopeView {
5352 id: genericScopeView
5453 anchors.fill: parent
55− previewListView: previewListView
5654
5755 UT.UnityTestCase {
56+ id: testCase
5857 name: "GenericScopeView"
5958 when: scopes.loaded && windowShown
6059
60+ property Item previewListView: findChild(genericScopeView, "previewListView")
61+
6162 function init() {
6263 genericScopeView.scope = scopes.getScope(2)
6364 shell.width = units.gu(120)
@@ -69,24 +70,24 @@ Item {
6970 tryCompare(genericScopeView.scope, "isActive", false)
7071 genericScopeView.isCurrent = true
7172 tryCompare(genericScopeView.scope, "isActive", true)
72− previewListView.open = true
73+ testCase.previewListView.open = true
7374 tryCompare(genericScopeView.scope, "isActive", false)
74− previewListView.open = false
75+ testCase.previewListView.open = false
7576 tryCompare(genericScopeView.scope, "isActive", true)
7677 genericScopeView.isCurrent = false
7778 tryCompare(genericScopeView.scope, "isActive", false)
7879 }
7980
8081 function test_showDash() {
81− previewListView.open = true;
82+ testCase.previewListView.open = true;
8283 scopes.getScope(2).showDash();
83− tryCompare(previewListView, "open", false);
84+ tryCompare(testCase.previewListView, "open", false);
8485 }
8586
8687 function test_hideDash() {
87− previewListView.open = true;
88+ testCase.previewListView.open = true;
8889 scopes.getScope(2).hideDash();
89− tryCompare(previewListView, "open", false);
90+ tryCompare(testCase.previewListView, "open", false);
9091 }
9192
9293 function test_searchQuery() {
@@ -179,13 +180,86 @@ Item {
179180 mouseClick(header0, header0.width / 2, header0.height / 2);
180181 tryCompare(category, "filtered", true);
181182 }
182− }
183− }
184183
185− PreviewListView {
186− id: previewListView
187− anchors.fill: parent
188− visible: false
189− scope: genericScopeView.scope
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);
196+ tryCompare(testCase.previewListView, "open", true);
197+ tryCompare(testCase.previewListView, "x", 0);
198+ }
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+ }
190264 }
191265}
tests/qmltests/tst_Shell.qml+1−1
@@ -104,7 +104,7 @@ Item {
104104 killApps(ApplicationManager);
105105
106106 var dashContent = findChild(shell, "dashContent");
107− dashContent.previewOpen = false;
107+ dashContent.closePreview();
108108
109109 var dashHome = findChild(shell, "clickscope loader");
110110 swipeUntilScopeViewIsReached(dashHome);