on dc654b4 help sign in
unity8/qml/Panel/Panel.qml
296 lines 8.7 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.Application 0.1
20import "../Components"
21import "../Components/ListItems"
23Item {
24 id: root
25 readonly property real panelHeight: nonIndicatorArea.y + nonIndicatorArea.height
26 property alias indicators: __indicators
27 property alias callHint: __callHint
28 property bool fullscreenMode: false
29 property bool searchVisible: true
31 signal searchClicked
33 function hideIndicatorMenu(delay) {
34 if (delay !== undefined) {
35 hideTimer.interval = delay;
36 hideTimer.start();
37 } else {
38 indicators.hide();
39 }
40 }
42 Timer {
43 id: hideTimer
44 running: false
45 onTriggered: {
46 indicators.hide();
47 }
48 }
50 Connections {
51 target: indicators
52 onShownChanged: hideTimer.stop()
53 }
55 Rectangle {
56 id: darkenedArea
57 property real darkenedOpacity: 0.6
58 anchors {
59 left: parent.left
60 right: parent.right
61 top: nonIndicatorArea.bottom
62 bottom: parent.bottom
63 }
64 color: "black"
65 opacity: indicators.unitProgress * darkenedOpacity
67 MouseArea {
68 anchors.fill: parent
69 enabled: indicators.shown
70 onClicked: if (indicators.fullyOpened) indicators.hide();
71 }
72 }
74 PanelBackground {
75 anchors.fill: nonIndicatorArea
76 }
78 Item {
79 id: nonIndicatorArea
80 objectName: "indicatorArea"
82 anchors {
83 top: callHint.bottom
84 left: parent.left
85 right: parent.right
86 }
87 height: d.indicatorHeight
89 PanelSeparatorLine {
90 id: leftSeparatorLine
91 anchors {
92 bottom: parent.bottom
93 left: parent.left
94 right: parent.right
95 }
96 saturation: 1 - indicators.unitProgress
97 }
99 MouseArea {
100 id: nonIndicatorMouseArea
101 enabled: callHint.active
102 anchors {
103 top: parent.top
104 left: parent.left
105 right: parent.right
106 }
107 height: indicators.panelHeight/2
108 onClicked: callHint.activate();
109 }
110 }
112 // eater
113 MouseArea {
114 anchors.fill: callHint
115 onClicked: callHint.activate()
116 }
118 Item {
119 id: indicatorArea
120 objectName: "indicatorArea"
122 anchors {
123 top: callHint.bottom
124 right: parent.right
125 bottom: parent.bottom
126 }
127 width: indicators.width
129 Behavior on anchors.topMargin { StandardAnimation {} }
131 BorderImage {
132 id: dropShadow
133 anchors {
134 fill: indicators
135 leftMargin: -units.gu(1)
136 bottomMargin: -units.gu(1)
137 }
138 visible: indicators.height > indicators.panelHeight
139 source: "graphics/rectangular_dropshadow.sci"
140 }
142 VerticalThinDivider {
143 id: indicatorDividor
144 anchors {
145 top: indicators.top
146 bottom: indicators.bottom
147 right: indicators.left
149 topMargin: nonIndicatorArea.anchors.topMargin + indicators.panelHeight
150 }
152 width: units.dp(2)
153 source: "graphics/VerticalDivider.png"
154 }
156 PanelBackground {
157 anchors.fill: indicators
158 }
160 Indicators {
161 id: __indicators
162 objectName: "indicators"
164 anchors {
165 top: parent.top
166 right: parent.right
167 }
169 width: (root.width > units.gu(60)) ? units.gu(40) : root.width
170 shown: false
171 panelHeight: units.gu(3)
172 openedHeight: root.height - (callHint.y + callHint.height)
173 overFlowWidth: search.state=="hidden" ? root.width : root.width - search.width
175 enableHint: !callHint.active && !fullscreenMode
176 showHintBottomMargin: fullscreenMode ? -panelHeight : 0
177 showHintHeightOffset: callHint.active ? callHint.height : 0
179 onShowTapped: {
180 if (callHint.active) {
181 var callHintScenePosition = callHint.mapToItem(null, callHint.x, callHint.y);
182 var indicatorScenePosition = mapToItem(null, x, y);
184 // tapped on callHint
185 if (position.y > callHintScenePosition.y && position.y <= callHintScenePosition.y + callHint.height) {
186 callHint.activate();
187 // tapped on top half of indicator
188 } else if (!fullscreenMode && position.y > indicatorScenePosition.y && position.y < indicatorScenePosition.y + panelHeight/2) {
189 callHint.activate();
190 }
191 }
192 }
193 }
195 PanelSeparatorLine {
196 id: indicatorsSeparatorLine
197 visible: true
198 anchors {
199 top: indicators.bottom
200 left: indicatorDividor.left
201 right: indicators.right
202 }
203 }
204 }
206 SearchIndicator {
207 id: search
208 objectName: "search"
209 enabled: root.searchVisible
211 state: {
212 if (parent.width < indicators.width + width) {
213 if (indicators.state != "initial") {
214 return "hidden";
215 }
216 }
217 if (root.searchVisible && !indicators.showAll) {
218 return "visible";
219 }
220 return "hidden";
221 }
223 anchors {
224 top: nonIndicatorArea.top
225 bottom: nonIndicatorArea.bottom
226 left: nonIndicatorArea.left
227 }
229 mouseArea {
230 onClicked: root.searchClicked()
231 }
232 }
234 ActiveCallHint {
235 id: __callHint
236 anchors {
237 left: parent.left
238 right: parent.right
239 }
240 height: units.gu(3)
241 y: -height
243 states: [
244 State {
245 name: "active"
246 when: callHint.active
247 PropertyChanges { target: callHint; y: 0 }
248 PropertyChanges { target: search.mouseArea; anchors.topMargin: -callHint.height/3 }
249 }
250 ]
251 Behavior on y { StandardAnimation {} }
252 }
254 QtObject {
255 id: d
256 readonly property real indicatorHeight: indicators.panelHeight + leftSeparatorLine.height
257 }
259 states: [
260 State {
261 name: "onscreen" //fully opaque and visible at top edge of screen
262 when: !fullscreenMode
263 },
264 State {
265 name: "offscreen" //pushed off screen
266 when: fullscreenMode
267 PropertyChanges { target: nonIndicatorArea; anchors.topMargin: -d.indicatorHeight }
268 PropertyChanges { target: indicatorArea; anchors.topMargin: indicators.state === "initial" ? -d.indicatorHeight : 0 }
269 }
270 ]
272 transitions: [
273 Transition {
274 to: "onscreen"
275 SequentialAnimation {
276 ParallelAnimation {
277 StandardAnimation { target: nonIndicatorArea; property: "anchors.topMargin" }
278 StandardAnimation { target: indicatorArea; property: "anchors.topMargin" }
279 }
280 PropertyAction { target: search; property: "z"; value: 2 }
281 PropertyAction { target: indicatorArea; property: "z"; value: 2 }
282 }
283 },
284 Transition {
285 to: "offscreen"
286 SequentialAnimation {
287 PropertyAction { target: search; property: "z"; value: 0 }
288 PropertyAction { target: indicatorArea; property: "z"; value: 0 }
289 ParallelAnimation {
290 StandardAnimation { target: nonIndicatorArea; property: "anchors.topMargin" }
291 StandardAnimation { target: indicatorArea; property: "anchors.topMargin" }
292 }
293 }
294 }
295 ]