on xenial help sign in
Using visibleindicatorsmodel to source filtermodel for both row & menuContent
09e3927Nick Dedekind
qml/Panel/IndicatorRow.qml−44
@@ -26,7 +26,6 @@ Item {
26 readonly property alias currentItemIndex: itemView.currentIndex
26 readonly property alias currentItemIndex: itemView.currentIndex
27 readonly property alias row: itemView
27 readonly property alias row: itemView
28 property QtObject indicatorsModel: null
28 property QtObject indicatorsModel: null
29− property var visibleIndicators: undefined
30 property int overFlowWidth: width
29 property int overFlowWidth: width
31 property bool showAll: false
30 property bool showAll: false
32 property real currentItemOffset: 0.0
31 property real currentItemOffset: 0.0
@@ -86,7 +85,6 @@ Item {
86 objectName: "item" + index
85 objectName: "item" + index
87 height: indicatorRow.height
86 height: indicatorRow.height
88 width: visible ? indicatorItem.width : 0
87 width: visible ? indicatorItem.width : 0
89− visible: indicatorItem.indicatorVisible
90 opacity: 1 - indicatorRow.unitProgress
88 opacity: 1 - indicatorRow.unitProgress
91 y: 0
89 y: 0
92 state: "standard"
90 state: "standard"
@@ -107,48 +105,6 @@ Item {
107
105
108 widgetSource: model.widgetSource
106 widgetSource: model.widgetSource
109 indicatorProperties : model.indicatorProperties
107 indicatorProperties : model.indicatorProperties
110−
111− Component.onCompleted: {
112− updateVisiblility();
113− }
114− onIndicatorVisibleChanged: {
115− updateVisiblility();
116−
117− if (indicatorVisible) {
118− showAll = true;
119− allVisible.start();
120− }
121− }
122−
123− function updateVisiblility() {
124− if (visibleIndicators == undefined) {
125− visibleIndicators = {}
126− }
127− indicatorRow.visibleIndicators[model.identifier] = indicatorVisible;
128−
129− // removed current index?
130− if (indicatorRow.currentItemIndex === index && !indicatorVisible) {
131− // find the next closest visible indicator (after current, else before)
132− var newIndex = -1;
133− for (var i = index+1; i < itemView.count; i++) {
134− if (indicatorRow.visibleIndicators[i] === undefined || indicatorRow.visibleIndicators[model.identifier]) {
135− newIndex = i;
136− break;
137− }
138− }
139− if (newIndex === -1) {
140− for (i = index - 1; i >= 0; i--) {
141− if (indicatorRow.visibleIndicators[i] === undefined || indicatorRow.visibleIndicators[model.identifier]) {
142− newIndex = i;
143− break;
144− }
145− }
146− }
147− indicatorRow.setCurrentItemIndex(newIndex);
148− }
149−
150− indicatorRow.visibleIndicatorsChanged();
151− }
152 }
108 }
153
109
154 states: [
110 states: [
qml/Panel/Indicators.qml+7−19
@@ -21,6 +21,7 @@ import Unity.Indicators 0.1 as Indicators
21
21
22import "../Components"
22import "../Components"
23import "../Components/ListItems"
23import "../Components/ListItems"
24+import "Indicators"
24
25
25Showable {
26Showable {
26 id: indicators
27 id: indicators
@@ -179,6 +180,10 @@ Showable {
179 source: "graphics/VerticalDivider.png"
180 source: "graphics/VerticalDivider.png"
180 }
181 }
181
182
183+ VisibleIndicatorsModel {
184+ id: indicatorsModel
185+ }
186+
182 MenuContent {
187 MenuContent {
183 id: menuContent
188 id: menuContent
184 objectName: "menuContent"
189 objectName: "menuContent"
@@ -220,13 +225,9 @@ Showable {
220 right: parent.right
225 right: parent.right
221 bottom: parent.bottom
226 bottom: parent.bottom
222 }
227 }
223− height: get_height()
228+ height: Math.max(Math.min(handleImage.height, indicators.height - handleImage.height), 0)
224 clip: height < handleImage.height
229 clip: height < handleImage.height
225
230
226− function get_height() {
227− return Math.max(Math.min(handleImage.height, indicators.height - handleImage.height), 0);
228− }
229−
230 BorderImage {
231 BorderImage {
231 id: handleImage
232 id: handleImage
232 source: "graphics/handle.sci"
233 source: "graphics/handle.sci"
@@ -246,10 +247,6 @@ Showable {
246 anchors.fill: indicatorRow
247 anchors.fill: indicatorRow
247 }
248 }
248
249
249− Indicators.IndicatorsModel {
250− id: indicatorsModel
251− }
252−
253 IndicatorRow {
250 IndicatorRow {
254 id: indicatorRow
251 id: indicatorRow
255 objectName: "indicatorRow"
252 objectName: "indicatorRow"
@@ -262,14 +259,6 @@ Showable {
262 state: indicators.state
259 state: indicators.state
263 unitProgress: indicators.unitProgress
260 unitProgress: indicators.unitProgress
264
261
265− onVisibleIndicatorsChanged: {
266− // need to do it here so we can control sequence
267− if (visibleIndicators !== undefined) {
268− menuContent.visibleIndicators = visibleIndicators;
269− menuContent.setCurrentMenuIndex(currentItemIndex);
270− }
271− }
272−
273 EdgeDragArea {
262 EdgeDragArea {
274 id: rowDragArea
263 id: rowDragArea
275 anchors.fill: indicatorRow
264 anchors.fill: indicatorRow
@@ -315,7 +304,6 @@ Showable {
315 indicators.state = "initial";
304 indicators.state = "initial";
316 initalizeItem = true;
305 initalizeItem = true;
317 indicatorRow.currentItemOffset = 0;
306 indicatorRow.currentItemOffset = 0;
318− menuContent.animateNextMenuChange = false;
319 }
307 }
320 }
308 }
321 }
309 }
@@ -346,7 +334,7 @@ Showable {
346 if (!oldActive) return;
334 if (!oldActive) return;
347 d.enableIndexChangeSignal = false;
335 d.enableIndexChangeSignal = false;
348
336
349− menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex);
337+ menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex, fullyOpened || partiallyOpened);
350
338
351 d.enableIndexChangeSignal = oldActive;
339 d.enableIndexChangeSignal = oldActive;
352 }
340 }
qml/Panel/Indicators/IndicatorDelegate.qmlnew file+34
@@ -0,0 +1,34 @@
1+/*
2+ * Copyright 2013 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Nick Dedekind <nick.dedekind@canonical.com>
18+ */
19+
20+import QtQuick 2.0
21+import Unity.Indicators 0.1 as Indicators
22+
23+Indicators.IndicatorBase {
24+ enabled: false
25+
26+ onRootActionStateChanged: {
27+ if (rootActionState == undefined) {
28+ enabled = false;
29+ return;
30+ }
31+
32+ enabled = rootActionState.visible;
33+ }
34+}
qml/Panel/Indicators/VisibleIndicatorsModel.qmlnew file+81
@@ -0,0 +1,81 @@
1+/*
2+ * Copyright 2013 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ *
16+ * Authors:
17+ * Nick Dedekind <nick.dedekind@canonical.com>
18+ */
19+
20+import QtQuick 2.0
21+import Unity.Indicators 0.1 as Indicators
22+import Utils 0.1
23+
24+SortFilterProxyModel {
25+ id: filteredIndicators
26+
27+ model: Indicators.VisibleIndicatorsModel {
28+ id: visibleIndicatorsModel
29+ model: indicatorsModel
30+ }
31+
32+ filterRole: Indicators.IndicatorsModelRole.IsVisible
33+ filterRegExp: RegExp("^true$")
34+ dynamicSortFilter: true
35+
36+ property Item __container: Item {
37+ Indicators.IndicatorsModel {
38+ id: indicatorsModel
39+ }
40+
41+ Repeater {
42+ id: repeater
43+ model: indicatorsModel
44+
45+ property var visibleIndicators: undefined
46+ onVisibleIndicatorsChanged: {
47+ if (visibleIndicators !== undefined) {
48+ visibleIndicatorsModel.visible = visibleIndicators;
49+ }
50+ }
51+
52+ delegate: IndicatorDelegate {
53+ id: item
54+ Component.onCompleted: {
55+ for(var pName in indicatorProperties) {
56+ if (item.hasOwnProperty(pName)) {
57+ item[pName] = indicatorProperties[pName];
58+ }
59+ }
60+ updateVisibility();
61+ }
62+
63+ onEnabledChanged: {
64+ updateVisibility()
65+ }
66+
67+ function updateVisibility() {
68+ if (repeater.visibleIndicators === undefined) {
69+ repeater.visibleIndicators = {}
70+ }
71+ repeater.visibleIndicators[model.identifier] = enabled;
72+ repeater.visibleIndicatorsChanged();
73+ }
74+ }
75+ }
76+ }
77+
78+ function load() {
79+ indicatorsModel.load();
80+ }
81+}
qml/Panel/MenuContent.qml+6−26
@@ -28,27 +28,22 @@ MainView {
28
28
29 property QtObject indicatorsModel: null
29 property QtObject indicatorsModel: null
30 property bool __contentActive: false
30 property bool __contentActive: false
31− readonly property int currentMenuIndex : filteredIndicators.mapToSource(tabs.selectedTabIndex)
31+ readonly property int currentMenuIndex: tabs.selectedTabIndex
32 backgroundColor: "#221e1c" // FIXME not in palette yet
32 backgroundColor: "#221e1c" // FIXME not in palette yet
33 property int contentReleaseInterval: 20000
33 property int contentReleaseInterval: 20000
34 property bool activeHeader: false
34 property bool activeHeader: false
35− property alias visibleIndicators: visibleIndicatorsModel.visible
36− property bool animateNextMenuChange: false
37 property real headerHeight: tabs.tabBar.height
35 property real headerHeight: tabs.tabBar.height
38
36
39 width: units.gu(40)
37 width: units.gu(40)
40 height: units.gu(42)
38 height: units.gu(42)
41
39
42− function setCurrentMenuIndex(index) {
40+ function setCurrentMenuIndex(index, animate) {
43− var filteredIndex = filteredIndicators.mapFromSource(index);
44−
45− if (tabs.selectedTabIndex !== filteredIndex) {
41+ if (tabs.selectedTabIndex !== index) {
46− if (tabs.selectedTabIndex === -1 || !animateNextMenuChange) {
42+ if (tabs.selectedTabIndex === -1 || !animate) {
47 tabs.tabBar.animate = false;
43 tabs.tabBar.animate = false;
48 }
44 }
49− tabs.selectedTabIndex = filteredIndex;
45+ tabs.selectedTabIndex = index;
50 tabs.tabBar.animate = true;
46 tabs.tabBar.animate = true;
51− animateNextMenuChange = true;
52 }
47 }
53 }
48 }
54
49
@@ -68,29 +63,14 @@ MainView {
68 tabs.tabBar.alwaysSelectionMode = activeHeader;
63 tabs.tabBar.alwaysSelectionMode = activeHeader;
69 }
64 }
70
65
71− SortFilterProxyModel {
72− id: filteredIndicators
73− model: visibleIndicatorsModel
74− dynamicSortFilter: true
75−
76− filterRole: Indicators.IndicatorsModelRole.IsVisible
77− filterRegExp: RegExp("^true$")
78− }
79−
80− Indicators.VisibleIndicatorsModel {
81− id: visibleIndicatorsModel
82− model: indicatorsModel
83− }
84−
85 Tabs {
66 Tabs {
86 id: tabs
67 id: tabs
87 objectName: "tabs"
68 objectName: "tabs"
88 anchors.fill: parent
69 anchors.fill: parent
89− selectedTabIndex: -1
90
70
91 Repeater {
71 Repeater {
92 id: repeater
72 id: repeater
93− model: filteredIndicators
73+ model: indicatorsModel ? indicatorsModel : null
94 objectName: "tabsRepeater"
74 objectName: "tabsRepeater"
95
75
96 // FIXME: This is needed because tabs dont handle repeaters well.
76 // FIXME: This is needed because tabs dont handle repeaters well.
qml/Panel/Panel.qml+1−1
@@ -50,7 +50,7 @@ Item {
50
50
51 Connections {
51 Connections {
52 target: indicatorsMenu
52 target: indicatorsMenu
53− onShown: hideTimer.stop()
53+ onShownChanged: hideTimer.stop()
54 }
54 }
55
55
56 PanelBackground {
56 PanelBackground {