@@ -0,0 +1,161 @@
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 0.1
19+
20+AbstractButton {
21+ id: root
22+
23+ property int windowHeight: 0
24+
25+ property var scope: null
26+
27+ property bool showList: false
28+
29+ readonly property var currentDepartment: scope && scope.hasDepartments ? scope.getDepartment(scope.currentDepartment) : null
30+
31+ // Are we drilling down the tree or up?
32+ property bool isGoingBack: false
33+
34+ visible: root.currentDepartment != null
35+
36+ height: visible ? units.gu(5) : 0
37+
38+ onClicked: {
39+ root.showList = !root.showList;
40+ }
41+
42+ Rectangle {
43+ color: "black"
44+ opacity: 0.3
45+ width: parent.width
46+ anchors.top: departmentListView.top
47+ height: windowHeight
48+ visible: showList
49+ }
50+
51+ Image {
52+ anchors {
53+ top: parent.top
54+ left: parent.left
55+ right: parent.right
56+ }
57+ fillMode: Image.Stretch
58+ source: "graphics/dash_divider_top_lightgrad.png"
59+ z: -1
60+ }
61+
62+ Image {
63+ anchors {
64+ bottom: parent.bottom
65+ left: parent.left
66+ right: parent.right
67+ }
68+ fillMode: Image.Stretch
69+ source: "graphics/dash_divider_top_darkgrad.png"
70+ z: -1
71+ }
72+
73+ Label {
74+ anchors.fill: parent
75+ anchors.margins: units.gu(2)
76+ verticalAlignment: Text.AlignVCenter
77+ text: root.currentDepartment ? root.currentDepartment.label : ""
78+ }
79+
80+ Image {
81+ anchors.verticalCenter: parent.verticalCenter
82+ anchors.right: parent.right
83+ anchors.rightMargin: units.gu(2)
84+ rotation: showList ? 180 : 0
85+ source: "image://theme/dropdown-menu"
86+ height: parent.height - units.gu(2)
87+ fillMode: Image.PreserveAspectFit
88+ }
89+
90+ // departmentListView is outside root
91+ ListView {
92+ id: departmentListView
93+ orientation: ListView.Horizontal
94+ interactive: false
95+ model: ListModel {
96+ id: departmentModel
97+ }
98+ width: root.width
99+ readonly property int maxHeight: units.gu(60)
100+ property int prevHeight: maxHeight
101+ height: currentItem ? currentItem.height : maxHeight
102+ onHeightChanged: {
103+ console.log("MOOO", height)
104+ prevHeight = height;
105+ }
106+ anchors.top: root.bottom
107+ delegate: DashDepartmentsList {
108+ visible: root.showList
109+ width: departmentListView.width
110+ height: department && department.loaded ? Math.min(implicitHeight, departmentListView.maxHeight) : departmentListView.prevHeight
111+ department: scope.getDepartment(departmentId)
112+ onEnterDepartment: {
113+ scope.loadDepartment(departmentId);
114+ // We only need to add a new item to the model
115+ // if we have children, otherwise just load it
116+ if (hasChildren) {
117+ isGoingBack = false;
118+ departmentModel.append({"departmentId": departmentId});
119+ departmentListView.currentIndex++;
120+ } else {
121+ showList = false;
122+ }
123+ }
124+ onGoBackToParentClicked: {
125+ scope.loadDepartment(department.parentId);
126+ isGoingBack = true;
127+ departmentModel.setProperty(departmentListView.currentIndex - 1, "departmentId", department.parentId);
128+ departmentListView.currentIndex--;
129+ }
130+ onAllDepartmentClicked: {
131+ showList = false;
132+ if (root.currentDepartment.count == 0) {
133+ // For leaves we have to go to the parent too
134+ scope.loadDepartment(root.currentDepartment.parentId);
135+ }
136+ }
137+ }
138+ onContentXChanged: {
139+ if (contentX == width * departmentListView.currentIndex) {
140+ if (isGoingBack) {
141+ departmentModel.remove(departmentListView.currentIndex + 1);
142+ } else {
143+ departmentModel.setProperty(departmentListView.currentIndex - 1, "departmentId", "");
144+ }
145+ }
146+ }
147+ }
148+
149+ InverseMouseArea {
150+ anchors.fill: departmentListView
151+ enabled: root.showList
152+ onClicked: root.showList = false
153+ }
154+
155+ onScopeChanged: {
156+ departmentModel.clear();
157+ if (scope && scope.hasDepartments) {
158+ departmentModel.append({"departmentId": scope.currentDepartment});
159+ }
160+ }
161+}