on 4792915 help sign in
unity8/qml/Panel/Panel.qml
452 lines 16 kB history raw
1/*
2 * Copyright (C) 2013-2017 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.4
18import Ubuntu.Components 1.3
19import Ubuntu.Layouts 1.0
20import Unity.Application 0.1
21import Unity.Indicators 0.1
22import Utils 0.1
23import Unity.ApplicationMenu 0.1
25import QtQuick.Window 2.2
27import "../ApplicationMenus"
28import "../Components"
29import "../Components/PanelState"
30import ".."
31import "Indicators"
33Item {
34 id: root
35 readonly property real panelHeight: panelArea.y + minimizedPanelHeight
37 property real minimizedPanelHeight: units.gu(3)
38 property real expandedPanelHeight: units.gu(7)
39 property real indicatorMenuWidth: width
40 property real applicationMenuWidth: width
42 property alias applicationMenus: __applicationMenus
43 property alias indicators: __indicators
44 property bool fullscreenMode: false
45 property real panelAreaShowProgress: 1.0
46 property bool greeterShown: false
47 property bool hasKeyboard: false
49 property string mode: "staged"
51 MouseArea {
52 id: backMouseEater
53 anchors.fill: parent
54 anchors.topMargin: panelHeight
55 visible: !indicators.fullyClosed || !applicationMenus.fullyClosed
56 enabled: visible
57 hoverEnabled: true // should also eat hover events, otherwise they will pass through
59 onClicked: {
60 __applicationMenus.hide();
61 __indicators.hide();
62 }
63 }
65 Binding {
66 target: PanelState
67 property: "panelHeight"
68 value: minimizedPanelHeight
69 }
71 RegisteredApplicationMenuModel {
72 id: registeredMenuModel
73 persistentSurfaceId: PanelState.focusedPersistentSurfaceId
74 }
76 QtObject {
77 id: d
79 property bool revealControls: !greeterShown &&
80 !applicationMenus.shown &&
81 !indicators.shown &&
82 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
84 property bool showWindowDecorationControls: (revealControls && PanelState.decorationsVisible) ||
85 PanelState.decorationsAlwaysVisible
87 property bool showPointerMenu: revealControls && enablePointerMenu &&
88 (PanelState.decorationsVisible || mode == "staged")
90 property bool enablePointerMenu: applicationMenus.available &&
91 applicationMenus.model
93 property bool showTouchMenu: !greeterShown &&
94 !showPointerMenu &&
95 !showWindowDecorationControls
97 property bool enableTouchMenus: showTouchMenu &&
98 applicationMenus.available &&
99 applicationMenus.model
100 }
102 Item {
103 id: panelArea
104 objectName: "panelArea"
106 anchors.fill: parent
108 transform: Translate {
109 y: indicators.state === "initial"
110 ? (1.0 - panelAreaShowProgress) * - minimizedPanelHeight
111 : 0
112 }
114 BorderImage {
115 id: indicatorsDropShadow
116 anchors {
117 fill: __indicators
118 margins: -units.gu(1)
119 }
120 visible: !__indicators.fullyClosed
121 source: "graphics/rectangular_dropshadow.sci"
122 }
124 BorderImage {
125 id: appmenuDropShadow
126 anchors {
127 fill: __applicationMenus
128 margins: -units.gu(1)
129 }
130 visible: !__applicationMenus.fullyClosed
131 source: "graphics/rectangular_dropshadow.sci"
132 }
134 BorderImage {
135 id: panelDropShadow
136 anchors {
137 fill: panelAreaBackground
138 bottomMargin: -units.gu(1)
139 }
140 visible: PanelState.dropShadow
141 source: "graphics/rectangular_dropshadow.sci"
142 }
144 Rectangle {
145 id: panelAreaBackground
146 color: callHint.visible ? theme.palette.normal.positive : theme.palette.normal.background
147 anchors {
148 top: parent.top
149 left: parent.left
150 right: parent.right
151 }
152 height: minimizedPanelHeight
154 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration } }
155 }
157 MouseArea {
158 id: decorationMouseArea
159 objectName: "windowControlArea"
160 anchors {
161 left: parent.left
162 right: parent.right
163 }
164 height: minimizedPanelHeight
165 hoverEnabled: !__indicators.shown
166 onClicked: {
167 if (callHint.visible) {
168 callHint.showLiveCall();
169 }
170 }
172 onPressed: {
173 if (!callHint.visible) {
174 // let it fall through to the window decoration of the maximized window behind, if any
175 mouse.accepted = false;
176 }
177 var menubar = menuBarLoader.item;
178 if (menubar) {
179 menubar.invokeMenu(mouse);
180 }
181 }
183 Row {
184 anchors.fill: parent
185 spacing: units.gu(2)
187 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
188 // cf. https://bugreports.qt.io/browse/QTBUG-32909
189 WindowControlButtons {
190 id: windowControlButtons
191 objectName: "panelWindowControlButtons"
192 height: indicators.minimizedPanelHeight
193 opacity: d.showWindowDecorationControls ? 1 : 0
194 visible: opacity != 0
195 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
197 active: PanelState.decorationsVisible || PanelState.decorationsAlwaysVisible
198 windowIsMaximized: true
199 onCloseClicked: PanelState.closeClicked()
200 onMinimizeClicked: PanelState.minimizeClicked()
201 onMaximizeClicked: PanelState.restoreClicked()
202 closeButtonShown: PanelState.closeButtonShown
203 }
205 Loader {
206 id: menuBarLoader
207 objectName: "menuBarLoader"
208 height: parent.height
209 enabled: d.enablePointerMenu
210 opacity: d.showPointerMenu ? 1 : 0
211 visible: opacity != 0
212 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
213 active: d.showPointerMenu && !callHint.visible
215 width: parent.width - windowControlButtons.width - units.gu(2) - __indicators.barWidth
217 readonly property bool menusRequested: menuBarLoader.item ? menuBarLoader.item.showRequested : false
219 sourceComponent: MenuBar {
220 id: bar
221 objectName: "menuBar"
222 anchors.left: parent.left
223 anchors.margins: units.gu(1)
224 height: menuBarLoader.height
225 enableKeyFilter: valid && PanelState.decorationsVisible
226 unityMenuModel: __applicationMenus.model
228 Connections {
229 target: __applicationMenus
230 onShownChanged: bar.dismiss();
231 }
233 Connections {
234 target: __indicators
235 onShownChanged: bar.dismiss();
236 }
238 onDoubleClicked: PanelState.restoreClicked()
239 onPressed: mouse.accepted = false // let the parent mouse area handle this, so it can both unsnap window and show menu
240 }
241 }
242 }
244 ActiveCallHint {
245 id: callHint
246 objectName: "callHint"
248 anchors.centerIn: parent
249 height: minimizedPanelHeight
251 visible: active && indicators.state == "initial" && __applicationMenus.state == "initial"
252 greeterShown: root.greeterShown
253 }
254 }
256 PanelMenu {
257 id: __applicationMenus
259 model: registeredMenuModel.model
260 width: root.applicationMenuWidth
261 minimizedPanelHeight: root.minimizedPanelHeight
262 expandedPanelHeight: root.expandedPanelHeight
263 openedHeight: root.height
264 alignment: Qt.AlignLeft
265 enableHint: !callHint.active && !fullscreenMode
266 showOnClick: false
267 panelColor: panelAreaBackground.color
269 onShowTapped: {
270 if (callHint.active) {
271 callHint.showLiveCall();
272 }
273 }
275 showRowTitle: !expanded
276 rowTitle: PanelState.title
277 rowItemDelegate: ActionItem {
278 id: actionItem
279 property int ownIndex: index
280 objectName: "appMenuItem"+index
282 width: _title.width + units.gu(2)
283 height: parent.height
285 action: Action {
286 text: model.label.replace("_", "&")
287 }
289 Label {
290 id: _title
291 anchors.centerIn: parent
292 text: actionItem.text
293 horizontalAlignment: Text.AlignLeft
294 color: enabled ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
295 }
296 }
298 pageDelegate: PanelMenuPage {
299 menuModel: __applicationMenus.model
300 submenuIndex: modelIndex
302 factory: ApplicationMenuItemFactory {
303 rootModel: __applicationMenus.model
304 }
305 }
307 enabled: d.enableTouchMenus
308 opacity: d.showTouchMenu ? 1 : 0
309 visible: opacity != 0
310 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
312 onEnabledChanged: {
313 if (!enabled) hide();
314 }
315 }
317 PanelMenu {
318 id: __indicators
319 objectName: "indicators"
321 anchors {
322 top: parent.top
323 right: parent.right
324 }
325 width: root.indicatorMenuWidth
326 minimizedPanelHeight: root.minimizedPanelHeight
327 expandedPanelHeight: root.expandedPanelHeight
328 openedHeight: root.height
330 overFlowWidth: root.width
331 enableHint: !callHint.active && !fullscreenMode
332 showOnClick: !callHint.visible
333 panelColor: panelAreaBackground.color
335 onShowTapped: {
336 if (callHint.active) {
337 callHint.showLiveCall();
338 }
339 }
341 rowItemDelegate: IndicatorItem {
342 id: indicatorItem
343 objectName: identifier+"-panelItem"
345 property int ownIndex: index
346 readonly property bool overflow: parent.width - x > __indicators.overFlowWidth
347 readonly property bool hidden: !expanded && (overflow || !indicatorVisible || hideSessionIndicator || hideKeyboardIndicator)
348 // HACK for indicator-session
349 readonly property bool hideSessionIndicator: identifier == "indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
350 // HACK for indicator-keyboard
351 readonly property bool hideKeyboardIndicator: identifier == "indicator-keyboard" && !hasKeyboard
353 height: parent.height
354 expanded: indicators.expanded
355 selected: ListView.isCurrentItem
357 identifier: model.identifier
358 busName: indicatorProperties.busName
359 actionsObjectPath: indicatorProperties.actionsObjectPath
360 menuObjectPath: indicatorProperties.menuObjectPath
362 opacity: hidden ? 0.0 : 1.0
363 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
365 width: ((expanded || indicatorVisible) && !hideSessionIndicator && !hideKeyboardIndicator) ? implicitWidth : 0
367 Behavior on width { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
368 }
370 pageDelegate: PanelMenuPage {
371 objectName: modelData.identifier + "-page"
372 submenuIndex: 0
374 menuModel: delegate.menuModel
376 factory: IndicatorMenuItemFactory {
377 indicator: {
378 var context = modelData.identifier;
379 if (context && context.indexOf("fake-") === 0) {
380 context = context.substring("fake-".length)
381 }
382 return context;
383 }
384 rootModel: delegate.menuModel
385 }
387 IndicatorDelegate {
388 id: delegate
389 busName: modelData.indicatorProperties.busName
390 actionsObjectPath: modelData.indicatorProperties.actionsObjectPath
391 menuObjectPath: modelData.indicatorProperties.menuObjectPath
392 }
393 }
395 enabled: !applicationMenus.expanded
396 opacity: !callHint.visible && !applicationMenus.expanded ? 1 : 0
397 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
399 onEnabledChanged: {
400 if (!enabled) hide();
401 }
402 }
403 }
405 IndicatorsLight {
406 id: indicatorLights
407 }
409 states: [
410 State {
411 name: "onscreen" //fully opaque and visible at top edge of screen
412 when: !fullscreenMode
413 PropertyChanges {
414 target: panelArea;
415 anchors.topMargin: 0
416 opacity: 1;
417 }
418 },
419 State {
420 name: "offscreen" //pushed off screen
421 when: fullscreenMode
422 PropertyChanges {
423 target: panelArea;
424 anchors.topMargin: {
425 if (indicators.state !== "initial") return 0;
426 if (applicationMenus.state !== "initial") return 0;
427 return -minimizedPanelHeight;
428 }
429 opacity: indicators.fullyClosed && applicationMenus.fullyClosed ? 0.0 : 1.0
430 }
431 PropertyChanges {
432 target: indicators.showDragHandle;
433 anchors.bottomMargin: -units.gu(1)
434 }
435 PropertyChanges {
436 target: applicationMenus.showDragHandle;
437 anchors.bottomMargin: -units.gu(1)
438 }
439 }
440 ]
442 transitions: [
443 Transition {
444 to: "onscreen"
445 UbuntuNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }
446 },
447 Transition {
448 to: "offscreen"
449 UbuntuNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }
450 }
451 ]