18
18
import Ubuntu.Components 1.3
20
import "../Components"
24
23
objectName: "dashNavigation"
26
26
property var scope: null
27
property var scopeStyle: null
29
property alias windowWidth: blackRect.width
30
property alias windowHeight: blackRect.height
31
readonly property var openList: {
32
if (navigationButton.showList) return navigationButton.listView;
33
if (altNavigationButton.showList) return altNavigationButton.listView;
36
readonly property bool disableParentInteractive: {
37
return navigationButton.showList || altNavigationButton.showList ||
38
navigationButton.inverseMousePressed || altNavigationButton.inverseMousePressed;
41
// FIXME this is only here for highlight purposes (see Background.qml, too)
42
readonly property var background: backgroundItem
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
44
36
visible: height != 0
45
height: navigationButton.currentNavigation || altNavigationButton.currentNavigation ? units.gu(5) : 0
49
readonly property color foregroundColor: root.scopeStyle
50
? root.scopeStyle.getTextColor(backgroundItem.luminance)
51
: theme.palette.normal.baseText
52
readonly property bool bothVisible: altNavigationButton.visible && navigationButton.visible
53
readonly property real navigationWidth: root.width >= units.gu(60) ? units.gu(40) : root.width
54
readonly property real buttonWidth: navigationWidth / (bothVisible ? 2 : 1)
59
objectName: "blackRect"
61
opacity: openList && openList.currentItem && openList.currentItem.visible ? 0.5 : 0
62
Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
63
anchors { left: parent.left; right: parent.right }
70
style: scopeStyle ? scopeStyle.navigationBackground : "color:///#f5f5f5"
74
fillMode: Image.Stretch
75
source: scopeStyle.backgroundLuminance > 0.2 ? "graphics/navigation_shadow.png" : "graphics/navigation_shadow_light.png"
76
anchors { top: parent.bottom; left: parent.left; right: parent.right }
79
DashNavigationButton {
80
id: altNavigationButton
81
objectName: "altNavigationButton"
85
scopeStyle: root.scopeStyle
86
foregroundColor: d.foregroundColor
87
listView.width: d.navigationWidth
89
showDivider: navigationButton.visible || root.width > d.navigationWidth
90
// needed so that InverseMouseArea is above navigationButton
91
z: listView.height > 0 ? 1 : 0
94
DashNavigationButton {
96
objectName: "navigationButton"
98
width: altNavigationButton.visible ? d.buttonWidth : d.navigationWidth
99
x: altNavigationButton.visible ? d.buttonWidth : 0
101
scopeStyle: root.scopeStyle
102
foregroundColor: d.foregroundColor
103
listView.width: d.navigationWidth
105
showDivider: root.width > d.navigationWidth
109
fillMode: Image.Stretch
110
source: backgroundItem.luminance > 0.7 ? "graphics/navigation_shadow.png" : "graphics/navigation_shadow_light.png"
111
x: navigationButton.listView.height > 0 ? altNavigationButton.x : navigationButton.x
114
anchors.bottom: parent.bottom
115
visible: d.bothVisible && (navigationButton.listView.height > 0 || altNavigationButton.listView.height > 0)
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();