on xenial help sign in
Using visibleindicatorsmodel to source filtermodel for both row & menuContent
commit09e39276d0a93aa80fd63f0801e119f15f049823 authorNick Dedekind <nicholas.dedekind@gmail.com> dateTue 14 Jan 2014, 15:35 (13 years ago) parent3938582
6 files changed+129−90
qml/Panel/IndicatorRow.qml−44 qml/Panel/Indicators.qml+7−19 qml/Panel/Indicators/IndicatorDelegate.qml+34 qml/Panel/Indicators/VisibleIndicatorsModel.qml+81 qml/Panel/MenuContent.qml+6−26 qml/Panel/Panel.qml+1−1
qml/Panel/IndicatorRow.qml−44
@@ -26,7 +26,6 @@ Item {
2626 readonly property alias currentItemIndex: itemView.currentIndex
2727 readonly property alias row: itemView
2828 property QtObject indicatorsModel: null
29− property var visibleIndicators: undefined
3029 property int overFlowWidth: width
3130 property bool showAll: false
3231 property real currentItemOffset: 0.0
@@ -86,7 +85,6 @@ Item {
8685 objectName: "item" + index
8786 height: indicatorRow.height
8887 width: visible ? indicatorItem.width : 0
89− visible: indicatorItem.indicatorVisible
9088 opacity: 1 - indicatorRow.unitProgress
9189 y: 0
9290 state: "standard"
@@ -107,48 +105,6 @@ Item {
107105
108106 widgetSource: model.widgetSource
109107 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− }
152108 }
153109
154110 states: [
qml/Panel/Indicators.qml+7−19
@@ -21,6 +21,7 @@ import Unity.Indicators 0.1 as Indicators
2121
2222import "../Components"
2323import "../Components/ListItems"
24+import "Indicators"
2425
2526Showable {
2627 id: indicators
@@ -179,6 +180,10 @@ Showable {
179180 source: "graphics/VerticalDivider.png"
180181 }
181182
183+ VisibleIndicatorsModel {
184+ id: indicatorsModel
185+ }
186+
182187 MenuContent {
183188 id: menuContent
184189 objectName: "menuContent"
@@ -220,13 +225,9 @@ Showable {
220225 right: parent.right
221226 bottom: parent.bottom
222227 }
223− height: get_height()
228+ height: Math.max(Math.min(handleImage.height, indicators.height - handleImage.height), 0)
224229 clip: height < handleImage.height
225230
226− function get_height() {
227− return Math.max(Math.min(handleImage.height, indicators.height - handleImage.height), 0);
228− }
229−
230231 BorderImage {
231232 id: handleImage
232233 source: "graphics/handle.sci"
@@ -246,10 +247,6 @@ Showable {
246247 anchors.fill: indicatorRow
247248 }
248249
249− Indicators.IndicatorsModel {
250− id: indicatorsModel
251− }
252−
253250 IndicatorRow {
254251 id: indicatorRow
255252 objectName: "indicatorRow"
@@ -262,14 +259,6 @@ Showable {
262259 state: indicators.state
263260 unitProgress: indicators.unitProgress
264261
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−
273262 EdgeDragArea {
274263 id: rowDragArea
275264 anchors.fill: indicatorRow
@@ -315,7 +304,6 @@ Showable {
315304 indicators.state = "initial";
316305 initalizeItem = true;
317306 indicatorRow.currentItemOffset = 0;
318− menuContent.animateNextMenuChange = false;
319307 }
320308 }
321309 }
@@ -346,7 +334,7 @@ Showable {
346334 if (!oldActive) return;
347335 d.enableIndexChangeSignal = false;
348336
349− menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex);
337+ menuContent.setCurrentMenuIndex(indicatorRow.currentItemIndex, fullyOpened || partiallyOpened);
350338
351339 d.enableIndexChangeSignal = oldActive;
352340 }
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 {
2828
2929 property QtObject indicatorsModel: null
3030 property bool __contentActive: false
31− readonly property int currentMenuIndex : filteredIndicators.mapToSource(tabs.selectedTabIndex)
31+ readonly property int currentMenuIndex: tabs.selectedTabIndex
3232 backgroundColor: "#221e1c" // FIXME not in palette yet
3333 property int contentReleaseInterval: 20000
3434 property bool activeHeader: false
35− property alias visibleIndicators: visibleIndicatorsModel.visible
36− property bool animateNextMenuChange: false
3735 property real headerHeight: tabs.tabBar.height
3836
3937 width: units.gu(40)
4038 height: units.gu(42)
4139
42− function setCurrentMenuIndex(index) {
43− var filteredIndex = filteredIndicators.mapFromSource(index);
44−
45− if (tabs.selectedTabIndex !== filteredIndex) {
46− if (tabs.selectedTabIndex === -1 || !animateNextMenuChange) {
40+ function setCurrentMenuIndex(index, animate) {
41+ if (tabs.selectedTabIndex !== index) {
42+ if (tabs.selectedTabIndex === -1 || !animate) {
4743 tabs.tabBar.animate = false;
4844 }
49− tabs.selectedTabIndex = filteredIndex;
45+ tabs.selectedTabIndex = index;
5046 tabs.tabBar.animate = true;
51− animateNextMenuChange = true;
5247 }
5348 }
5449
@@ -68,29 +63,14 @@ MainView {
6863 tabs.tabBar.alwaysSelectionMode = activeHeader;
6964 }
7065
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−
8566 Tabs {
8667 id: tabs
8768 objectName: "tabs"
8869 anchors.fill: parent
89− selectedTabIndex: -1
9070
9171 Repeater {
9272 id: repeater
93− model: filteredIndicators
73+ model: indicatorsModel ? indicatorsModel : null
9474 objectName: "tabsRepeater"
9575
9676 // FIXME: This is needed because tabs dont handle repeaters well.
qml/Panel/Panel.qml+1−1
@@ -50,7 +50,7 @@ Item {
5050
5151 Connections {
5252 target: indicatorsMenu
53− onShown: hideTimer.stop()
53+ onShownChanged: hideTimer.stop()
5454 }
5555
5656 PanelBackground {