2
* Copyright (C) 2014 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 0.1
22
objectName: "dashDepartments"
24
property var scope: null
26
property bool showList: false
28
readonly property var currentDepartment: scope && scope.hasDepartments ? scope.getDepartment(scope.currentDepartmentId) : null
30
property alias windowWidth: blackRect.width
31
property alias windowHeight: blackRect.height
33
// Are we drilling down the tree or up?
34
property bool isGoingBack: false
36
visible: root.currentDepartment != null
38
height: visible ? units.gu(5) : 0
41
root.showList = !root.showList;
47
opacity: departmentListView.currentItem && departmentListView.currentItem.visible ? 0.3 : 0
48
Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
49
anchors.top: departmentListView.top
50
anchors.right: parent.right
60
fillMode: Image.Stretch
61
source: "graphics/dash_divider_top_lightgrad.png"
71
fillMode: Image.Stretch
72
source: "graphics/dash_divider_top_darkgrad.png"
78
anchors.margins: units.gu(2)
79
verticalAlignment: Text.AlignVCenter
80
text: root.currentDepartment ? root.currentDepartment.label : ""
81
color: "gray" // TODO remove once we're a separate app
85
anchors.verticalCenter: parent.verticalCenter
86
anchors.right: parent.right
87
anchors.rightMargin: units.gu(2)
88
rotation: showList ? 180 : 0
89
source: "image://theme/dropdown-menu"
90
sourceSize.height: parent.height - units.gu(2)
91
sourceSize.width: units.gu(2)
92
fillMode: Image.PreserveAspectFit
95
// departmentListView is outside root
97
id: departmentListView
98
objectName: "departmentListView"
99
orientation: ListView.Horizontal
101
clip: root.width != windowWidth
105
// departmentId: the department id of the department the list represents
106
// nullifyDepartment: overrides departmentId to be null
107
// This is used to "clear" the delegate when going "right" on the tree
114
readonly property int maxHeight: (windowHeight - mapToItem(null, root.x, root.y).y) - units.gu(8)
115
property int prevHeight: maxHeight
116
height: currentItem ? currentItem.height : maxHeight
119
prevHeight = currentItem.desiredHeight;
122
highlightMoveDuration: UbuntuAnimation.FastDuration
123
delegate: DashDepartmentsList {
124
objectName: "department" + index
126
width: departmentListView.width
127
property real desiredHeight: {
129
if (department && department.loaded && x == departmentListView.contentX)
131
return Math.min(implicitHeight, departmentListView.maxHeight);
133
return departmentListView.prevHeight;
139
height: desiredHeight
140
department: (nullifyDepartment || !scope) ? null : scope.getDepartment(departmentId)
141
currentDepartment: root.currentDepartment
143
scope.loadDepartment(newDepartmentId);
144
// We only need to add a new item to the model
145
// if we have children, otherwise just load it
148
departmentModel.append({"departmentId": newDepartmentId, "nullifyDepartment": false});
149
departmentListView.currentIndex++;
154
onGoBackToParentClicked: {
155
scope.loadDepartment(department.parentDepartmentId);
157
departmentModel.setProperty(departmentListView.currentIndex - 1, "nullifyDepartment", false);
158
departmentListView.currentIndex--;
160
onAllDepartmentClicked: {
162
if (root.currentDepartment.parentDepartmentId == department.departmentId) {
163
// For leaves we have to go to the parent too
164
scope.loadDepartment(root.currentDepartment.parentDepartmentId);
169
if (contentX == width * departmentListView.currentIndex) {
171
departmentModel.remove(departmentListView.currentIndex + 1);
173
departmentModel.setProperty(departmentListView.currentIndex - 1, "nullifyDepartment", true);
180
anchors.fill: departmentListView
181
enabled: root.showList
182
onClicked: root.showList = false
186
departmentModel.clear();
187
if (scope && scope.hasDepartments) {
188
departmentModel.append({"departmentId": scope.currentDepartmentId, "nullifyDepartment": false});
194
onHasDepartmentsChanged: {
195
if (scope.hasDepartments) {
196
departmentModel.append({"departmentId": scope.currentDepartmentId, "nullifyDepartment": false});
198
departmentModel.clear();