on xenial help sign in
Some simplification in DashContent
fc2a5b6Albert Astals
qml/Dash/DashContent.qml+5−10
@@ -27,13 +27,9 @@ Item {
27 readonly property alias currentIndex: dashContentList.currentIndex
27 readonly property alias currentIndex: dashContentList.currentIndex
28 property alias previewOpen: previewListView.open
28 property alias previewOpen: previewListView.open
29
29
30− property ScopeDelegateMapper scopeMapper : ScopeDelegateMapper {}
31 property ListModel searchHistory
30 property ListModel searchHistory
32
31
33− signal movementStarted()
34− signal movementEnded()
35 signal scopeLoaded(string scopeId)
32 signal scopeLoaded(string scopeId)
36− signal positionedAtBeginning()
37 signal gotoScope(string scopeId)
33 signal gotoScope(string scopeId)
38 signal openScope(var scope)
34 signal openScope(var scope)
39
35
@@ -71,7 +67,7 @@ Item {
71 dashContentList.currentIndex = index
67 dashContentList.currentIndex = index
72
68
73 if (reset) {
69 if (reset) {
74− dashContent.positionedAtBeginning()
70+ dashContentList.currentItem.item.positionAtBeginning()
75 }
71 }
76 }
72 }
77
73
@@ -114,8 +110,7 @@ Item {
114 highlightRangeMode: ListView.StrictlyEnforceRange
110 highlightRangeMode: ListView.StrictlyEnforceRange
115 // TODO Investigate if we can switch to a smaller cache buffer when/if UbuntuShape gets more performant
111 // TODO Investigate if we can switch to a smaller cache buffer when/if UbuntuShape gets more performant
116 cacheBuffer: 1073741823
112 cacheBuffer: 1073741823
117− onMovementStarted: dashContent.movementStarted()
113+ onMovementStarted: currentItem.item.showHeader();
118− onMovementEnded: dashContent.movementEnded()
119 clip: parent.x != 0
114 clip: parent.x != 0
120
115
121 // If the number of items is less than the current index, then need to reset to another item.
116 // If the number of items is less than the current index, then need to reset to another item.
@@ -135,7 +130,9 @@ Item {
135 width: ListView.view.width
130 width: ListView.view.width
136 height: ListView.view.height
131 height: ListView.view.height
137 asynchronous: true
132 asynchronous: true
138− source: scopeMapper.map(scope.id)
133+ // TODO This if will eventually go away since we're killing DashApps.qml
134+ // once we move app closing to the spread
135+ source: (scope.id == "clickscope") ? "DashApps.qml" : "GenericScopeView.qml"
139 objectName: scope.id + " loader"
136 objectName: scope.id + " loader"
140
137
141 readonly property bool moving: item ? item.moving : false
138 readonly property bool moving: item ? item.moving : false
@@ -154,8 +151,6 @@ Item {
154 item.scope = Qt.binding(function() { return scope })
151 item.scope = Qt.binding(function() { return scope })
155 item.isCurrent = Qt.binding(function() { return visible && ListView.isCurrentItem })
152 item.isCurrent = Qt.binding(function() { return visible && ListView.isCurrentItem })
156 item.tabBarHeight = dashPageHeader.implicitHeight;
153 item.tabBarHeight = dashPageHeader.implicitHeight;
157− dashContentList.movementStarted.connect(item.movementStarted)
158− dashContent.positionedAtBeginning.connect(item.positionedAtBeginning)
159 dashContent.scopeLoaded(item.scope.id)
154 dashContent.scopeLoaded(item.scope.id)
160 }
155 }
161 Connections {
156 Connections {
qml/Dash/GenericScopeView.qml+8−7
@@ -33,9 +33,6 @@ FocusScope {
33 property PageHeader pageHeader: null
33 property PageHeader pageHeader: null
34 property Item previewListView: null
34 property Item previewListView: null
35
35
36− signal movementStarted
37− signal positionedAtBeginning
38−
39 property bool enableHeightBehaviorOnNextCreation: false
36 property bool enableHeightBehaviorOnNextCreation: false
40 property var categoryView: categoryView
37 property var categoryView: categoryView
41
38
@@ -49,6 +46,14 @@ FocusScope {
49 shell.activateApplication(appId);
46 shell.activateApplication(appId);
50 }
47 }
51
48
49+ function positionAtBeginning() {
50+ categoryView.positionAtBeginning()
51+ }
52+
53+ function showHeader() {
54+ categoryView.showHeader()
55+ }
56+
52 Binding {
57 Binding {
53 target: scope
58 target: scope
54 property: "isActive"
59 property: "isActive"
@@ -69,10 +74,6 @@ FocusScope {
69 previewListView.open = false;
74 previewListView.open = false;
70 }
75 }
71
76
72− onMovementStarted: categoryView.showHeader()
73−
74− onPositionedAtBeginning: categoryView.positionAtBeginning()
75−
76 Binding {
77 Binding {
77 target: scopeView.scope
78 target: scopeView.scope
78 property: "searchQuery"
79 property: "searchQuery"
qml/Dash/ScopeDelegateMapper.qmldeleted−30
@@ -1,30 +0,0 @@
1−/*
2− * Copyright (C) 2013 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−
19−QtObject {
20− property var scopeDelegateMapping: {"clickscope": "DashApps.qml"}
21− property string genericScope: "GenericScopeView.qml"
22−
23− function map(scopeId) {
24− var customScope = scopeDelegateMapping[scopeId]
25− if (customScope != undefined) {
26− return customScope
27− }
28− return genericScope
29− }
30−}
tests/qmltests/Dash/qml/FakeScopeView.qmldeleted−45
@@ -1,45 +0,0 @@
1−/*
2− * Copyright 2013 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 Unity 0.2
19−
20−import "../../../../qml/Dash"
21−
22−GenericScopeView {
23− id: fakeScopeView
24−
25− property alias backColor : back.color
26− property var categoryView: null
27−
28− onMovementStarted: {
29− if (shell != undefined && shell.scopeStatus != undefined) {
30− shell.scopeStatus[scope.id].movementStarted++;
31− }
32− }
33− onPositionedAtBeginning: {
34− if (shell != undefined && shell.scopeStatus != undefined) {
35− shell.scopeStatus[scope.id].positionedAtBeginning++;
36− }
37− }
38−
39− Rectangle {
40− id: back
41− anchors.fill: parent
42− color: "grey"
43− z: -1
44− }
45−}
tests/qmltests/Dash/qml/fake_generic_scopeView.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 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−
19−FakeScopeView {
20− id: fake_generic_scopeView
21− objectName: "fake_generic_scopeView"
22−
23− backColor: "#D0D0D0"
24−}
tests/qmltests/Dash/qml/fake_scopeView1.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 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−
19−FakeScopeView {
20− id: fake_scopeView1
21− objectName: "fake_scopeView1"
22−
23− backColor: "#90E090"
24−}
tests/qmltests/Dash/qml/fake_scopeView2.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 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−
19−FakeScopeView {
20− id: fake_scopeView2
21− objectName: "fake_scopeView2"
22−
23− backColor: "#A0D0A0"
24−}
tests/qmltests/Dash/qml/fake_scopeView3.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 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−
19−FakeScopeView {
20− id: fake_scopeView3
21− objectName: "fake_scopeView3"
22−
23− backColor: "#B0C0B0"
24−}
tests/qmltests/Dash/qml/fake_scopeView4.qmldeleted−24
@@ -1,24 +0,0 @@
1−/*
2− * Copyright 2013 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−
19−FakeScopeView {
20− id: fake_scopeView4
21− objectName: "fake_scopeView4"
22−
23− backColor: "#C0C0C0"
24−}
tests/qmltests/Dash/tst_Dash.qml−11
@@ -41,16 +41,6 @@ Item {
41 showScopeOnLoaded: "MockScope2"
41 showScopeOnLoaded: "MockScope2"
42 }
42 }
43
43
44− ScopeDelegateMapper {
45− id: scopeDelegateMapper
46− scopeDelegateMapping: {
47− "MockScope1": Qt.resolvedUrl("qml/fake_scopeView1.qml"),
48− "MockScope2": Qt.resolvedUrl("qml/fake_scopeView2.qml"),
49− "clickscope": Qt.resolvedUrl("qml/fake_scopeView3.qml")
50− }
51− genericScope: Qt.resolvedUrl("qml/fake_generic_scopeView.qml")
52− }
53−
54 UT.UnityTestCase {
44 UT.UnityTestCase {
55 name: "Dash"
45 name: "Dash"
56 when: windowShown
46 when: windowShown
@@ -59,7 +49,6 @@ Item {
59
49
60 Component.onCompleted: {
50 Component.onCompleted: {
61 var dashContent = findChild(dash, "dashContent");
51 var dashContent = findChild(dash, "dashContent");
62− dashContent.scopeMapper = scopeDelegateMapper;
63 scopes = dashContent.scopes;
52 scopes = dashContent.scopes;
64 }
53 }
65
54
tests/qmltests/Dash/tst_DashContent.qml+26−50
@@ -35,13 +35,6 @@ Item {
35 property var panel: null
35 property var panel: null
36 // BEGIN To reduce warnings
36 // BEGIN To reduce warnings
37
37
38− property var scopeStatus: {
39− 'MockScope1': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
40− 'MockScope2': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
41− 'clickscope': { 'movementStarted': 0, 'positionedAtBeginning': 0 },
42− 'MockScope5': { 'movementStarted': 0, 'positionedAtBeginning': 0 }
43− }
44−
45 Scopes {
38 Scopes {
46 id: scopesModel
39 id: scopesModel
47 }
40 }
@@ -55,34 +48,9 @@ Item {
55 }
48 }
56 scopes : scopesModel
49 scopes : scopesModel
57
50
58− scopeMapper : scopeDelegateMapper
59 searchHistory: SearchHistoryModel {}
51 searchHistory: SearchHistoryModel {}
60 }
52 }
61
53
62− ScopeDelegateMapper {
63− id: scopeDelegateMapper
64− scopeDelegateMapping: {
65− "MockScope1": Qt.resolvedUrl("qml/fake_scopeView1.qml"),
66− "MockScope2": Qt.resolvedUrl("qml/fake_scopeView2.qml"),
67− "clickscope": Qt.resolvedUrl("qml/fake_scopeView3.qml"),
68− }
69− genericScope: Qt.resolvedUrl("qml/fake_generic_scopeView.qml")
70− }
71−
72− function clear_scope_status() {
73− scopeStatus["MockScope1"].movementStarted = 0;
74− scopeStatus["MockScope1"].positionedAtBeginning = 0;
75−
76− scopeStatus["MockScope2"].movementStarted = 0;
77− scopeStatus["MockScope2"].positionedAtBeginning = 0;
78−
79− scopeStatus["clickscope"].movementStarted = 0;
80− scopeStatus["clickscope"].positionedAtBeginning = 0;
81−
82− scopeStatus["MockScope5"].movementStarted = 0;
83− scopeStatus["MockScope5"].positionedAtBeginning = 0;
84− }
85−
86 SignalSpy {
54 SignalSpy {
87 id: scopeLoadedSpy
55 id: scopeLoadedSpy
88 target: dashContent
56 target: dashContent
@@ -108,7 +76,6 @@ Item {
108
76
109 function cleanup() {
77 function cleanup() {
110 movementStartedSpy.clear();
78 movementStartedSpy.clear();
111− clear_scope_status();
112 dashContent.visible = true;
79 dashContent.visible = true;
113
80
114 var dashContentList = findChild(dashContent, "dashContentList");
81 var dashContentList = findChild(dashContent, "dashContentList");
@@ -149,29 +116,38 @@ Item {
149 verify(dashContentList.currentIndex >= 0 && dashContentList.currentIndex < 5);
116 verify(dashContentList.currentIndex >= 0 && dashContentList.currentIndex < 5);
150 }
117 }
151
118
152− function test_movement_started_signal() {
119+ function test_show_header_on_list_movement() {
153− dashContent.setCurrentScopeAtIndex(3, true, false);
154−
155 var dashContentList = findChild(dashContent, "dashContentList");
120 var dashContentList = findChild(dashContent, "dashContentList");
156− verify(dashContentList != undefined)
121+ verify(dashContentList != undefined);
122+ var categoryListView = findChild(dashContentList, "categoryListView");
123+ verify(categoryListView != undefined);
124+
125+ waitForRendering(categoryListView);
157
126
158− dashContentList.movementStarted();
127+ categoryListView.contentY = units.gu(11);
128+ console.log("contentY", categoryListView.contentY);
159
129
160− compare(movementStartedSpy.count, 1, "DashContent should have emitted movementStarted signal when content list did.");
130+ var startX = dashContentList.width/2;
161− compare(scopeStatus["MockScope1"].movementStarted, 1, "MockScope1 should have emitted movementStarted signal when content list did.");
131+ var startY = dashContentList.height/2;
162− compare(scopeStatus["MockScope2"].movementStarted, 1, "MockScope2 should have emitted movementStarted signal when content list did.");
132+ touchFlick(dashContentList, startX - units.gu(2), startY, startX, startY);
163− compare(scopeStatus["clickscope"].movementStarted, 1, "clickscope should have emitted movementStarted signal when content list did.");
133+ tryCompare(categoryListView, "contentY", units.gu(11) - categoryListView.pageHeader.height);
164− compare(scopeStatus["MockScope5"].movementStarted, 1, "MockScope5 should have emitted movementStarted signal when content list did.");
165 }
134 }
166
135
167− function test_positioned_at_beginning_signal() {
136+ function test_set_current_scope_reset() {
137+ var dashContentList = findChild(dashContent, "dashContentList");
138+ verify(dashContentList != undefined);
139+ var categoryListView = findChild(dashContentList, "categoryListView");
140+ verify(categoryListView != undefined);
141+
142+ categoryListView.contentY = units.gu(10);
143+
144+ compare(dashContentList.currentItem.item.objectName, "MockScope1")
145+ compare(categoryListView.contentY, units.gu(10));
146+
168− dashContent.setCurrentScopeAtIndex(3, true, false);
147+ dashContent.setCurrentScopeAtIndex(0, false, true);
169
148
170− dashContent.positionedAtBeginning();
149+ compare(dashContentList.currentItem.item.objectName, "MockScope1")
171− compare(scopeStatus["MockScope1"].positionedAtBeginning, 1, "MockScope1 should have emitted positionedAtBeginning signal when DashContent did.");
150+ compare(categoryListView.contentY, 0);
172− compare(scopeStatus["MockScope2"].positionedAtBeginning, 1, "MockScope2 should have emitted positionedAtBeginning signal when DashContent did.");
173− compare(scopeStatus["clickscope"].positionedAtBeginning, 1, "clickscope should have emitted positionedAtBeginning signal when DashContent did.");
174− compare(scopeStatus["MockScope5"].positionedAtBeginning, 1, "MockScope5 should have emitted positionedAtBeginning signal when DashContent did.");
175 }
151 }
176
152
177 // This tests that setting the current scope index will end up at the correct index even if
153 // This tests that setting the current scope index will end up at the correct index even if