on 3c8fd5f help sign in
unity8/Panel/MenuContent.qml
133 lines 4.1 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 "../Components"
22// FIXME : We dont want to use MainView.
23// Need a regular Item which can have tabs with local header.
24// https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1211704
25MainView {
26 id: content
28 property QtObject indicatorsModel: null
29 property bool __contentActive: false
30 readonly property int currentMenuIndex : tabs.selectedTabIndex
31 backgroundColor: "#221e1c" // FIXME not in palette yet
32 property int contentReleaseInterval: 20000
33 property bool activeHeader: false
35 width: units.gu(40)
36 height: units.gu(42)
38 function setCurrentMenuIndex(index) {
39 if (currentMenuIndex !== index) {
40 if (currentMenuIndex == -1) {
41 tabs.tabBar.animate = false;
42 }
43 tabs.selectedTabIndex = index;
44 tabs.tabBar.animate = true;
45 }
46 }
48 function activateContent() {
49 contentReleaseTimer.stop();
50 __contentActive = true;
51 }
53 function releaseContent() {
54 if (__contentActive) {
55 contentReleaseTimer.restart();
56 }
57 }
59 onActiveHeaderChanged: {
60 tabs.tabBar.selectionMode = activeHeader;
61 tabs.tabBar.alwaysSelectionMode = activeHeader;
62 }
64 Tabs {
65 id: tabs
66 objectName: "tabs"
67 anchors.fill: parent
68 selectedTabIndex: -1
70 Repeater {
71 id: repeater
72 model: indicatorsModel
73 objectName: "menus"
75 // FIXME: This is needed because tabs dont handle repeaters well.
76 // Due to the child ordering happening after child insertion.
77 // QTBUG-32438
78 onItemAdded: {
79 parent.childrenChanged();
80 }
82 Tab {
83 id: tab
84 objectName: model.identifier
85 title: model.title
87 page: Page {
88 Loader {
89 clip: true
90 anchors.fill: parent
91 source: pageSource
92 asynchronous: true
94 property bool contentActive: content.__contentActive
96 onContentActiveChanged: {
97 if (contentActive && item) {
98 item.start()
99 } else if (!contentActive && item) {
100 item.stop()
101 }
102 }
104 onVisibleChanged: {
105 // Reset the indicator states
106 if (!visible && item && item["reset"]) {
107 item.reset()
108 }
109 }
111 onLoaded: {
112 for(var pName in indicatorProperties) {
113 if (item.hasOwnProperty(pName)) {
114 item[pName] = indicatorProperties[pName]
115 }
116 }
117 if (contentActive && menus.visible) {
118 item.start()
119 }
120 }
121 }
122 }
123 }
124 }
125 }
127 Timer {
128 id: contentReleaseTimer
130 interval: contentReleaseInterval
131 onTriggered: content.__contentActive = false
132 }