on 73354fd help sign in
unity8/Panel/MenuContent.qml
204 lines 6.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 "Menus"
20import "../Components"
22Rectangle {
23 id: content
25 property QtObject indicatorsModel: null
26 property bool animate: true // FIXME: Remove. This doesnt seem to be being used and it's referenced in Indicators.
27 property bool overviewActive: true // "state of the menu"
28 property bool __shown: false
29 property bool __contentActive: false
30 property alias currentIndex : menus.currentIndex
31 property color backgroundColor: "#221e1c"
32 property int contentReleaseInterval: 5000
34 width: units.gu(40)
35 height: units.gu(42)
36 color: backgroundColor
37 enabled: __shown
39 signal menuSelected(int index)
41 function showMenu() {
42 __shown = true
43 overviewActive = false
44 }
46 function showOverview() {
47 __shown = true
48 overviewActive = true
49 }
51 function hideAll() {
52 __shown = false
53 }
55 function activateContent() {
56 contentReleaseTimer.stop()
57 __contentActive = true
58 }
60 function releaseContent() {
61 if (__contentActive)
62 contentReleaseTimer.restart()
63 }
65 ListView {
66 id: menus
67 objectName: "menus"
69 anchors.bottom: parent.bottom
70 anchors.top: header.bottom
71 width: parent.width
73 spacing: units.gu(0.5)
74 opacity: !overviewActive && __shown ? 1 : 0
75 enabled: opacity != 0
76 orientation: ListView.Horizontal
77 model: indicatorsModel
78 interactive: false
79 //FIXME: This will make sure that all plugins still alive
80 //check bug https://bugs.launchpad.net/manhattan/+bug/1088945 for more details
81 cacheBuffer: 2147483647
83 delegate: Loader {
84 clip: true
85 property bool contentActive: content.__contentActive
87 onContentActiveChanged: {
88 if (contentActive && item) {
89 item.start()
90 } else if (!contentActive && item) {
91 item.stop()
92 }
93 }
95 width: menus.width
96 height: menus.height
97 sourceComponent: component
98 visible: content.__shown
99 onVisibleChanged: {
100 // Reset the indicator states
101 if (!visible && item) {
102 item.reset()
103 }
104 }
105 asynchronous: true
107 onStatusChanged: {
108 if (status == Loader.Ready) {
109 if (indicatorsModel.widgetsMap && item.hasOwnProperty("widgetsMap")) {
110 item["widgetsMap"] = indicatorsModel.widgetsMap
111 }
112 for(var pName in initialProperties) {
113 if (item.hasOwnProperty(pName)) {
114 item[pName] = initialProperties[pName]
115 }
116 }
117 if (contentActive && menus.visible) {
118 item.start()
119 }
120 }
121 }
123 // FIXME: QTBUG-30632 - asynchronous loader crashes when changing index quickly.
124 Component.onDestruction: {
125 active = false;
126 }
128 // Need to use a binding because the handle height changes.
129 // FIXME: Dont know why we're using handle height (introduces dep).. Check with design about bottom margin
130 Binding {
131 target: item
132 property: "anchors.bottomMargin"
133 value: handle.height
134 }
135 }
137 Behavior on opacity { NumberAnimation {duration: 200} }
138 }
140 Overview {
141 id: overview
142 objectName: "overview"
144 anchors.top: header.bottom
145 anchors.bottom: parent.bottom
146 // FIXME: Dont know why we're using handle height (introduces dep).. Check with design about bottom margin
147 anchors.bottomMargin: handle.height
149 width: content.width
150 indicatorsModel: content.indicatorsModel
151 enabled: content.overviewActive && content.__shown
152 opacity: content.overviewActive && content.__shown ? 1 : 0
153 Behavior on opacity {NumberAnimation{duration: 200}}
154 visible: opacity != 0
156 onMenuSelected: {
157 var storedDuration = menus.highlightMoveDuration
158 var storedVelocity = menus.highlightMoveVelocity
159 menus.highlightMoveDuration = 0
160 menus.highlightMoveVelocity = 100000
162 menus.currentIndex = modelIndex
163 content.overviewActive = false
165 menus.highlightMoveDuration = storedDuration
166 menus.highlightMoveVelocity = storedVelocity
168 content.menuSelected(modelIndex)
169 }
170 }
172 Rectangle {
173 id: header
174 objectName: "header"
176 property alias title: pageHeader.text
178 color: backgroundColor
179 opacity: pageHeader.opacity
180 anchors {
181 left: parent.left
182 right: parent.right
183 }
184 height: childrenRect.height
186 PageHeader {
187 id: pageHeader
188 anchors {
189 left: parent.left
190 right: parent.right
191 }
192 text: content.overviewActive ? i18n.tr("Device") : (indicatorsModel && menus.currentIndex >= 0 && menus.currentIndex < indicatorsModel.count) ? indicatorsModel.get(menus.currentIndex).title : ""
193 opacity: __shown ? 1 : 0
194 Behavior on opacity {NumberAnimation{duration: 100}}
195 }
196 }
198 Timer {
199 id: contentReleaseTimer
201 interval: contentReleaseInterval
202 onTriggered: __contentActive = false
203 }