on xenial help sign in
Have just one place for headers
commit6606d60d37c6825be7839fdbec498eeef598f0d2 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 25 Sep 2015, 16:27 (11 years ago) parenta147203
2 files changed+25−66
qml/Dash/DashNavigation.qml+20−43 qml/Dash/DashNavigationList.qml+5−23
qml/Dash/DashNavigation.qml+20−43
@@ -32,7 +32,7 @@ Item {
3232 // internal
3333 readonly property var currentNavigation: scope && scope.hasNavigation ? scope.getNavigation(scope.currentNavigationId) : null
3434 // Are we drilling down the tree or up?
35− property bool isGoingBack: false
35+ property bool isEnteringChildren: false
3636
3737 visible: height != 0
3838 implicitHeight: navigationListView.y + navigationListView.height
@@ -57,13 +57,17 @@ Item {
5757 // parentNavigationId: the parent navigation Id
5858 }
5959 delegate: DashNavigationHeader {
60− height: units.gu(5)
60+ height: index == 0 && headersModel.count > 1 ? 0 : units.gu(5)
6161 width: parent.width
6262
63+ backVisible: index != 0
6364 text: headerText
6465 foregroundColor: d.foregroundColor
6566
6667 function pop(popsNeeded) {
68+ if (popsNeeded == 0)
69+ return;
70+ isEnteringChildren = false;
6771 navigationListView.currentIndex = navigationListView.currentIndex - popsNeeded;
6872 navigationModel.setProperty(navigationListView.currentIndex, "nullifyNavigation", false);
6973 navigationModel.remove(navigationModel.count - popsNeeded, popsNeeded);
@@ -76,7 +80,7 @@ Item {
7680 onBackClicked: {
7781 scope.setNavigationState(parentNavigationId);
7882
79− var popsNeeded = headersModel.count - index + 1;
83+ var popsNeeded = headersModel.count - index;
8084 pop(popsNeeded);
8185 }
8286
@@ -84,7 +88,7 @@ Item {
8488 root.leafClicked();
8589 scope.setNavigationState(navigationId);
8690
87− var popsNeeded = headersModel.count - index;
91+ var popsNeeded = headersModel.count - index - 1;
8892 pop(popsNeeded);
8993 }
9094 }
@@ -124,6 +128,7 @@ Item {
124128 objectName: "navigation" + index
125129 visible: height > 0
126130 width: navigationListView.width
131+ itemsIndent: index != 0 ? units.gu(5) : 0
127132 scopeStyle: root.scopeStyle
128133 foregroundColor: d.foregroundColor
129134 property real desiredHeight: {
@@ -138,61 +143,29 @@ Item {
138143 height: desiredHeight
139144 navigation: (nullifyNavigation || !scope) ? null : scope.getNavigation(navigationId)
140145 currentNavigation: root.currentNavigation
141− onEnterNavigation: {
146+ onEnterNavigation: { // var newNavigationId, string newNavigationLabel, bool hasChildren
142147 scope.setNavigationState(newNavigationId);
143148 // We only need to add a new item to the model
144149 // if we have children, otherwise just load it
145150 if (hasChildren) {
146− isGoingBack = false;
151+ isEnteringChildren = true;
147152 navigationModel.append({"navigationId": newNavigationId, "nullifyNavigation": false});
148− if (navigationModel.count > 2) {
149− headersModel.append({"headerText": navigation.allLabel != "" ? navigation.allLabel : navigation.label,
150− "navigationId": navigationId,
151− "parentNavigationId": navigation.parentNavigationId
152− });
153− }
153+ headersModel.append({"headerText": newNavigationLabel,
154+ "navigationId": newNavigationId,
155+ "parentNavigationId": navigationId
156+ });
154157 navigationListView.currentIndex++;
155158 } else {
156159 root.leafClicked();
157160 }
158161 }
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− }
187162 }
188163 onContentXChanged: {
189164 if (navigationListView.highlightMoveDuration == 0)
190165 return;
191166
192167 if (contentX == width * navigationListView.currentIndex) {
193− if (isGoingBack) {
194− navigationModel.remove(navigationListView.currentIndex + 1);
195− } else {
168+ if (isEnteringChildren) {
196169 navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", true);
197170 }
198171 }
@@ -224,6 +197,10 @@ Item {
224197 } else {
225198 navigationModel.append({"navigationId": currentNavigation.parentNavigationId, "nullifyNavigation": false});
226199 }
200+ headersModel.append({"headerText": currentNavigation.label,
201+ "navigationId": currentNavigation.navigationId,
202+ "parentNavigationId": currentNavigation.parentNavigationId
203+ });
227204 }
228205 }
229206 Connections {
qml/Dash/DashNavigationList.qml+5−23
@@ -21,13 +21,12 @@ import "../Components"
2121
2222Item {
2323 id: root
24+ property real itemsIndent: 0
2425 property var navigation: null
2526 property var currentNavigation: null
2627 property var scopeStyle: null
2728 property color foregroundColor: Theme.palette.normal.baseText
28− signal enterNavigation(var newNavigationId, bool hasChildren)
29− signal goBackToParentClicked()
30− signal allNavigationClicked()
29+ signal enterNavigation(var newNavigationId, string newNavigationLabel, bool hasChildren)
3130
3231 readonly property int itemHeight: units.gu(5)
3332 implicitHeight: flickable.contentHeight
@@ -54,23 +53,6 @@ Item {
5453 id: column
5554 width: parent.width
5655
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−
7456 Repeater {
7557 model: navigation && navigation.loaded ? navigation : null
7658 clip: true
@@ -80,16 +62,16 @@ Item {
8062 showDivider: index != navigation.count - 1
8163 selected: isActive
8264 anchors.left: parent.left
83− anchors.leftMargin: navigationHeader.backVisible ? navigationHeader.backButtonWidth : 0
65+ anchors.leftMargin: itemsIndent
8466 anchors.right: parent.right
8567
86− onClicked: root.enterNavigation(navigationId, hasChildren)
68+ onClicked: root.enterNavigation(navigationId, label, hasChildren)
8769
8870 Label {
8971 anchors {
9072 verticalCenter: parent.verticalCenter
9173 left: parent.left
92− leftMargin: navigationHeader.backVisible ? 0 : units.gu(2)
74+ leftMargin: itemsIndent > 0 ? 0 : units.gu(2)
9375 right: rightIcon.visible ? rightIcon.left : parent.right
9476 rightMargin: rightIcon.visible ? units.gu(0.5) : units.gu(2)
9577 }