on xenial help sign in
First attempt at the "stack" of categories
commit5444515929f6d8d491e676443a96d7e487ef1e75 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 25 Sep 2015, 15:23 (11 years ago) parent07d6ec2
3 files changed+145−66
qml/Dash/DashNavigation.qml+55−9 qml/Dash/DashNavigationHeader.qml+75 qml/Dash/DashNavigationList.qml+15−57
qml/Dash/DashNavigation.qml+55−9
@@ -44,15 +44,51 @@ Item {
4444 : Theme.palette.normal.baseText
4545 }
4646
47− Label {
48− id: label
47+ Column {
48+ id: headersColumn
4949 anchors.top: parent.top
50− anchors.left: parent.left
51− anchors.margins: units.gu(2)
52− text: root.currentNavigation ? root.currentNavigation.label : ""
53− color: d.foregroundColor
54− elide: Text.ElideRight
55− maximumLineCount: 1
50+ width: parent.width
51+ Repeater {
52+ model: ListModel {
53+ id: headersModel
54+ // Roles
55+ // headerText: the text to show
56+ // navigationId: the navigation Id that represents
57+ // parentNavigationId: the parent navigation Id
58+ }
59+ delegate: DashNavigationHeader {
60+ height: units.gu(5)
61+ width: parent.width
62+
63+ text: headerText
64+ foregroundColor: d.foregroundColor
65+
66+ function pop(popsNeeded) {
67+ navigationListView.currentIndex = navigationListView.currentIndex - popsNeeded;
68+ navigationModel.setProperty(navigationListView.currentIndex, "nullifyNavigation", false);
69+ navigationModel.remove(navigationModel.count - popsNeeded, popsNeeded);
70+
71+ popsNeeded = Math.min(headersModel.count, popsNeeded);
72+ // This is effectively deleting ourselves, so needs to be the last thing of the function
73+ headersModel.remove(headersModel.count - popsNeeded, popsNeeded);
74+ }
75+
76+ onBackClicked: {
77+ scope.setNavigationState(parentNavigationId);
78+
79+ var popsNeeded = headersModel.count - index + 1;
80+ pop(popsNeeded);
81+ }
82+
83+ onTextClicked: {
84+ root.leafClicked();
85+ scope.setNavigationState(navigationId);
86+
87+ var popsNeeded = headersModel.count - index;
88+ pop(popsNeeded);
89+ }
90+ }
91+ }
5692 }
5793
5894 ListView {
@@ -67,7 +103,7 @@ Item {
67103 // nullifyNavigation: overrides navigationId to be null
68104 // This is used to "clear" the delegate when going "right" on the tree
69105 }
70− anchors.top: label.bottom
106+ anchors.top: headersColumn.bottom
71107 property int maxHeight: -1
72108 Component.onCompleted: updateMaxHeight();
73109 function updateMaxHeight()
@@ -109,6 +145,12 @@ Item {
109145 if (hasChildren) {
110146 isGoingBack = false;
111147 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+ }
112154 navigationListView.currentIndex++;
113155 } else {
114156 root.leafClicked();
@@ -130,6 +172,10 @@ Item {
130172 isGoingBack = true;
131173 navigationModel.setProperty(navigationListView.currentIndex - 1, "nullifyNavigation", false);
132174 navigationListView.currentIndex--;
175+
176+ if (headersModel.count > 0) {
177+ headersModel.remove(headersModel.count - 1);
178+ }
133179 }
134180 onAllNavigationClicked: {
135181 root.leafClicked();
qml/Dash/DashNavigationHeader.qmlnew file+75
@@ -0,0 +1,75 @@
1+/*
2+ * Copyright (C) 2014 Canonical, Ltd.
3+ *
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.
7+ *
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.
12+ *
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/>.
15+ */
16+
17+import QtQuick 2.2
18+import Ubuntu.Components 1.1
19+import Ubuntu.Components.ListItems 1.1 as ListItem
20+
21+Row {
22+ id: root
23+
24+ property alias backVisible: backImageItem.visible
25+ property alias foregroundColor: backImage.color
26+ property alias textEnabled: textItem.enabled
27+ property alias text: textLabel.text
28+
29+ readonly property alias backButtonWidth: backImageItem.width
30+
31+ signal backClicked()
32+ signal textClicked()
33+
34+ ListItem.Standard {
35+ id: backImageItem
36+ height: parent.height
37+ width: height
38+ showDivider: false
39+
40+ Icon {
41+ id: backImage
42+ anchors.centerIn: parent
43+ name: "back"
44+ height: units.gu(2)
45+ width: height
46+ }
47+
48+ onClicked: root.backClicked();
49+ }
50+
51+ ListItem.Standard {
52+ id: textItem
53+ objectName: "allButton"
54+ height: parent.height
55+ showDivider: false
56+
57+ Label {
58+ id: textLabel
59+ anchors {
60+ verticalCenter: parent.verticalCenter
61+ left: parent.left
62+ right: parent.right
63+ leftMargin: backImageItem.visible ? 0 : units.gu(2)
64+ rightMargin: units.gu(2)
65+ }
66+ font.bold: true
67+ color: root.foregroundColor
68+ wrapMode: Text.Wrap
69+ maximumLineCount: 2
70+ elide: Text.ElideMiddle
71+ }
72+
73+ onClicked: root.textClicked();
74+ }
75+}
qml/Dash/DashNavigationList.qml+15−57
@@ -54,66 +54,21 @@ Item {
5454 id: column
5555 width: parent.width
5656
57− ListItem.Standard {
58− id: backButton
59− objectName: "backButton"
60− visible: navigation && !navigation.isRoot || false
61− height: itemHeight
62−
63− onClicked: root.goBackToParentClicked();
64−
65− Icon {
66− id: backImage
67− anchors {
68− verticalCenter: parent.verticalCenter
69− left: parent.left
70− leftMargin: units.gu(2)
71− }
72− name: "back"
73− height: units.gu(2)
74− width: height
75− color: root.foregroundColor
76− }
57+ DashNavigationHeader {
58+ id: navigationHeader
7759
78− Label {
79− anchors {
80− verticalCenter: parent.verticalCenter
81− left: backImage.right
82− right: parent.right
83− leftMargin: units.gu(0.5)
84− rightMargin: units.gu(2)
85− }
86− text: navigation ? navigation.parentLabel : ""
87− color: root.foregroundColor
88− wrapMode: Text.Wrap
89− maximumLineCount: 2
90− elide: Text.ElideMiddle
91− }
92− }
93−
94− ListItem.Standard {
95− id: allButton
96− objectName: "allButton"
97− visible: navigation && (!navigation.isRoot || (!navigation.hidden && root.currentNavigation && !root.currentNavigation.isRoot && root.currentNavigation.parentNavigationId == navigation.navigationId)) || false
9860 height: itemHeight
61+ width: parent.width
9962
100− Label {
101− anchors {
102− verticalCenter: parent.verticalCenter
103− left: parent.left
104− right: parent.right
105− leftMargin: units.gu(2)
106− rightMargin: units.gu(2)
107− }
108− text: navigation ? (navigation.allLabel != "" ? navigation.allLabel : navigation.label) : ""
109− font.bold: true
110− color: root.foregroundColor
111− wrapMode: Text.Wrap
112− maximumLineCount: 2
113− elide: Text.ElideMiddle
114− }
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) : ""
11569
116− onClicked: root.allNavigationClicked();
70+ onBackClicked: root.goBackToParentClicked();
71+ onTextClicked: root.allNavigationClicked();
11772 }
11873
11974 Repeater {
@@ -124,6 +79,9 @@ Item {
12479 height: root.itemHeight
12580 showDivider: index != navigation.count - 1
12681 selected: isActive
82+ anchors.left: parent.left
83+ anchors.leftMargin: navigationHeader.backVisible ? navigationHeader.backButtonWidth : 0
84+ anchors.right: parent.right
12785
12886 onClicked: root.enterNavigation(navigationId, hasChildren)
12987
@@ -131,7 +89,7 @@ Item {
13189 anchors {
13290 verticalCenter: parent.verticalCenter
13391 left: parent.left
134− leftMargin: units.gu(2)
92+ leftMargin: navigationHeader.backVisible ? 0 : units.gu(2)
13593 right: rightIcon.visible ? rightIcon.left : parent.right
13694 rightMargin: rightIcon.visible ? units.gu(0.5) : units.gu(2)
13795 }