@@ -1,223 +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.2
18−import Ubuntu.Components 1.1
19−
20−AbstractButton {
21− id: root
22− objectName: "dashNavigation"
23−
24− // Set by parent
25− property var scope: null
26− property var scopeStyle: null
27− property color foregroundColor: Theme.palette.normal.baseText
28− property bool showDivider: false
29−
30− // Used by parent
31− readonly property var currentNavigation: scope && scope.hasNavigation ? scope.getNavigation(scope.currentNavigationId) : null
32− readonly property alias listView: navigationListView
33− readonly property bool inverseMousePressed: inverseMouseArea.pressed
34− property bool showList: false
35−
36− // Internal
37− // Are we drilling down the tree or up?
38− property bool isGoingBack: false
39−
40− visible: root.currentNavigation != null
41−
42− onClicked: {
43− navigationListView.updateMaxHeight();
44− root.showList = !root.showList;
45− }
46−
47− Label {
48− anchors.fill: parent
49− anchors.margins: units.gu(2)
50− anchors.rightMargin: units.gu(5)
51− verticalAlignment: Text.AlignVCenter
52− text: root.currentNavigation ? root.currentNavigation.label : ""
53− color: root.foregroundColor
54− elide: Text.ElideRight
55− maximumLineCount: 1
56− }
57−
58− Icon {
59− anchors.verticalCenter: parent.verticalCenter
60− anchors.right: parent.right
61− anchors.rightMargin: units.gu(2)
62− name: showList ? "up" : "down"
63− height: units.gu(2)
64− width: height
65− color: root.foregroundColor
66− }
67−
68− // navigationListView is outside root
69− ListView {
70− id: navigationListView
71− objectName: "navigationListView"
72− visible: height > 0
73− orientation: ListView.Horizontal
74− interactive: false
75− clip: root.width != windowWidth
76− model: ListModel {
77− id: navigationModel
78− // We have two roles
79− // navigationId: the navigation id of the navigation the list represents
80− // nullifyNavigation: overrides navigationId to be null
81− // This is used to "clear" the delegate when going "right" on the tree
82− }
83− anchors.top: root.bottom
84− property int maxHeight: -1
85− Component.onCompleted: updateMaxHeight();
86− function updateMaxHeight()
87− {
88− maxHeight = (windowHeight - mapToItem(null, 0, 0).y) - units.gu(8);
89− }
90− property int prevHeight: maxHeight
91− height: currentItem ? currentItem.height : maxHeight
92− onHeightChanged: {
93− if (root.showList) {
94− prevHeight = currentItem.desiredHeight;
95− }
96− }
97− highlightMoveDuration: UbuntuAnimation.FastDuration
98− delegate: DashNavigationList {
99− objectName: "navigation" + index
100− visible: height > 0
101− width: navigationListView.width
102− scopeStyle: root.scopeStyle
103− foregroundColor: root.foregroundColor
104− property real desiredHeight: {
105− if (root.showList) {
106− if (navigation && navigation.loaded && x == navigationListView.contentX)
107− {
108− navigationListView.updateMaxHeight();
109− return Math.min(implicitHeight, navigationListView.maxHeight);
110− } else {
111− return navigationListView.prevHeight;
112− }
113− } else {
114− return 0;
115− }
116− }
117− height: desiredHeight
118− navigation: (nullifyNavigation || !scope) ? null : scope.getNavigation(navigationId)
119− currentNavigation: root.currentNavigation
120− onEnterNavigation: {
121− scope.setNavigationState(newNavigationId);
122− // We only need to add a new item to the model
123− // if we have children, otherwise just load it
124− if (hasChildren) {
125− isGoingBack = false;
126− navigationModel.append({"navigationId": newNavigationId, "nullifyNavigation": false});
127− navigationListView.currentIndex++;
128− } else {
129− showList = false;
130− }
131− }
132− onGoBackToParentClicked: {
133− if (navigationListView.currentIndex == 0) {
134− // This can happen if we jumped to the non root of a deep tree and the user
135− // is now going back, create space in the list for the list to move "left"
136− var aux = navigationListView.highlightMoveDuration;
137− navigationListView.highlightMoveDuration = 0;
138− navigationModel.insert(0, {"navigationId": navigation.parentNavigationId, "nullifyNavigation": false});
139− navigationListView.currentIndex = navigationListView.currentIndex + 1;
140− navigationListView.contentX = width * navigationListView.currentIndex;
141− navigationListView.highlightMoveDuration = aux;
142− }
143−
144− scope.setNavigationState(navigation.parentNavigationId);
145− isGoingBack = true;
146− navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", false);
147− navigationListView.currentIndex--;
148− }
149− onAllNavigationClicked: {
150− showList = false;
151− if (root.currentNavigation.parentNavigationId == navigation.navigationId) {
152− // For leaves we have to go to the parent too
153− scope.setNavigationState(root.currentNavigation.parentNavigationId);
154− }
155− }
156− }
157− onContentXChanged: {
158− if (navigationListView.highlightMoveDuration == 0)
159− return;
160−
161− if (contentX == width * navigationListView.currentIndex) {
162− if (isGoingBack) {
163− navigationModel.remove(navigationListView.currentIndex + 1);
164− } else {
165− navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", true);
166− }
167− }
168− }
169− }
170−
171− Image {
172− anchors {
173− top: navigationListView.bottom
174− left: navigationListView.left
175− right: navigationListView.right
176− }
177− fillMode: Image.Stretch
178− source: "graphics/navigation_shadow.png"
179− visible: root.showList
180− }
181−
182− property bool isFirstLoad: false
183− onScopeChanged: {
184− navigationModel.clear();
185− isFirstLoad = true;
186− }
187− function setNewNavigation() {
188− if (isFirstLoad && currentNavigation && currentNavigation.loaded) {
189− isFirstLoad = false;
190− if (currentNavigation.count > 0) {
191− navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
192− } else {
193− navigationModel.append({"navigationId": currentNavigation.parentNavigationId, "nullifyNavigation": false});
194− }
195− }
196− }
197− Connections {
198− target: currentNavigation
199− onLoadedChanged: setNewNavigation();
200− }
201− onCurrentNavigationChanged: setNewNavigation();
202−
203− InverseMouseArea {
204− id: inverseMouseArea
205− anchors.fill: navigationListView
206− enabled: root.showList
207− onPressed: root.showList = false
208− }
209−
210− Rectangle {
211− visible: root.showDivider
212− anchors {
213− top: parent.top
214− topMargin: units.dp(1)
215− bottom: parent.bottom
216− left: parent.right
217− leftMargin: -units.dp(0.5)
218− }
219− width: units.dp(1)
220− color: root.foregroundColor
221− opacity: 0.2
222− }
223−}