on 4787a4f help sign in
unity8/Panel/MenuContent.qml
201 lines 6.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 "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: 20000
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 source: pageQml
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 for(var pName in indicatorProperties) {
110 if (item.hasOwnProperty(pName)) {
111 item[pName] = indicatorProperties[pName]
112 }
113 }
114 if (contentActive && menus.visible) {
115 item.start()
116 }
117 }
118 }
120 // FIXME: QTBUG-30632 - asynchronous loader crashes when changing index quickly.
121 Component.onDestruction: {
122 active = false;
123 }
125 // Need to use a binding because the handle height changes.
126 // FIXME: Dont know why we're using handle height (introduces dep).. Check with design about bottom margin
127 Binding {
128 target: item
129 property: "anchors.bottomMargin"
130 value: handle.height
131 }
132 }
134 Behavior on opacity { NumberAnimation {duration: 200} }
135 }
137 Overview {
138 id: overview
139 objectName: "overview"
141 anchors.top: header.bottom
142 anchors.bottom: parent.bottom
143 // FIXME: Dont know why we're using handle height (introduces dep).. Check with design about bottom margin
144 anchors.bottomMargin: handle.height
146 width: content.width
147 indicatorsModel: content.indicatorsModel
148 enabled: content.overviewActive && content.__shown
149 opacity: content.overviewActive && content.__shown ? 1 : 0
150 Behavior on opacity {NumberAnimation{duration: 200}}
151 visible: opacity != 0
153 onMenuSelected: {
154 var storedDuration = menus.highlightMoveDuration
155 var storedVelocity = menus.highlightMoveVelocity
156 menus.highlightMoveDuration = 0
157 menus.highlightMoveVelocity = 100000
159 menus.currentIndex = modelIndex
160 content.overviewActive = false
162 menus.highlightMoveDuration = storedDuration
163 menus.highlightMoveVelocity = storedVelocity
165 content.menuSelected(modelIndex)
166 }
167 }
169 Rectangle {
170 id: header
171 objectName: "header"
173 property alias title: pageHeader.text
175 color: backgroundColor
176 opacity: pageHeader.opacity
177 anchors {
178 left: parent.left
179 right: parent.right
180 }
181 height: childrenRect.height
183 PageHeader {
184 id: pageHeader
185 anchors {
186 left: parent.left
187 right: parent.right
188 }
189 text: content.overviewActive ? i18n.tr("Device") : (indicatorsModel && menus.currentIndex >= 0 && menus.currentIndex < indicatorsModel.count) ? indicatorsModel.get(menus.currentIndex).title : ""
190 opacity: __shown ? 1 : 0
191 Behavior on opacity {NumberAnimation{duration: 100}}
192 }
193 }
195 Timer {
196 id: contentReleaseTimer
198 interval: contentReleaseInterval
199 onTriggered: __contentActive = false
200 }