on 3f5d08f 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 Unity.Indicators 0.1 as Indicators
20import "Menus"
21import "../Components"
23Rectangle {
24 id: content
26 property QtObject indicatorsModel: null
27 property bool animate: true // FIXME: Remove. This doesnt seem to be being used and it's referenced in Indicators.
28 property bool overviewActive: true // "state of the menu"
29 property bool __shown: false
30 property bool __contentActive: false
31 property alias currentIndex : menus.currentIndex
32 property color backgroundColor: "#221e1c"
33 property int contentReleaseInterval: 20000
35 width: units.gu(40)
36 height: units.gu(42)
37 color: backgroundColor
38 enabled: __shown
40 signal menuSelected(int index)
42 function showMenu() {
43 __shown = true
44 overviewActive = false
45 }
47 function showOverview() {
48 __shown = true
49 overviewActive = true
50 }
52 function hideAll() {
53 __shown = false
54 }
56 function activateContent() {
57 contentReleaseTimer.stop()
58 __contentActive = true
59 }
61 function releaseContent() {
62 if (__contentActive)
63 contentReleaseTimer.restart()
64 }
66 ListView {
67 id: menus
68 objectName: "menus"
70 anchors.bottom: parent.bottom
71 anchors.top: header.bottom
72 width: parent.width
74 spacing: units.gu(0.5)
75 opacity: !overviewActive && __shown ? 1 : 0
76 enabled: opacity != 0
77 orientation: ListView.Horizontal
78 model: indicatorsModel
79 interactive: false
80 //FIXME: This will make sure that all plugins still alive
81 //check bug https://bugs.launchpad.net/manhattan/+bug/1088945 for more details
82 cacheBuffer: 2147483647
84 delegate: Loader {
85 clip: true
86 property bool contentActive: content.__contentActive
88 onContentActiveChanged: {
89 if (contentActive && item) {
90 item.start()
91 } else if (!contentActive && item) {
92 item.stop()
93 }
94 }
96 width: menus.width
97 height: menus.height
98 source: pageSource
99 visible: content.__shown
100 onVisibleChanged: {
101 // Reset the indicator states
102 if (!visible && item && item["reset"]) {
103 item.reset()
104 }
105 }
106 asynchronous: true
108 onLoaded: {
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 }
119 // Need to use a binding because the handle height changes.
120 // FIXME: Dont know why we're using handle height (introduces dep).. Check with design about bottom margin
121 Binding {
122 target: item
123 property: "anchors.bottomMargin"
124 value: handle.height
125 }
126 }
128 Behavior on opacity { NumberAnimation {duration: 200} }
129 }
131 Overview {
132 id: overview
133 objectName: "overview"
135 anchors.top: header.bottom
136 anchors.bottom: parent.bottom
137 // FIXME: Dont know why we're using handle height (introduces dep).. Check with design about bottom margin
138 anchors.bottomMargin: handle.height
140 width: content.width
141 indicatorsModel: content.indicatorsModel
142 enabled: content.overviewActive && content.__shown
143 opacity: content.overviewActive && content.__shown ? 1 : 0
144 Behavior on opacity {NumberAnimation{duration: 200}}
145 visible: opacity != 0
147 onMenuSelected: {
148 var storedDuration = menus.highlightMoveDuration
149 var storedVelocity = menus.highlightMoveVelocity
150 menus.highlightMoveDuration = 0
151 menus.highlightMoveVelocity = 100000
153 menus.currentIndex = modelIndex
154 content.overviewActive = false
156 menus.highlightMoveDuration = storedDuration
157 menus.highlightMoveVelocity = storedVelocity
159 content.menuSelected(modelIndex)
160 }
161 }
163 Rectangle {
164 id: header
165 objectName: "header"
167 property alias title: pageHeader.text
169 color: backgroundColor
170 opacity: pageHeader.opacity
171 anchors {
172 left: parent.left
173 right: parent.right
174 }
175 height: childrenRect.height
177 PageHeader {
178 id: pageHeader
179 anchors {
180 left: parent.left
181 right: parent.right
182 }
183 text: {
184 if (content.overviewActive)
185 return i18n.tr("Device");
186 if (indicatorsModel && menus.currentIndex >= 0 && menus.currentIndex < indicatorsModel.count)
187 return indicatorsModel.data(menus.currentIndex, Indicators.IndicatorsModelRole.Title);
188 return "";
189 }
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 }