on 5ea1eca help sign in
unity8/qml/Panel/MenuContent.qml
170 lines 5.5 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
36 property bool animateNextMenuChange: false
38 width: units.gu(40)
39 height: units.gu(42)
41 function setCurrentMenuIndex(index) {
42 var filteredIndex = filteredIndicators.mapFromSource(index)
44 if (tabs.selectedTabIndex !== filteredIndex) {
45 if (tabs.selectedTabIndex == -1 || !animateNextMenuChange) {
46 tabs.tabBar.animate = false;
47 }
48 tabs.selectedTabIndex = filteredIndex;
49 tabs.tabBar.animate = true;
50 animateNextMenuChange = true;
51 }
52 }
54 function activateContent() {
55 contentReleaseTimer.stop();
56 __contentActive = true;
57 }
59 function releaseContent() {
60 if (__contentActive) {
61 contentReleaseTimer.restart();
62 }
63 }
65 onActiveHeaderChanged: {
66 tabs.tabBar.selectionMode = activeHeader;
67 tabs.tabBar.alwaysSelectionMode = activeHeader;
68 }
70 SortFilterProxyModel {
71 id: filteredIndicators
72 model: visibleIndicatorsModel
73 dynamicSortFilter: true
75 filterRole: Indicators.IndicatorsModelRole.IsVisible
76 filterRegExp: RegExp("^true$")
77 }
79 Indicators.VisibleIndicatorsModel {
80 id: visibleIndicatorsModel
81 model: indicatorsModel
82 }
84 Tabs {
85 id: tabs
86 objectName: "tabs"
87 anchors.fill: parent
88 selectedTabIndex: -1
90 Repeater {
91 id: repeater
92 model: filteredIndicators
93 objectName: "tabsRepeater"
95 // FIXME: This is needed because tabs dont handle repeaters well.
96 // Due to the child ordering happening after child insertion.
97 // QTBUG-32438
98 onItemAdded: {
99 parent.childrenChanged();
100 }
102 Tab {
103 id: tab
104 objectName: model.identifier
106 page: Page {
107 Loader {
108 id: loader
109 clip: true
110 anchors.fill: parent
111 source: pageSource
112 asynchronous: true
114 readonly property bool indexActive: index >= 0 && index < menuActivator.count && menuActivator.content[index].active
115 readonly property bool contentActive: content.__contentActive && indexActive
117 onContentActiveChanged: {
118 if (contentActive && item) {
119 item.start()
120 } else if (!contentActive && item) {
121 item.stop()
122 }
123 }
125 onVisibleChanged: {
126 // Reset the indicator states
127 if (!visible && item && item["reset"]) {
128 item.reset()
129 }
130 }
132 onLoaded: {
133 for(var pName in indicatorProperties) {
134 if (item.hasOwnProperty(pName)) {
135 item[pName] = indicatorProperties[pName]
136 }
137 }
138 if (contentActive && tabs.visible) {
139 item.start()
140 }
141 }
143 Binding {
144 target: tab
145 property: "title"
146 value: loader.item && loader.item.hasOwnProperty("title") && loader.item.title !== "" ? loader.item.title : model.identifier
147 }
148 }
149 }
150 }
151 }
152 }
154 Timer {
155 id: contentReleaseTimer
157 interval: contentReleaseInterval
158 onTriggered: {
159 content.__contentActive = false;
160 menuActivator.clear();
161 }
162 }
164 Indicators.MenuContentActivator {
165 id: menuActivator
166 running: content.__contentActive
167 baseIndex: content.currentMenuIndex
168 count: indicatorsModel.count
169 }