on xenial help sign in
Reorganize code + todo so i don't forget

This should make the temp scope -> dash overview -> temp scope situation possible, working on that next

commit94d598f7733d49a75e286f863f64779d2272d5e7 authorAlbert Astals <albert.astals@canonical.com> dateThu 17 Jul 2014, 16:39 (12 years ago) parent6e6ee17
2 files changed+153−126
qml/Dash/Dash.qml+11−102 qml/Dash/ScopesOverview.qml+142−24
qml/Dash/Dash.qml+11−102
@@ -79,10 +79,6 @@ Showable {
7979
8080 property alias enableAnimation: progressAnimation.enabled
8181 property real progress: 0
82− property bool showingNonFavoriteScope: false
83− property bool growingDashFromPos: false
84− property var allScopePosition
85− property var allScopeSize
8682 Behavior on progress {
8783 id: progressAnimation
8884 UbuntuNumberAnimation { }
@@ -94,14 +90,13 @@ Showable {
9490 id: scopesOverview
9591 anchors.fill: parent
9692 scope: scopes ? scopes.getScope("scopesOverview") : null
97− enabled: !overviewController.showingNonFavoriteScope
9893 progress: overviewController.progress
9994 scopeScale: 1 - overviewController.progress * 0.6
10095 visible: scopeScale != 1
10196 currentIndex: dashContent.currentIndex
10297 onDone: {
103− if (dashContent.parent == scopesOverviewXYScaler) {
104− animateDashFromAll();
98+ if (currentTab == 1) {
99+ animateDashFromAll(dashContent.currentScopeId);
105100 }
106101 hide();
107102 }
@@ -111,11 +106,11 @@ Showable {
111106 }
112107 onAllFavoriteSelected: {
113108 setCurrentScope(scopeId, false, false);
114− animateDashFromAll();
109+ animateDashFromAll(dashContent.currentScopeId);
115110 hide();
116111 }
117112 onAllSelected: {
118− showTemporaryScope(scopeId, pos, scopesOverview.allCardSize);
113+ showTemporaryScope(scopes.getScope(scopeId), pos, allCardSize);
119114 }
120115 onSearchSelected: {
121116 var scopeIndex = filteredScopes.findFirst(Scopes.RoleId, scopeId);
@@ -126,63 +121,24 @@ Showable {
126121 hide();
127122 } else {
128123 // Is not a favorite one
129− showTemporaryScope(scopeId, pos, size)
124+ showTemporaryScope(scopes.getScope(scopeId), pos, size)
130125 }
131126 }
132127 function hide() {
133128 overviewController.enableAnimation = true;
134129 overviewController.progress = 0;
135130 }
136− function animateDashFromAll() {
137− var currentScopePos = scopesOverview.allScopeCardPosition(dashContent.currentScopeId);
138− if (currentScopePos) {
139− showDashFromPos(currentScopePos, scopesOverview.allCardSize);
140− } else {
141− console.log("Warning: Could not find Dash OverView All card position for scope", dashContent.currentScopeId);
142− }
143− }
144− function showDashFromPos(itemPos, itemSize) {
145− scopesOverviewXYScaler.scale = itemSize.width / scopesOverviewXYScaler.width;
146− scopesOverviewXYScaler.x = itemPos.x -(scopesOverviewXYScaler.width - scopesOverviewXYScaler.width * scopesOverviewXYScaler.scale) / 2;
147− scopesOverviewXYScaler.y = itemPos.y -(scopesOverviewXYScaler.height - scopesOverviewXYScaler.height * scopesOverviewXYScaler.scale) / 2;
148− overviewController.growingDashFromPos = true;
149− scopesOverviewXYScaler.scale = 1;
150− scopesOverviewXYScaler.x = 0;
151− scopesOverviewXYScaler.y = 0;
152− }
153− function showTemporaryScope(scopeId, itemPos, itemSize) {
154− scopeItem.scope = scopes.getScope(scopeId);
155− scopeItem.parent = scopesOverviewXYScaler;
156− scopesOverviewXYScaler.scale = itemSize.width / scopesOverviewXYScaler.width;
157− scopesOverviewXYScaler.x = itemPos.x -(scopesOverviewXYScaler.width - scopesOverviewXYScaler.width * scopesOverviewXYScaler.scale) / 2;
158− scopesOverviewXYScaler.y = itemPos.y -(scopesOverviewXYScaler.height - scopesOverviewXYScaler.height * scopesOverviewXYScaler.scale) / 2;
159− overviewController.showingNonFavoriteScope = true;
160− overviewController.allScopePosition = itemPos;
161− overviewController.allScopeSize = itemSize;
162− scopesOverview.overrideOpacity = 0;
163− scopesOverviewXYScaler.scale = 1;
164− scopesOverviewXYScaler.x = 0;
165− scopesOverviewXYScaler.y = 0;
166− }
167131 }
168132
169133 DashContent {
170134 id: dashContent
171− parent: {
172− if (overviewController.progress == 0) {
173− return dash;
174− } else if (scopesOverview.dashItemEater) {
175− return scopesOverview.dashItemEater;
176− } else {
177− return scopesOverviewXYScaler;
178− }
179− }
135+ parent: overviewController.progress == 0 ? dash : scopesOverview.dashItemEater
180136 objectName: "dashContent"
181137 width: dash.width
182138 height: dash.height
183139 model: filteredScopes
184140 scopes: scopes
185− visible: !overviewController.showingNonFavoriteScope && x != -width
141+ visible: !scopesOverview.showingNonFavoriteScope && x != -width
186142 onGotoScope: {
187143 dash.setCurrentScope(scopeId, true, false);
188144 }
@@ -210,7 +166,7 @@ Showable {
210166 }
211167
212168 enabled: opacity == 1
213− opacity: overviewController.growingDashFromPos ? 1 : 1 - overviewController.progress
169+ opacity: scopesOverview.growingDashFromPos ? 1 : 1 - overviewController.progress
214170 }
215171
216172 DashBackground
@@ -223,8 +179,7 @@ Showable {
223179 GenericScopeView {
224180 id: scopeItem
225181
226− x: overviewController.showingNonFavoriteScope ? 0 : width + dashContent.x
227− z: 1
182+ anchors.left: dashContent.right
228183 width: parent.width
229184 height: parent.height
230185 scale: dash.contentScale
@@ -233,16 +188,8 @@ Showable {
233188 hasBackAction: true
234189 isCurrent: visible
235190 onBackClicked: {
236− if (overviewController.showingNonFavoriteScope) {
237− var v = overviewController.allScopeSize.width / scopeItem.width;
238− scopesOverviewXYScaler.scale = v;
239− scopesOverviewXYScaler.x = overviewController.allScopePosition.x -(scopeItem.width - scopeItem.width * v) / 2;
240− scopesOverviewXYScaler.y = overviewController.allScopePosition.y -(scopeItem.height - scopeItem.height * v) / 2;
241− scopesOverview.overrideOpacity = -1;
242− } else {
243− closeOverlayScope();
244− closePreview();
245− }
191+ closeOverlayScope();
192+ closePreview();
246193 }
247194
248195 Connections {
@@ -256,44 +203,6 @@ Showable {
256203 }
257204 }
258205
259− Item {
260− id: scopesOverviewXYScaler
261− width: parent.width
262− height: parent.height
263−
264− clip: scale != 1.0
265− enabled: scale == 1
266− opacity: scale
267−
268− property bool animationsEnabled: overviewController.showingNonFavoriteScope || overviewController.growingDashFromPos
269−
270− Behavior on x {
271− enabled: scopesOverviewXYScaler.animationsEnabled
272− UbuntuNumberAnimation { }
273− }
274− Behavior on y {
275− enabled: scopesOverviewXYScaler.animationsEnabled
276− UbuntuNumberAnimation { }
277− }
278−
279− Behavior on scale {
280− enabled: scopesOverviewXYScaler.animationsEnabled
281− UbuntuNumberAnimation {
282− onRunningChanged: {
283− if (!running) {
284− if (overviewController.showingNonFavoriteScope && scopesOverviewXYScaler.scale != 1) {
285− overviewController.showingNonFavoriteScope = false;
286− scopeItem.scope = null;
287− scopeItem.parent = dash;
288− } else if (overviewController.growingDashFromPos) {
289− overviewController.growingDashFromPos = false;
290− }
291− }
292− }
293− }
294− }
295− }
296−
297206 EdgeDragArea {
298207 id: overviewDragHandle
299208 z: 1
qml/Dash/ScopesOverview.qml+142−24
@@ -21,25 +21,24 @@ import "../Components"
2121Item {
2222 id: root
2323
24+ // Properties passed by parent
2425 property real progress: 0
2526 property var scope: null
26− property bool forceDisableDashEater: false
27− property var dashItemEater: {
28− if (!forceDisableDashEater && tabBar.currentTab == 0 && middleItems.count > 0) {
27+ property int currentIndex: 0
28+ property real scopeScale: 1
29+
30+ // Properties used by parent
31+ property bool growingDashFromPos: false
32+ readonly property bool showingNonFavoriteScope: tempScopeItem.scope != null
33+ readonly property alias currentTab: tabBar.currentTab
34+ readonly property var dashItemEater: {
35+ if (!forceXYScalerEater && tabBar.currentTab == 0 && middleItems.count > 0) {
2936 var loaderItem = middleItems.itemAt(0).item;
3037 return loaderItem && loaderItem.currentItem ? loaderItem.currentItem : null;
3138 }
32− return null;
39+ return scopesOverviewXYScaler;
3340 }
34− property int currentIndex: 0
35− property real scopeScale: 1
36− property real overrideOpacity: -1
37− property QtObject scopeStyle: QtObject {
38− property string headerLogo: ""
39− property color foreground: "white"
40− property color background: "transparent"
41− }
42− property size allCardSize: {
41+ readonly property size allCardSize: {
4342 if (middleItems.count > 1) {
4443 var loaderItem = middleItems.itemAt(1).item;
4544 if (loaderItem) {
@@ -50,12 +49,57 @@ Item {
5049 return Qt.size(0, 0);
5150 }
5251
52+ // Internal properties
53+ property bool forceXYScalerEater: false
54+ property QtObject scopeStyle: QtObject {
55+ property string headerLogo: ""
56+ property color foreground: "white"
57+ property color background: "transparent"
58+ }
59+
60+
5361 signal done()
5462 signal favoriteSelected(int index)
5563 signal allFavoriteSelected(var scopeId)
5664 signal allSelected(var scopeId, var pos)
5765 signal searchSelected(var scopeId, var pos, var size)
5866
67+ function showTemporaryScope(scope, itemPos, itemSize) {
68+ scopesOverviewXYScaler.restorePosition = itemPos;
69+ scopesOverviewXYScaler.restoreSize = itemSize;
70+ scopesOverviewXYScaler.scale = itemSize.width / scopesOverviewXYScaler.width;
71+ scopesOverviewXYScaler.x = itemPos.x -(scopesOverviewXYScaler.width - scopesOverviewXYScaler.width * scopesOverviewXYScaler.scale) / 2;
72+ scopesOverviewXYScaler.y = itemPos.y -(scopesOverviewXYScaler.height - scopesOverviewXYScaler.height * scopesOverviewXYScaler.scale) / 2;
73+ scopesOverviewXYScaler.opacity = 0;
74+ tempScopeItem.scope = scope;
75+ middleItems.overrideOpacity = 0;
76+ scopesOverviewXYScaler.scale = 1;
77+ scopesOverviewXYScaler.x = 0;
78+ scopesOverviewXYScaler.y = 0;
79+ scopesOverviewXYScaler.opacity = 1;
80+ }
81+
82+ function animateDashFromAll(scopeId) {
83+ var currentScopePos = allScopeCardPosition(scopeId);
84+ if (currentScopePos) {
85+ showDashFromPos(currentScopePos, allCardSize);
86+ } else {
87+ console.log("Warning: Could not find Dash OverView All card position for scope", dashContent.currentScopeId);
88+ }
89+ }
90+
91+ function showDashFromPos(itemPos, itemSize) {
92+ scopesOverviewXYScaler.scale = itemSize.width / scopesOverviewXYScaler.width;
93+ scopesOverviewXYScaler.x = itemPos.x -(scopesOverviewXYScaler.width - scopesOverviewXYScaler.width * scopesOverviewXYScaler.scale) / 2;
94+ scopesOverviewXYScaler.y = itemPos.y -(scopesOverviewXYScaler.height - scopesOverviewXYScaler.height * scopesOverviewXYScaler.scale) / 2;
95+ scopesOverviewXYScaler.opacity = 0;
96+ root.growingDashFromPos = true;
97+ scopesOverviewXYScaler.scale = 1;
98+ scopesOverviewXYScaler.x = 0;
99+ scopesOverviewXYScaler.y = 0;
100+ scopesOverviewXYScaler.opacity = 1;
101+ }
102+
59103 function allScopeCardPosition(scopeId) {
60104 if (middleItems.count > 1) {
61105 var loaderItem = middleItems.itemAt(1).item;
@@ -89,11 +133,11 @@ Item {
89133 // Need this in order, otherwise something gets unhappy in rendering
90134 // of the overlay in carousels because the parent of the dash dies for
91135 // a moment, this way we make sure it's reparented first
92− // by forceDisableDashEater making dashItemEater return null and
93− // then really kill the parent by updating scope.searchQuery
94− root.forceDisableDashEater = true;
136+ // by forceXYScalerEater making dashItemEater return scopesOverviewXYScaler
137+ // before we kill the previous parent by scope.searchQuery
138+ root.forceXYScalerEater = true;
95139 root.scope.searchQuery = pageHeader.searchQuery;
96− root.forceDisableDashEater = false;
140+ root.forceXYScalerEater = false;
97141 }
98142 }
99143
@@ -107,11 +151,13 @@ Item {
107151 PageHeader {
108152 id: pageHeader
109153
154+ readonly property real yDisplacement: pageHeader.height + tabBar.height + tabBar.anchors.margins
155+
110156 y: {
111157 if (root.progress < 0.5) {
112− return -height;
158+ return -yDisplacement;
113159 } else {
114− return -height + (root.progress - 0.5) * height * 2;
160+ return -yDisplacement + (root.progress - 0.5) * yDisplacement * 2;
115161 }
116162 }
117163 width: parent.width
@@ -135,11 +181,12 @@ Item {
135181
136182 enabled: opacity == 1
137183 opacity: !scope || scope.searchQuery == "" ? 1 : 0
138− Behavior on opacity { UbuntuNumberAnimation {} }
184+ Behavior on opacity { UbuntuNumberAnimation { } }
139185 }
140186
141187 Repeater {
142188 id: middleItems
189+ property real overrideOpacity: -1
143190 model: scope && scope.searchQuery == "" ? scope.categories : null
144191 delegate: Loader {
145192 id: loader
@@ -172,8 +219,8 @@ Item {
172219 scale: index == 0 ? scopeScale : 1
173220
174221 opacity: {
175− if (root.overrideOpacity >= 0)
176− return root.overrideOpacity;
222+ if (middleItems.overrideOpacity >= 0)
223+ return middleItems.overrideOpacity;
177224
178225 if (tabBar.currentTab != index)
179226 return 0;
@@ -255,9 +302,10 @@ Item {
255302 showPageHeader: false
256303 clip: true
257304 opacity: searchResultsViewer.scope ? 1 : 0
258− Behavior on opacity { UbuntuNumberAnimation {} }
305+ Behavior on opacity { UbuntuNumberAnimation { } }
259306
260307 clickOverride: function (index, result, item, itemModel) {
308+ // TODO Make sure pageheader suggestions popup is hidden
261309 if (itemModel.scopeId) {
262310 root.searchSelected(itemModel.scopeId, item.mapToItem(null, 0, 0), Qt.size(item.width, item.height));
263311 } else {
@@ -278,7 +326,7 @@ Item {
278326 width: parent.width
279327 enabled: opacity == 0.4
280328 opacity: scope && scope.searchQuery == "" ? 0.4 : 0
281− Behavior on opacity { UbuntuNumberAnimation {} }
329+ Behavior on opacity { UbuntuNumberAnimation { } }
282330 y: {
283331 if (root.progress < 0.5) {
284332 return parent.height;
@@ -323,4 +371,74 @@ Item {
323371 height: parent.height
324372 anchors.left: scopesOverviewContent.right
325373 }
374+
375+
376+
377+ Item {
378+ id: scopesOverviewXYScaler
379+ width: parent.width
380+ height: parent.height
381+
382+ clip: scale != 1.0
383+ enabled: scale == 1
384+
385+ property bool animationsEnabled: root.showingNonFavoriteScope || root.growingDashFromPos
386+
387+ property var restorePosition
388+ property var restoreSize
389+
390+ Behavior on x {
391+ enabled: scopesOverviewXYScaler.animationsEnabled
392+ UbuntuNumberAnimation { }
393+ }
394+ Behavior on y {
395+ enabled: scopesOverviewXYScaler.animationsEnabled
396+ UbuntuNumberAnimation { }
397+ }
398+ Behavior on opacity {
399+ enabled: scopesOverviewXYScaler.animationsEnabled
400+ UbuntuNumberAnimation { }
401+ }
402+ Behavior on scale {
403+ enabled: scopesOverviewXYScaler.animationsEnabled
404+ UbuntuNumberAnimation {
405+ onRunningChanged: {
406+ if (!running) {
407+ if (root.showingNonFavoriteScope && scopesOverviewXYScaler.scale != 1) {
408+ tempScopeItem.scope = null;
409+ } else if (root.growingDashFromPos) {
410+ root.growingDashFromPos = false;
411+ }
412+ }
413+ }
414+ }
415+ }
416+
417+ DashBackground
418+ {
419+ anchors.fill: tempScopeItem
420+ visible: tempScopeItem.visible
421+ parent: tempScopeItem.parent
422+ }
423+
424+ GenericScopeView {
425+ id: tempScopeItem
426+
427+ width: parent.width
428+ height: parent.height
429+ scale: dash.contentScale
430+ clip: scale != 1.0
431+ visible: scope != null
432+ hasBackAction: true
433+ isCurrent: visible
434+ onBackClicked: {
435+ var v = scopesOverviewXYScaler.restoreSize.width / tempScopeItem.width;
436+ scopesOverviewXYScaler.scale = v;
437+ scopesOverviewXYScaler.x = scopesOverviewXYScaler.restorePosition.x -(tempScopeItem.width - tempScopeItem.width * v) / 2;
438+ scopesOverviewXYScaler.y = scopesOverviewXYScaler.restorePosition.y -(tempScopeItem.height - tempScopeItem.height * v) / 2;
439+ scopesOverviewXYScaler.opacity = 0;
440+ scopesOverview.middleItems = -1;
441+ }
442+ }
443+ }
326444}