on 551c708 help sign in
unity8/qml/Panel/MenuContent.qml
157 lines 5.2 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: tabs.selectedTabIndex
32 backgroundColor: "#221e1c" // FIXME not in palette yet
33 property int contentReleaseInterval: 20000
34 property bool activeHeader: false
35 property real headerHeight: tabs.tabBar.height
37 width: units.gu(40)
38 height: units.gu(42)
40 function setCurrentMenuIndex(index, animate) {
41 if (tabs.selectedTabIndex !== index) {
42 if (tabs.selectedTabIndex === -1 || !animate) {
43 tabs.tabBar.animate = false;
44 }
45 tabs.selectedTabIndex = index;
46 tabs.tabBar.animate = true;
47 }
48 }
50 function activateContent() {
51 contentReleaseTimer.stop();
52 __contentActive = true;
53 }
55 function releaseContent() {
56 if (__contentActive) {
57 contentReleaseTimer.restart();
58 }
59 }
61 onActiveHeaderChanged: {
62 tabs.tabBar.selectionMode = activeHeader;
63 tabs.tabBar.alwaysSelectionMode = activeHeader;
64 }
66 Tabs {
67 id: tabs
68 objectName: "tabs"
69 anchors.fill: parent
71 Repeater {
72 id: repeater
73 model: content.indicatorsModel ? content.indicatorsModel : null
74 objectName: "tabsRepeater"
76 // FIXME: This is needed because tabs dont handle repeaters well.
77 // Due to the child ordering happening after child insertion.
78 // QTBUG-32438
79 onItemAdded: {
80 parent.childrenChanged();
81 }
83 Tab {
84 id: tab
85 objectName: model.identifier
87 page: Page {
88 Loader {
89 id: loader
90 clip: true
91 anchors.fill: parent
92 source: pageSource
93 asynchronous: true
95 readonly property bool indexActive: index >= 0 && index < menuActivator.count && menuActivator.content[index].active
96 readonly property bool contentActive: content.__contentActive && indexActive
98 onContentActiveChanged: {
99 if (contentActive && item) {
100 item.start()
101 } else if (!contentActive && item) {
102 item.stop()
103 }
104 }
106 onVisibleChanged: {
107 // Reset the indicator states
108 if (!visible && item && item["reset"]) {
109 item.reset()
110 }
111 }
113 onLoaded: {
114 for(var pName in indicatorProperties) {
115 if (item.hasOwnProperty(pName)) {
116 item[pName] = indicatorProperties[pName]
117 }
118 }
119 if (contentActive && tabs.visible) {
120 item.start()
121 }
122 }
124 Binding {
125 target: tab
126 property: "title"
127 value: loader.item && loader.item.hasOwnProperty("title") && loader.item.title !== "" ? loader.item.title : model.identifier
128 }
130 Binding {
131 target: loader.item
132 property: "objectName"
133 value: identifier + "-page"
134 }
135 }
136 }
137 }
138 }
139 }
141 Timer {
142 id: contentReleaseTimer
144 interval: contentReleaseInterval
145 onTriggered: {
146 content.__contentActive = false;
147 menuActivator.clear();
148 }
149 }
151 Indicators.MenuContentActivator {
152 id: menuActivator
153 running: content.__contentActive
154 baseIndex: content.currentMenuIndex
155 count: indicatorsModel.count
156 }