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