2 * Copyright (C) 2014,2015 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
23 objectName: "dashNavigation"
26 property var scope: null
27 property real availableHeight
32 readonly property var currentNavigation: scope && scope.hasNavigation ? scope.getNavigation(scope.currentNavigationId) : null
33 // Are we drilling down the tree or up?
34 property bool isEnteringChildren: false
37 implicitHeight: scope && scope.hasNavigation ? navigationListView.y + navigationListView.height : 0
39 function resetNavigation() {
40 if (navigationModel.count > 1) {
53 function pop(popsNeeded) {
56 isEnteringChildren = false;
57 navigationListView.currentIndex = navigationListView.currentIndex - popsNeeded;
58 navigationModel.setProperty(navigationListView.currentIndex, "nullifyNavigation", false);
59 navigationModel.remove(navigationModel.count - popsNeeded, popsNeeded);
61 popsNeeded = Math.min(headersModel.count, popsNeeded);
62 // This is effectively deleting ourselves, so needs to be the last thing of the function
63 headersModel.remove(headersModel.count - popsNeeded, popsNeeded);
70 // headerText: the text to show
71 // navigationId: the navigation Id that represents
72 // parentNavigationId: the parent navigation Id
74 delegate: DashNavigationHeader {
75 objectName: "dashNavigationHeader" + index
76 height: index == 0 && headersModel.count > 1 ? 0 : units.gu(5)
77 width: headersColumn.width
79 backVisible: index != 0
83 scope.setNavigationState(parentNavigationId);
85 var popsNeeded = headersModel.count - index;
86 headersColumn.pop(popsNeeded);
90 scope.setNavigationState(navigationId);
92 var popsNeeded = headersModel.count - index - 1;
93 headersColumn.pop(popsNeeded);
102 id: navigationListView
103 objectName: "navigationListView"
104 orientation: ListView.Horizontal
109 // navigationId: the navigation id of the navigation the list represents
110 // nullifyNavigation: overrides navigationId to be null
111 // This is used to "clear" the delegate when going "right" on the tree
114 top: headersColumn.bottom
118 readonly property int maxHeight: root.availableHeight - navigationListView.y
119 property int prevHeight: maxHeight
120 height: currentItem ? currentItem.height : maxHeight
124 prevHeight = currentItem.desiredHeight;
127 highlightMoveDuration: UbuntuAnimation.FastDuration
128 delegate: DashNavigationList {
129 objectName: "navigation" + index
131 width: navigationListView.width
132 property real desiredHeight: {
133 if (navigation && navigation.loaded && x == navigationListView.contentX)
135 return Math.min(implicitHeight, navigationListView.maxHeight);
137 return navigationListView.prevHeight;
140 height: desiredHeight
141 navigation: (nullifyNavigation || !scope) ? null : scope.getNavigation(navigationId)
142 currentNavigation: root.currentNavigation
143 onEnterNavigation: { // var newNavigationId, string newNavigationLabel, bool hasChildren
144 scope.setNavigationState(newNavigationId);
145 // We only need to add a new item to the model
146 // if we have children, otherwise just load it
148 isEnteringChildren = true;
149 navigationModel.append({"navigationId": newNavigationId, "nullifyNavigation": false});
150 headersModel.append({"headerText": newNavigationLabel,
151 "navigationId": newNavigationId,
152 "parentNavigationId": navigationId
154 navigationListView.currentIndex++;
161 if (navigationListView.highlightMoveDuration == 0)
164 if (contentX == width * navigationListView.currentIndex) {
165 if (isEnteringChildren) {
166 navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", true);
172 property bool isFirstLoad: false
173 onScopeChanged: clear();
175 navigationModel.clear();
176 headersModel.clear();
179 function setNewNavigation() {
180 if (isFirstLoad && currentNavigation && currentNavigation.loaded) {
182 if (currentNavigation.count > 0) {
183 navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
185 navigationModel.append({"navigationId": currentNavigation.parentNavigationId, "nullifyNavigation": false});
187 headersModel.append({"headerText": currentNavigation.allLabel != "" ? currentNavigation.allLabel : currentNavigation.label,
188 "navigationId": currentNavigation.navigationId,
189 "parentNavigationId": currentNavigation.parentNavigationId
194 target: currentNavigation
195 onLoadedChanged: setNewNavigation();
197 onCurrentNavigationChanged: setNewNavigation();