on xenial help sign in
Have just one place for headers
6606d60Albert Astals Cid
qml/Dash/DashNavigation.qml+20−43
@@ -32,7 +32,7 @@ Item {
32 // internal
32 // internal
33 readonly property var currentNavigation: scope && scope.hasNavigation ? scope.getNavigation(scope.currentNavigationId) : null
33 readonly property var currentNavigation: scope && scope.hasNavigation ? scope.getNavigation(scope.currentNavigationId) : null
34 // Are we drilling down the tree or up?
34 // Are we drilling down the tree or up?
35− property bool isGoingBack: false
35+ property bool isEnteringChildren: false
36
36
37 visible: height != 0
37 visible: height != 0
38 implicitHeight: navigationListView.y + navigationListView.height
38 implicitHeight: navigationListView.y + navigationListView.height
@@ -57,13 +57,17 @@ Item {
57 // parentNavigationId: the parent navigation Id
57 // parentNavigationId: the parent navigation Id
58 }
58 }
59 delegate: DashNavigationHeader {
59 delegate: DashNavigationHeader {
60− height: units.gu(5)
60+ height: index == 0 && headersModel.count > 1 ? 0 : units.gu(5)
61 width: parent.width
61 width: parent.width
62
62
63+ backVisible: index != 0
63 text: headerText
64 text: headerText
64 foregroundColor: d.foregroundColor
65 foregroundColor: d.foregroundColor
65
66
66 function pop(popsNeeded) {
67 function pop(popsNeeded) {
68+ if (popsNeeded == 0)
69+ return;
70+ isEnteringChildren = false;
67 navigationListView.currentIndex = navigationListView.currentIndex - popsNeeded;
71 navigationListView.currentIndex = navigationListView.currentIndex - popsNeeded;
68 navigationModel.setProperty(navigationListView.currentIndex, "nullifyNavigation", false);
72 navigationModel.setProperty(navigationListView.currentIndex, "nullifyNavigation", false);
69 navigationModel.remove(navigationModel.count - popsNeeded, popsNeeded);
73 navigationModel.remove(navigationModel.count - popsNeeded, popsNeeded);
@@ -76,7 +80,7 @@ Item {
76 onBackClicked: {
80 onBackClicked: {
77 scope.setNavigationState(parentNavigationId);
81 scope.setNavigationState(parentNavigationId);
78
82
79− var popsNeeded = headersModel.count - index + 1;
83+ var popsNeeded = headersModel.count - index;
80 pop(popsNeeded);
84 pop(popsNeeded);
81 }
85 }
82
86
@@ -84,7 +88,7 @@ Item {
84 root.leafClicked();
88 root.leafClicked();
85 scope.setNavigationState(navigationId);
89 scope.setNavigationState(navigationId);
86
90
87− var popsNeeded = headersModel.count - index;
91+ var popsNeeded = headersModel.count - index - 1;
88 pop(popsNeeded);
92 pop(popsNeeded);
89 }
93 }
90 }
94 }
@@ -124,6 +128,7 @@ Item {
124 objectName: "navigation" + index
128 objectName: "navigation" + index
125 visible: height > 0
129 visible: height > 0
126 width: navigationListView.width
130 width: navigationListView.width
131+ itemsIndent: index != 0 ? units.gu(5) : 0
127 scopeStyle: root.scopeStyle
132 scopeStyle: root.scopeStyle
128 foregroundColor: d.foregroundColor
133 foregroundColor: d.foregroundColor
129 property real desiredHeight: {
134 property real desiredHeight: {
@@ -138,61 +143,29 @@ Item {
138 height: desiredHeight
143 height: desiredHeight
139 navigation: (nullifyNavigation || !scope) ? null : scope.getNavigation(navigationId)
144 navigation: (nullifyNavigation || !scope) ? null : scope.getNavigation(navigationId)
140 currentNavigation: root.currentNavigation
145 currentNavigation: root.currentNavigation
141− onEnterNavigation: {
146+ onEnterNavigation: { // var newNavigationId, string newNavigationLabel, bool hasChildren
142 scope.setNavigationState(newNavigationId);
147 scope.setNavigationState(newNavigationId);
143 // We only need to add a new item to the model
148 // We only need to add a new item to the model
144 // if we have children, otherwise just load it
149 // if we have children, otherwise just load it
145 if (hasChildren) {
150 if (hasChildren) {
146− isGoingBack = false;
151+ isEnteringChildren = true;
147 navigationModel.append({"navigationId": newNavigationId, "nullifyNavigation": false});
152 navigationModel.append({"navigationId": newNavigationId, "nullifyNavigation": false});
148− if (navigationModel.count > 2) {
149− headersModel.append({"headerText": navigation.allLabel != "" ? navigation.allLabel : navigation.label,
153+ headersModel.append({"headerText": newNavigationLabel,
150− "navigationId": navigationId,
154+ "navigationId": newNavigationId,
151− "parentNavigationId": navigation.parentNavigationId
155+ "parentNavigationId": navigationId
152− });
156+ });
153− }
154 navigationListView.currentIndex++;
157 navigationListView.currentIndex++;
155 } else {
158 } else {
156 root.leafClicked();
159 root.leafClicked();
157 }
160 }
158 }
161 }
159− onGoBackToParentClicked: {
160− if (navigationListView.currentIndex == 0) {
161− // This can happen if we jumped to the non root of a deep tree and the user
162− // is now going back, create space in the list for the list to move "left"
163− var aux = navigationListView.highlightMoveDuration;
164− navigationListView.highlightMoveDuration = 0;
165− navigationModel.insert(0, {"navigationId": navigation.parentNavigationId, "nullifyNavigation": false});
166− navigationListView.currentIndex = navigationListView.currentIndex + 1;
167− navigationListView.contentX = width * navigationListView.currentIndex;
168− navigationListView.highlightMoveDuration = aux;
169− }
170−
171− scope.setNavigationState(navigation.parentNavigationId);
172− isGoingBack = true;
173− navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", false);
174− navigationListView.currentIndex--;
175−
176− if (headersModel.count > 0) {
177− headersModel.remove(headersModel.count - 1);
178− }
179− }
180− onAllNavigationClicked: {
181− root.leafClicked();
182− if (root.currentNavigation.parentNavigationId == navigation.navigationId) {
183− // For leaves we have to go to the parent too
184− scope.setNavigationState(root.currentNavigation.parentNavigationId);
185− }
186− }
187 }
162 }
188 onContentXChanged: {
163 onContentXChanged: {
189 if (navigationListView.highlightMoveDuration == 0)
164 if (navigationListView.highlightMoveDuration == 0)
190 return;
165 return;
191
166
192 if (contentX == width * navigationListView.currentIndex) {
167 if (contentX == width * navigationListView.currentIndex) {
193− if (isGoingBack) {
168+ if (isEnteringChildren) {
194− navigationModel.remove(navigationListView.currentIndex + 1);
195− } else {
196 navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", true);
169 navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", true);
197 }
170 }
198 }
171 }
@@ -224,6 +197,10 @@ Item {
224 } else {
197 } else {
225 navigationModel.append({"navigationId": currentNavigation.parentNavigationId, "nullifyNavigation": false});
198 navigationModel.append({"navigationId": currentNavigation.parentNavigationId, "nullifyNavigation": false});
226 }
199 }
200+ headersModel.append({"headerText": currentNavigation.label,
201+ "navigationId": currentNavigation.navigationId,
202+ "parentNavigationId": currentNavigation.parentNavigationId
203+ });
227 }
204 }
228 }
205 }
229 Connections {
206 Connections {
qml/Dash/DashNavigationList.qml+5−23
@@ -21,13 +21,12 @@ import "../Components"
21
21
22Item {
22Item {
23 id: root
23 id: root
24+ property real itemsIndent: 0
24 property var navigation: null
25 property var navigation: null
25 property var currentNavigation: null
26 property var currentNavigation: null
26 property var scopeStyle: null
27 property var scopeStyle: null
27 property color foregroundColor: Theme.palette.normal.baseText
28 property color foregroundColor: Theme.palette.normal.baseText
28− signal enterNavigation(var newNavigationId, bool hasChildren)
29+ signal enterNavigation(var newNavigationId, string newNavigationLabel, bool hasChildren)
29− signal goBackToParentClicked()
30− signal allNavigationClicked()
31
30
32 readonly property int itemHeight: units.gu(5)
31 readonly property int itemHeight: units.gu(5)
33 implicitHeight: flickable.contentHeight
32 implicitHeight: flickable.contentHeight
@@ -54,23 +53,6 @@ Item {
54 id: column
53 id: column
55 width: parent.width
54 width: parent.width
56
55
57− DashNavigationHeader {
58− id: navigationHeader
59−
60− height: itemHeight
61− width: parent.width
62−
63− foregroundColor: root.foregroundColor
64− backVisible: navigation && !navigation.isRoot || false
65− textEnabled: navigation &&
66− (!navigation.isRoot ||
67− (!navigation.hidden && root.currentNavigation && !root.currentNavigation.isRoot && root.currentNavigation.parentNavigationId == navigation.navigationId)) || false
68− text: navigation ? (navigation.allLabel != "" ? navigation.allLabel : navigation.label) : ""
69−
70− onBackClicked: root.goBackToParentClicked();
71− onTextClicked: root.allNavigationClicked();
72− }
73−
74 Repeater {
56 Repeater {
75 model: navigation && navigation.loaded ? navigation : null
57 model: navigation && navigation.loaded ? navigation : null
76 clip: true
58 clip: true
@@ -80,16 +62,16 @@ Item {
80 showDivider: index != navigation.count - 1
62 showDivider: index != navigation.count - 1
81 selected: isActive
63 selected: isActive
82 anchors.left: parent.left
64 anchors.left: parent.left
83− anchors.leftMargin: navigationHeader.backVisible ? navigationHeader.backButtonWidth : 0
65+ anchors.leftMargin: itemsIndent
84 anchors.right: parent.right
66 anchors.right: parent.right
85
67
86− onClicked: root.enterNavigation(navigationId, hasChildren)
68+ onClicked: root.enterNavigation(navigationId, label, hasChildren)
87
69
88 Label {
70 Label {
89 anchors {
71 anchors {
90 verticalCenter: parent.verticalCenter
72 verticalCenter: parent.verticalCenter
91 left: parent.left
73 left: parent.left
92− leftMargin: navigationHeader.backVisible ? 0 : units.gu(2)
74+ leftMargin: itemsIndent > 0 ? 0 : units.gu(2)
93 right: rightIcon.visible ? rightIcon.left : parent.right
75 right: rightIcon.visible ? rightIcon.left : parent.right
94 rightMargin: rightIcon.visible ? units.gu(0.5) : units.gu(2)
76 rightMargin: rightIcon.visible ? units.gu(0.5) : units.gu(2)
95 }
77 }