on 5bc8421 help sign in
unity8/Panel/MenuContent.qml
161 lines 5.0 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
103 title: model.title
105 page: Page {
106 Loader {
107 clip: true
108 anchors.fill: parent
109 source: pageSource
110 asynchronous: true
112 property bool contentActive: content.__contentActive && menuActivator.content[index].active
114 onContentActiveChanged: {
115 if (contentActive && item) {
116 item.start()
117 } else if (!contentActive && item) {
118 item.stop()
119 }
120 }
122 onVisibleChanged: {
123 // Reset the indicator states
124 if (!visible && item && item["reset"]) {
125 item.reset()
126 }
127 }
129 onLoaded: {
130 for(var pName in indicatorProperties) {
131 if (item.hasOwnProperty(pName)) {
132 item[pName] = indicatorProperties[pName]
133 }
134 }
135 if (contentActive && tabs.visible) {
136 item.start()
137 }
138 }
139 }
140 }
141 }
142 }
143 }
145 Timer {
146 id: contentReleaseTimer
148 interval: contentReleaseInterval
149 onTriggered: {
150 content.__contentActive = false;
151 menuActivator.clear();
152 }
153 }
155 Indicators.MenuContentActivator {
156 id: menuActivator
157 running: content.__contentActive
158 baseIndex: content.currentMenuIndex
159 count: indicatorsModel.count
160 }