34
34
// Are we drilling down the tree or up?
35
35
property bool isGoingBack: false
37
visible: root.currentDepartment != null
37
visible: root.currentNavigation != null
39
39
height: visible ? units.gu(5) : 0
42
navigationListView.updateMaxHeight();
42
43
root.showList = !root.showList;
48
opacity: departmentListView.currentItem && departmentListView.currentItem.visible ? 0.3 : 0
49
opacity: navigationListView.currentItem && navigationListView.currentItem.visible ? 0.3 : 0
49
50
Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
50
anchors.top: departmentListView.top
51
anchors.top: navigationListView.top
51
52
anchors.right: parent.right
52
53
visible: opacity != 0
92
93
color: root.scopeStyle ? root.scopeStyle.foreground : "grey"
95
// departmentListView is outside root
96
// navigationListView is outside root
97
id: departmentListView
98
objectName: "departmentListView"
98
id: navigationListView
99
objectName: "navigationListView"
99
100
orientation: ListView.Horizontal
100
101
interactive: false
101
102
clip: root.width != windowWidth
102
103
model: ListModel {
104
105
// We have two roles
105
// departmentId: the department id of the department the list represents
106
// nullifyDepartment: overrides departmentId to be null
106
// navigationId: the navigation id of the navigation the list represents
107
// nullifyNavigation: overrides navigationId to be null
107
108
// This is used to "clear" the delegate when going "right" on the tree
122
128
highlightMoveDuration: UbuntuAnimation.FastDuration
123
delegate: DashDepartmentsList {
124
objectName: "department" + index
129
delegate: DashNavigationList {
130
objectName: "navigation" + index
125
131
visible: height != 0
126
width: departmentListView.width
132
width: navigationListView.width
127
133
scopeStyle: root.scopeStyle
128
134
property real desiredHeight: {
129
135
if (root.showList) {
130
if (department && department.loaded && x == departmentListView.contentX)
136
if (navigation && navigation.loaded && x == navigationListView.contentX)
132
return Math.min(implicitHeight, departmentListView.maxHeight);
138
navigationListView.updateMaxHeight();
139
return Math.min(implicitHeight, navigationListView.maxHeight);
134
return departmentListView.prevHeight;
141
return navigationListView.prevHeight;
140
147
height: desiredHeight
141
department: (nullifyDepartment || !scope) ? null : scope.getDepartment(departmentId)
142
currentDepartment: root.currentDepartment
144
scope.loadDepartment(newDepartmentId);
148
navigation: (nullifyNavigation || !scope) ? null : scope.getNavigation(navigationId)
149
currentNavigation: root.currentNavigation
151
scope.setNavigationState(newNavigationId, false);
145
152
// We only need to add a new item to the model
146
153
// if we have children, otherwise just load it
147
154
if (hasChildren) {
148
155
isGoingBack = false;
149
departmentModel.append({"departmentId": newDepartmentId, "nullifyDepartment": false});
150
departmentListView.currentIndex++;
156
navigationModel.append({"navigationId": newNavigationId, "nullifyNavigation": false});
157
navigationListView.currentIndex++;
152
159
showList = false;
155
162
onGoBackToParentClicked: {
156
scope.loadDepartment(department.parentDepartmentId);
163
scope.setNavigationState(navigation.parentNavigationId, false);
157
164
isGoingBack = true;
158
departmentModel.setProperty(departmentListView.currentIndex - 1, "nullifyDepartment", false);
159
departmentListView.currentIndex--;
165
navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", false);
166
navigationListView.currentIndex--;
161
onAllDepartmentClicked: {
168
onAllNavigationClicked: {
162
169
showList = false;
163
if (root.currentDepartment.parentDepartmentId == department.departmentId) {
170
if (root.currentNavigation.parentNavigationId == navigation.navigationId) {
164
171
// For leaves we have to go to the parent too
165
scope.loadDepartment(root.currentDepartment.parentDepartmentId);
172
scope.setNavigationState(root.currentNavigation.parentNavigationId, false);
169
176
onContentXChanged: {
170
if (contentX == width * departmentListView.currentIndex) {
177
if (contentX == width * navigationListView.currentIndex) {
171
178
if (isGoingBack) {
172
departmentModel.remove(departmentListView.currentIndex + 1);
179
navigationModel.remove(navigationListView.currentIndex + 1);
174
departmentModel.setProperty(departmentListView.currentIndex - 1, "nullifyDepartment", true);
181
navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", true);
180
187
InverseMouseArea {
181
anchors.fill: departmentListView
188
anchors.fill: navigationListView
182
189
enabled: root.showList
183
190
onClicked: root.showList = false
186
193
onScopeChanged: {
187
departmentModel.clear();
188
if (scope && scope.hasDepartments) {
189
departmentModel.append({"departmentId": scope.currentDepartmentId, "nullifyDepartment": false});
194
navigationModel.clear();
195
if (scope && scope.hasNavigation) {
196
navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
195
onHasDepartmentsChanged: {
196
if (scope.hasDepartments) {
197
departmentModel.append({"departmentId": scope.currentDepartmentId, "nullifyDepartment": false});
202
onHasNavigationChanged: {
203
if (scope.hasNavigation) {
204
navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
199
departmentModel.clear();
206
navigationModel.clear();