on xenial help sign in
Alt Navigation implementation
a3af675Albert Astals
qml/Dash/DashNavigation.qml → qml/Dash/DashNavigationButton.qmlrenamed+42−58
@@ -21,59 +21,35 @@ AbstractButton {
21 id: root
21 id: root
22 objectName: "dashNavigation"
22 objectName: "dashNavigation"
23
23
24+ // Set by parent
24 property var scope: null
25 property var scope: null
26+ property var scopeStyle: null
27+ property bool isAltNavigation: false
25
28
29+ // Used by parent
30+ readonly property var currentNavigation: scope && scope[hasNavigation] ? getNavigation(scope[currentNavigationId]) : null
31+ readonly property alias listView: navigationListView
26 property bool showList: false
32 property bool showList: false
27
33
28− readonly property var currentNavigation: scope && scope.hasNavigation ? scope.getNavigation(scope.currentNavigationId) : null
34+ // Internal
29−
30− property alias windowWidth: blackRect.width
31− property alias windowHeight: blackRect.height
32− property var scopeStyle: null
33−
34 // Are we drilling down the tree or up?
35 // Are we drilling down the tree or up?
35 property bool isGoingBack: false
36 property bool isGoingBack: false
37+ readonly property string hasNavigation: isAltNavigation ? "hasAltNavigation" : "hasNavigation"
38+ readonly property string currentNavigationId: isAltNavigation ? "currentAltNavigationId" : "currentNavigationId"
39+ function getNavigation(navId) {
40+ if (isAltNavigation) {
41+ return scope.getAltNavigation(navId);
42+ } else {
43+ return scope.getNavigation(navId);
44+ }
45+ }
36
46
37 visible: root.currentNavigation != null
47 visible: root.currentNavigation != null
38
48
39− height: visible ? units.gu(5) : 0
40−
41 onClicked: {
49 onClicked: {
42 root.showList = !root.showList;
50 root.showList = !root.showList;
43 }
51 }
44
52
45− Rectangle {
46− id: blackRect
47− color: "black"
48− opacity: navigationListView.currentItem && navigationListView.currentItem.visible ? 0.3 : 0
49− Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
50− anchors.top: navigationListView.top
51− anchors.right: parent.right
52− visible: opacity != 0
53− }
54−
55− Image {
56− anchors {
57− top: parent.top
58− left: parent.left
59− right: parent.right
60− }
61− fillMode: Image.Stretch
62− source: "graphics/dash_divider_top_lightgrad.png"
63− z: -1
64− }
65−
66− Image {
67− anchors {
68− bottom: parent.bottom
69− left: parent.left
70− right: parent.right
71− }
72− fillMode: Image.Stretch
73− source: "graphics/dash_divider_top_darkgrad.png"
74− z: -1
75− }
76−
77 Label {
53 Label {
78 anchors.fill: parent
54 anchors.fill: parent
79 anchors.margins: units.gu(2)
55 anchors.margins: units.gu(2)
@@ -106,11 +82,7 @@ AbstractButton {
106 // nullifyNavigation: overrides navigationId to be null
82 // nullifyNavigation: overrides navigationId to be null
107 // This is used to "clear" the delegate when going "right" on the tree
83 // This is used to "clear" the delegate when going "right" on the tree
108 }
84 }
109− anchors {
110− left: parent.left
111− right: parent.right
112− top: root.bottom
85+ anchors.top: root.bottom
113− }
114 readonly property int maxHeight: (windowHeight - mapToItem(null, root.x, root.y).y) - units.gu(8)
86 readonly property int maxHeight: (windowHeight - mapToItem(null, root.x, root.y).y) - units.gu(8)
115 property int prevHeight: maxHeight
87 property int prevHeight: maxHeight
116 height: currentItem ? currentItem.height : maxHeight
88 height: currentItem ? currentItem.height : maxHeight
@@ -138,7 +110,7 @@ AbstractButton {
138 }
110 }
139 }
111 }
140 height: desiredHeight
112 height: desiredHeight
141− navigation: (nullifyNavigation || !scope) ? null : scope.getNavigation(navigationId)
113+ navigation: (nullifyNavigation || !scope) ? null : getNavigation(navigationId)
142 currentNavigation: root.currentNavigation
114 currentNavigation: root.currentNavigation
143 onEnterNavigation: {
115 onEnterNavigation: {
144 scope.performQuery(navigationQuery);
116 scope.performQuery(navigationQuery);
@@ -177,27 +149,39 @@ AbstractButton {
177 }
149 }
178 }
150 }
179
151
180− InverseMouseArea {
181− anchors.fill: navigationListView
182− enabled: root.showList
183− onClicked: root.showList = false
184− }
185−
186 onScopeChanged: {
152 onScopeChanged: {
187 navigationModel.clear();
153 navigationModel.clear();
188− if (scope && scope.hasNavigation) {
154+ if (scope && scope[hasNavigation]) {
189− navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
155+ navigationModel.append({"navigationId": scope[currentNavigationId], "nullifyNavigation": false});
190 }
156 }
191 }
157 }
192
158
193 Connections {
159 Connections {
194 target: scope
160 target: scope
161+ // This is duplicated since we can't have something based on the dynamic hasNavigation string property
195 onHasNavigationChanged: {
162 onHasNavigationChanged: {
163+ if (!root.isAltNavigation) {
196− if (scope.hasNavigation) {
164+ if (scope.hasNavigation) {
197− navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
165+ navigationModel.append({"navigationId": scope.currentNavigationId, "nullifyNavigation": false});
198− } else {
166+ } else {
199− navigationModel.clear();
167+ navigationModel.clear();
168+ }
200 }
169 }
201 }
170 }
171+ onHasAltNavigationChanged: {
172+ if (root.isAltNavigation) {
173+ if (scope.hasAltNavigation) {
174+ navigationModel.append({"navigationId": scope.currentAltNavigationId, "nullifyNavigation": false});
175+ } else {
176+ navigationModel.clear();
177+ }
178+ }
179+ }
180+ }
181+
182+ InverseMouseArea {
183+ anchors.fill: navigationListView
184+ enabled: root.showList
185+ onClicked: root.showList = false
202 }
186 }
203}
187}
qml/Dash/DashNavigationList.qml+1−1
@@ -114,7 +114,7 @@ Item {
114 id: allButton
114 id: allButton
115 objectName: "allButton"
115 objectName: "allButton"
116 width: parent.width
116 width: parent.width
117− visible: navigation && (!navigation.isRoot || (root.currentNavigation && !root.currentNavigation.isRoot && root.currentNavigation.parentNavigationId == navigation.navigationId)) || false
117+ visible: navigation && (!navigation.isRoot || (!navigation.hidden && root.currentNavigation && !root.currentNavigation.isRoot && root.currentNavigation.parentNavigationId == navigation.navigationId)) || false
118 height: itemHeight
118 height: itemHeight
119
119
120 Label {
120 Label {
tests/mocks/Unity/fake_navigation.cpp+6−1
@@ -32,6 +32,7 @@ Navigation::Navigation(const QString& navigationId, const QString& label, const
32{
32{
33 QTimer::singleShot(1500, this, SLOT(slotLoaded()));
33 QTimer::singleShot(1500, this, SLOT(slotLoaded()));
34 connect(scope, SIGNAL(currentNavigationIdChanged()), this, SLOT(slotCurrentNavigationChanged()));
34 connect(scope, SIGNAL(currentNavigationIdChanged()), this, SLOT(slotCurrentNavigationChanged()));
35+ connect(scope, SIGNAL(currentAltNavigationIdChanged()), this, SLOT(slotCurrentNavigationChanged()));
35}
36}
36
37
37QString Navigation::navigationId() const
38QString Navigation::navigationId() const
@@ -118,7 +119,11 @@ QVariant Navigation::data(const QModelIndex &index, int role) const
118 case RoleHasChildren:
119 case RoleHasChildren:
119 return m_navigationId == "root" && index.row() != 3;
120 return m_navigationId == "root" && index.row() != 3;
120 case RoleIsActive:
121 case RoleIsActive:
122+ if (m_navigationId.startsWith("alt")) {
123+ return m_scope->currentAltNavigationId() == data(index, RoleNavigationId);
124+ } else {
121− return m_scope->currentNavigationId() == data(index, RoleNavigationId);
125+ return m_scope->currentNavigationId() == data(index, RoleNavigationId);
126+ }
122 }
127 }
123 return QVariant();
128 return QVariant();
124}
129}
tests/mocks/Unity/fake_scope.cpp+7−2
@@ -244,11 +244,16 @@ unity::shell::scopes::NavigationInterface* Scope::getAltNavigation(QString const
244
244
245 QString parentId;
245 QString parentId;
246 QString parentLabel;
246 QString parentLabel;
247− if (id.startsWith("altmiddle")) {
247+ if (id != "altroot") {
248 parentId = "altroot";
248 parentId = "altroot";
249 parentLabel = "altroot";
249 parentLabel = "altroot";
250 }
250 }
251− return new Navigation(id, id, "all"+id, parentId, parentLabel, this);
251+ auto result = new Navigation(id, id, "all"+id, parentId, parentLabel, this);
252+ if (id == "altroot") {
253+ m_currentAltNavigationId = "altrootChild1";
254+ Q_EMIT currentAltNavigationIdChanged();
255+ }
256+ return result;
252}
257}
253
258
254void Scope::performQuery(const QString& query)
259void Scope::performQuery(const QString& query)