on 7cd287d help sign in
unity8/Panel/MenuContent.qml
168 lines 5.4 kB history raw
1/*
2 * Copyright (C) 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 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 */
17import QtQuick 2.0
18import Ubuntu.Components 0.1
19import Unity.Indicators 0.1 as Indicators
20import Utils 0.1
21import "../Components"
23// FIXME : We dont want to use MainView.
24// Need a regular Item which can have tabs with local header.
25// https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1211704
26MainView {
27 id: content
29 property QtObject indicatorsModel: null
30 property bool __contentActive: false
31 readonly property int currentMenuIndex : filteredIndicators.mapToSource(tabs.selectedTabIndex)
32 backgroundColor: "#221e1c" // FIXME not in palette yet
33 property int contentReleaseInterval: 20000
34 property bool activeHeader: false
35 property alias visibleIndicators: visibleIndicatorsModel.visible
37 width: units.gu(40)
38 height: units.gu(42)
40 function setCurrentMenuIndex(index) {
41 var filteredIndex = filteredIndicators.mapFromSource(index)
43 if (tabs.selectedTabIndex !== filteredIndex) {
44 if (tabs.selectedTabIndex == -1) {
45 tabs.tabBar.animate = false;
46 }
47 tabs.selectedTabIndex = filteredIndex;
48 tabs.tabBar.animate = true;
49 }
50 }
52 function activateContent() {
53 contentReleaseTimer.stop();
54 __contentActive = true;
55 }
57 function releaseContent() {
58 if (__contentActive) {
59 contentReleaseTimer.restart();
60 }
61 }
63 onActiveHeaderChanged: {
64 tabs.tabBar.selectionMode = activeHeader;
65 tabs.tabBar.alwaysSelectionMode = activeHeader;
66 }
68 SortFilterProxyModel {
69 id: filteredIndicators
70 model: visibleIndicatorsModel
71 dynamicSortFilter: true
73 filterRole: Indicators.IndicatorsModelRole.IsVisible
74 filterRegExp: RegExp("^true$")
75 }
77 Indicators.VisibleIndicatorsModel {
78 id: visibleIndicatorsModel
79 model: indicatorsModel
80 }
82 Tabs {
83 id: tabs
84 objectName: "tabs"
85 anchors.fill: parent
86 selectedTabIndex: -1
88 Repeater {
89 id: repeater
90 model: filteredIndicators
91 objectName: "tabsRepeater"
93 // FIXME: This is needed because tabs dont handle repeaters well.
94 // Due to the child ordering happening after child insertion.
95 // QTBUG-32438
96 onItemAdded: {
97 parent.childrenChanged();
98 }
100 Tab {
101 id: tab
102 objectName: model.identifier
104 page: Page {
105 Loader {
106 id: loader
107 clip: true
108 anchors.fill: parent
109 source: pageSource
110 asynchronous: true
112 readonly property bool indexActive: index >= 0 && index < menuActivator.count && menuActivator.content[index].active
113 readonly property bool contentActive: content.__contentActive && indexActive
115 onContentActiveChanged: {
116 if (contentActive && item) {
117 item.start()
118 } else if (!contentActive && item) {
119 item.stop()
120 }
121 }
123 onVisibleChanged: {
124 // Reset the indicator states
125 if (!visible && item && item["reset"]) {
126 item.reset()
127 }
128 }
130 onLoaded: {
131 for(var pName in indicatorProperties) {
132 if (item.hasOwnProperty(pName)) {
133 item[pName] = indicatorProperties[pName]
134 }
135 }
136 if (contentActive && tabs.visible) {
137 item.start()
138 }
139 }
141 Binding {
142 target: tab
143 property: "title"
144 value: loader.item && loader.item.hasOwnProperty("title") && loader.item.title !== "" ? loader.item.title : model.identifier
145 }
146 }
147 }
148 }
149 }
150 }
152 Timer {
153 id: contentReleaseTimer
155 interval: contentReleaseInterval
156 onTriggered: {
157 content.__contentActive = false;
158 menuActivator.clear();
159 }
160 }
162 Indicators.MenuContentActivator {
163 id: menuActivator
164 running: content.__contentActive
165 baseIndex: content.currentMenuIndex
166 count: indicatorsModel.count
167 }