on a67c059 help sign in
unity8/Panel/MenuContent.qml
156 lines 4.6 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"
22Rectangle {
23 id: content
25 property QtObject indicatorsModel: null
26 property bool __contentActive: false
27 readonly property int currentMenuIndex : menus.currentIndex
28 property color backgroundColor: "#221e1c" // FIXME not in palette yet
29 property int contentReleaseInterval: 20000
31 width: units.gu(40)
32 height: units.gu(42)
33 color: backgroundColor
35 function setCurrentMenuIndex(index) {
36 if (currentMenuIndex !== index) {
37 menus.currentIndex = index;
38 }
39 }
41 function activateContent() {
42 contentReleaseTimer.stop();
43 __contentActive = true;
44 }
46 function releaseContent() {
47 if (__contentActive)
48 contentReleaseTimer.restart();
49 }
51 ListView {
52 id: menus
53 objectName: "menus"
55 anchors.bottom: parent.bottom
56 anchors.top: header.bottom
57 width: parent.width
59 spacing: units.gu(0.5)
60 enabled: opacity != 0
61 orientation: ListView.Horizontal
62 model: indicatorsModel
63 interactive: false
64 //FIXME: This will make sure that all plugins still alive
65 //check bug https://bugs.launchpad.net/manhattan/+bug/1088945 for more details
66 cacheBuffer: 2147483647
68 delegate: Loader {
69 clip: true
70 property bool contentActive: content.__contentActive && menuActivator.content[index].active
72 onContentActiveChanged: {
73 if (contentActive && item) {
74 item.start();
75 } else if (!contentActive && item) {
76 item.stop();
77 }
78 }
80 width: menus.width
81 height: menus.height
82 source: pageSource
83 onVisibleChanged: {
84 // Reset the indicator states
85 if (!visible && item && item["reset"]) {
86 item.reset();
87 }
88 }
89 asynchronous: true
91 onLoaded: {
92 for(var pName in indicatorProperties) {
93 if (item.hasOwnProperty(pName)) {
94 item[pName] = indicatorProperties[pName];
95 }
96 }
97 if (contentActive && menus.visible) {
98 item.start();
99 }
100 }
102 // Need to use a binding because the handle height changes.
103 // FIXME: Dont know why we're using handle height (introduces dep).. Check with design about bottom margin
104 Binding {
105 target: item
106 property: "anchors.bottomMargin"
107 value: handle.height
108 }
109 }
110 }
112 Rectangle {
113 id: header
114 objectName: "header"
116 property alias title: pageHeader.text
118 color: backgroundColor
119 opacity: pageHeader.opacity
120 anchors {
121 left: parent.left
122 right: parent.right
123 }
124 height: childrenRect.height
126 PageHeader {
127 id: pageHeader
128 anchors {
129 left: parent.left
130 right: parent.right
131 }
132 text: {
133 if (indicatorsModel && menus.currentIndex >= 0 && menus.currentIndex < indicatorsModel.count)
134 return indicatorsModel.data(menus.currentIndex, Indicators.IndicatorsModelRole.Title);
135 return "";
136 }
137 }
138 }
140 Timer {
141 id: contentReleaseTimer
143 interval: contentReleaseInterval
144 onTriggered: {
145 __contentActive = false;
146 menuActivator.clear();
147 }
148 }
150 Indicators.MenuContentActivator {
151 id: menuActivator
152 running: content.__contentActive
153 baseIndex: content.currentMenuIndex
154 count: indicatorsModel.count
155 }