2 * Copyright (C) 2013-2017 Canonical, Ltd.
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.
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.
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/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Layouts 1.0
20 import Unity.Application 0.1
21 import Unity.Indicators 0.1
23 import Unity.ApplicationMenu 0.1
25 import QtQuick.Window 2.2
27 import "../ApplicationMenus"
28 import "../Components"
29 import "../Components/PanelState"
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
41 property alias applicationMenuContentX: __applicationMenus.menuContentX
43 property alias applicationMenus: __applicationMenus
44 property alias indicators: __indicators
45 property bool fullscreenMode: false
46 property real panelAreaShowProgress: 1.0
47 property bool greeterShown: false
48 property bool hasKeyboard: false
50 property string mode: "staged"
55 anchors.topMargin: panelHeight
56 visible: !indicators.fullyClosed || !applicationMenus.fullyClosed
58 hoverEnabled: true // should also eat hover events, otherwise they will pass through
61 __applicationMenus.hide();
68 property: "panelHeight"
69 value: minimizedPanelHeight
72 RegisteredApplicationMenuModel {
73 id: registeredMenuModel
74 persistentSurfaceId: PanelState.focusedPersistentSurfaceId
80 property bool revealControls: !greeterShown &&
81 !applicationMenus.shown &&
83 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
85 property bool showWindowDecorationControls: (revealControls && PanelState.decorationsVisible) ||
86 PanelState.decorationsAlwaysVisible
88 property bool showPointerMenu: revealControls && enablePointerMenu &&
89 (PanelState.decorationsVisible || mode == "staged")
91 property bool enablePointerMenu: applicationMenus.available &&
92 applicationMenus.model
94 property bool showTouchMenu: !greeterShown &&
96 !showWindowDecorationControls
98 property bool enableTouchMenus: showTouchMenu &&
99 applicationMenus.available &&
100 applicationMenus.model
105 objectName: "panelArea"
109 transform: Translate {
110 y: indicators.state === "initial"
111 ? (1.0 - panelAreaShowProgress) * - minimizedPanelHeight
116 id: indicatorsDropShadow
119 margins: -units.gu(1)
121 visible: !__indicators.fullyClosed
122 source: "graphics/rectangular_dropshadow.sci"
126 id: appmenuDropShadow
128 fill: __applicationMenus
129 margins: -units.gu(1)
131 visible: !__applicationMenus.fullyClosed
132 source: "graphics/rectangular_dropshadow.sci"
138 fill: panelAreaBackground
139 bottomMargin: -units.gu(1)
141 visible: PanelState.dropShadow
142 source: "graphics/rectangular_dropshadow.sci"
146 id: panelAreaBackground
147 color: callHint.visible ? theme.palette.normal.positive : theme.palette.normal.background
153 height: minimizedPanelHeight
155 Behavior on color { ColorAnimation { duration: UbuntuAnimation.FastDuration } }
159 id: decorationMouseArea
160 objectName: "windowControlArea"
165 height: minimizedPanelHeight
166 hoverEnabled: !__indicators.shown
168 if (callHint.visible) {
169 callHint.showLiveCall();
174 if (!callHint.visible) {
175 // let it fall through to the window decoration of the maximized window behind, if any
176 mouse.accepted = false;
178 var menubar = menuBarLoader.item;
180 menubar.invokeMenu(mouse);
188 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
189 // cf. https://bugreports.qt.io/browse/QTBUG-32909
190 WindowControlButtons {
191 id: windowControlButtons
192 objectName: "panelWindowControlButtons"
193 height: indicators.minimizedPanelHeight
194 opacity: d.showWindowDecorationControls ? 1 : 0
195 visible: opacity != 0
196 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
198 active: PanelState.decorationsVisible || PanelState.decorationsAlwaysVisible
199 windowIsMaximized: true
200 onCloseClicked: PanelState.closeClicked()
201 onMinimizeClicked: PanelState.minimizeClicked()
202 onMaximizeClicked: PanelState.restoreClicked()
203 closeButtonShown: PanelState.closeButtonShown
208 objectName: "menuBarLoader"
209 height: parent.height
210 enabled: d.enablePointerMenu
211 opacity: d.showPointerMenu ? 1 : 0
212 visible: opacity != 0
213 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
214 active: d.showPointerMenu && !callHint.visible
216 width: parent.width - windowControlButtons.width - units.gu(2) - __indicators.barWidth
218 readonly property bool menusRequested: menuBarLoader.item ? menuBarLoader.item.showRequested : false
220 sourceComponent: MenuBar {
222 objectName: "menuBar"
223 anchors.left: parent ? parent.left : undefined
224 anchors.margins: units.gu(1)
225 height: menuBarLoader.height
226 enableKeyFilter: valid && PanelState.decorationsVisible
227 unityMenuModel: __applicationMenus.model
230 target: __applicationMenus
231 onShownChanged: bar.dismiss();
236 onShownChanged: bar.dismiss();
239 onDoubleClicked: PanelState.restoreClicked()
240 onPressed: mouse.accepted = false // let the parent mouse area handle this, so it can both unsnap window and show menu
247 objectName: "callHint"
249 anchors.centerIn: parent
250 height: minimizedPanelHeight
252 visible: active && indicators.state == "initial" && __applicationMenus.state == "initial"
253 greeterShown: root.greeterShown
258 id: __applicationMenus
261 model: registeredMenuModel.model
262 width: root.applicationMenuWidth
263 minimizedPanelHeight: root.minimizedPanelHeight
264 expandedPanelHeight: root.expandedPanelHeight
265 openedHeight: root.height
266 alignment: Qt.AlignLeft
267 enableHint: !callHint.active && !fullscreenMode
269 adjustDragHandleSizeToContents: false
270 panelColor: panelAreaBackground.color
273 if (callHint.active) {
274 callHint.showLiveCall();
279 rowItemDelegate: ActionItem {
281 property int ownIndex: index
282 objectName: "appMenuItem"+index
283 enabled: model.sensitive
285 width: _title.width + units.gu(2)
286 height: parent.height
289 text: model.label.replace("_", "&")
294 anchors.centerIn: parent
295 text: actionItem.text
296 horizontalAlignment: Text.AlignLeft
297 color: enabled ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
301 pageDelegate: PanelMenuPage {
302 readonly property bool isCurrent: modelIndex == __applicationMenus.currentMenuIndex
303 onIsCurrentChanged: {
304 if (isCurrent && menuModel) {
305 menuModel.aboutToShow(modelIndex);
309 menuModel: __applicationMenus.model
310 submenuIndex: modelIndex
312 factory: ApplicationMenuItemFactory {
313 rootModel: __applicationMenus.model
317 enabled: d.enableTouchMenus
318 opacity: d.showTouchMenu ? 1 : 0
319 visible: opacity != 0
320 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
323 if (!enabled) hide();
329 objectName: "panelTitle"
332 leftMargin: units.gu(1)
333 right: __indicators.left
334 rightMargin: units.gu(1)
336 height: root.minimizedPanelHeight
337 verticalAlignment: Text.AlignVCenter
338 elide: Text.ElideRight
341 font.weight: Font.Medium
342 color: theme.palette.selected.backgroundText
343 opacity: __applicationMenus.visible && !__applicationMenus.expanded ? 1 : 0
344 visible: opacity != 0
345 Behavior on opacity { NumberAnimation { duration: UbuntuAnimation.SnapDuration } }
346 text: PanelState.title
351 objectName: "indicators"
357 width: root.indicatorMenuWidth
358 minimizedPanelHeight: root.minimizedPanelHeight
359 expandedPanelHeight: root.expandedPanelHeight
360 openedHeight: root.height
362 overFlowWidth: root.width
363 enableHint: !callHint.active && !fullscreenMode
364 showOnClick: !callHint.visible
365 panelColor: panelAreaBackground.color
368 if (callHint.active) {
369 callHint.showLiveCall();
373 rowItemDelegate: IndicatorItem {
375 objectName: identifier+"-panelItem"
377 property int ownIndex: index
378 readonly property bool overflow: parent.width - x > __indicators.overFlowWidth
379 readonly property bool hidden: !expanded && (overflow || !indicatorVisible || hideSessionIndicator || hideKeyboardIndicator)
380 // HACK for indicator-session
381 readonly property bool hideSessionIndicator: identifier == "indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
382 // HACK for indicator-keyboard
383 readonly property bool hideKeyboardIndicator: identifier == "indicator-keyboard" && !hasKeyboard
385 height: parent.height
386 expanded: indicators.expanded
387 selected: ListView.isCurrentItem
389 identifier: model.identifier
390 busName: indicatorProperties.busName
391 actionsObjectPath: indicatorProperties.actionsObjectPath
392 menuObjectPath: indicatorProperties.menuObjectPath
394 opacity: hidden ? 0.0 : 1.0
395 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
397 width: ((expanded || indicatorVisible) && !hideSessionIndicator && !hideKeyboardIndicator) ? implicitWidth : 0
399 Behavior on width { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
402 pageDelegate: PanelMenuPage {
403 objectName: modelData.identifier + "-page"
406 menuModel: delegate.menuModel
408 factory: IndicatorMenuItemFactory {
410 var context = modelData.identifier;
411 if (context && context.indexOf("fake-") === 0) {
412 context = context.substring("fake-".length)
416 rootModel: delegate.menuModel
421 busName: modelData.indicatorProperties.busName
422 actionsObjectPath: modelData.indicatorProperties.actionsObjectPath
423 menuObjectPath: modelData.indicatorProperties.menuObjectPath
427 enabled: !applicationMenus.expanded
428 opacity: !callHint.visible && !applicationMenus.expanded ? 1 : 0
429 Behavior on opacity { UbuntuNumberAnimation { duration: UbuntuAnimation.SnapDuration } }
432 if (!enabled) hide();
443 name: "onscreen" //fully opaque and visible at top edge of screen
444 when: !fullscreenMode
452 name: "offscreen" //pushed off screen
457 if (indicators.state !== "initial") return 0;
458 if (applicationMenus.state !== "initial") return 0;
459 return -minimizedPanelHeight;
461 opacity: indicators.fullyClosed && applicationMenus.fullyClosed ? 0.0 : 1.0
464 target: indicators.showDragHandle;
465 anchors.bottomMargin: -units.gu(1)
468 target: applicationMenus.showDragHandle;
469 anchors.bottomMargin: -units.gu(1)
477 UbuntuNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }
481 UbuntuNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }