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