2 * Copyright (C) 2013-2017 Canonical Ltd.
3 * Copyright (C) 2020 UBports Foundation
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19import Lomiri.Components 1.3
20import Lomiri.Layouts 1.0
21import QtMir.Application 0.1
22import Lomiri.Indicators 0.1
24import Lomiri.ApplicationMenu 0.1
26import QtQuick.Window 2.2
28import "../ApplicationMenus"
30import "../Components/PanelState"
37 readonly property real panelHeight: panelArea.y + minimizedPanelHeight
38 readonly property bool fullyClosed: indicators.fullyClosed && applicationMenus.fullyClosed
40 property real minimizedPanelHeight: units.gu(3)
41 property real expandedPanelHeight: units.gu(7)
42 property real menuWidth: partialWidth ? units.gu(40) : width
43 property alias applicationMenuContentX: __applicationMenus.menuContentX
45 property alias applicationMenus: __applicationMenus
46 property alias indicators: __indicators
47 property bool fullscreenMode: false
48 property real panelAreaShowProgress: 1.0
49 property bool greeterShown: false
50 property bool hasKeyboard: false
51 property bool supportsMultiColorLed: true
52 property var blurSource : null
53 property bool lightMode : false
55 // Whether our expanded menus should take up the full width of the panel
56 property bool partialWidth: width >= units.gu(60)
58 property string mode: "staged"
59 property PanelState panelState
64 anchors.topMargin: panelHeight
65 visible: !indicators.fullyClosed || !applicationMenus.fullyClosed
67 hoverEnabled: true // should also eat hover events, otherwise they will pass through
70 __applicationMenus.hide();
77 property: "panelHeight"
78 value: minimizedPanelHeight
81 RegisteredApplicationMenuModel {
82 id: registeredMenuModel
83 persistentSurfaceId: panelState.focusedPersistentSurfaceId
89 property bool revealControls: !greeterShown &&
90 !applicationMenus.shown &&
92 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
94 property bool showWindowDecorationControls: (revealControls && panelState.decorationsVisible) ||
95 panelState.decorationsAlwaysVisible
97 property bool showPointerMenu: revealControls &&
98 (panelState.decorationsVisible || mode == "windowed")
100 property bool enablePointerMenu: applicationMenus.available &&
101 applicationMenus.model
103 property bool showTouchMenu: !greeterShown &&
105 !showWindowDecorationControls
107 property bool enableTouchMenus: showTouchMenu &&
108 applicationMenus.available &&
109 applicationMenus.model
114 objectName: "panelArea"
118 transform: Translate {
119 y: indicators.state === "initial"
120 ? (1.0 - panelAreaShowProgress) * - minimizedPanelHeight
125 id: indicatorsDropShadow
128 margins: -units.gu(1)
130 visible: !__indicators.fullyClosed
131 source: "graphics/rectangular_dropshadow.sci"
135 id: appmenuDropShadow
137 fill: __applicationMenus
138 margins: -units.gu(1)
140 visible: !__applicationMenus.fullyClosed
141 source: "graphics/rectangular_dropshadow.sci"
147 fill: panelAreaBackground
148 bottomMargin: -units.gu(1)
150 visible: panelState.dropShadow
151 source: "graphics/rectangular_dropshadow.sci"
155 id: panelAreaBackground
156 color: callHint.visible ? theme.palette.normal.activity :
157 (root.lightMode ? "#FFFFFF" : "#000000")
163 height: minimizedPanelHeight
165 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration } }
169 id: decorationMouseArea
170 objectName: "windowControlArea"
175 height: minimizedPanelHeight
176 hoverEnabled: !__indicators.shown
178 if (callHint.visible) {
179 callHint.showLiveCall();
184 if (!callHint.visible) {
185 // let it fall through to the window decoration of the maximized window behind, if any
186 mouse.accepted = false;
188 var menubar = menuBarLoader.item;
190 menubar.invokeMenu(mouse);
198 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
199 // cf. https://bugreports.qt.io/browse/QTBUG-32909
200 WindowControlButtons {
201 id: windowControlButtons
202 objectName: "panelWindowControlButtons"
203 height: indicators.minimizedPanelHeight
204 opacity: d.showWindowDecorationControls ? 1 : 0
205 visible: opacity != 0
206 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
208 active: panelState.decorationsVisible || panelState.decorationsAlwaysVisible
209 windowIsMaximized: true
210 onCloseClicked: panelState.closeClicked()
211 onMinimizeClicked: panelState.minimizeClicked()
212 onMaximizeClicked: panelState.restoreClicked()
213 closeButtonShown: panelState.closeButtonShown
218 objectName: "menuBarLoader"
219 height: parent.height
220 enabled: d.enablePointerMenu
221 opacity: d.showPointerMenu ? 1 : 0
222 visible: opacity != 0
223 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
224 active: d.showPointerMenu && !callHint.visible
226 width: parent.width - windowControlButtons.width - units.gu(2) - __indicators.barWidth
228 readonly property bool menusRequested: menuBarLoader.item ? menuBarLoader.item.showRequested : false
230 sourceComponent: MenuBar {
232 objectName: "menuBar"
233 anchors.left: menuBarLoader ? menuBarLoader.left : undefined
234 anchors.margins: units.gu(1)
235 height: menuBarLoader.height
236 enableKeyFilter: valid && panelState.decorationsVisible
237 lomiriMenuModel: __applicationMenus.model
238 panelState: root.panelState
241 target: __applicationMenus
242 onShownChanged: bar.dismiss();
247 onShownChanged: bar.dismiss();
250 onDoubleClicked: panelState.restoreClicked()
251 onPressed: mouse.accepted = false // let the parent mouse area handle this, so it can both unsnap window and show menu
258 objectName: "callHint"
260 anchors.centerIn: parent
261 height: minimizedPanelHeight
263 visible: active && indicators.state == "initial" && __applicationMenus.state == "initial"
264 greeterShown: root.greeterShown
269 id: __applicationMenus
272 model: registeredMenuModel.model
273 width: root.menuWidth
275 minimizedPanelHeight: root.minimizedPanelHeight
276 expandedPanelHeight: root.expandedPanelHeight
277 openedHeight: root.height
278 alignment: Qt.AlignLeft
279 enableHint: !callHint.active && !fullscreenMode
281 panelColor: panelAreaBackground.color
282 blurSource: root.blurSource
287 lightMode: root.lightMode
290 if (callHint.active) {
291 callHint.showLiveCall();
296 rowItemDelegate: ActionItem {
298 property int ownIndex: index
299 objectName: "appMenuItem"+index
300 enabled: model.sensitive
302 width: _title.width + units.gu(2)
303 height: parent.height
306 text: model.label.replace("_", "&")
311 anchors.centerIn: parent
312 text: actionItem.text
313 horizontalAlignment: Text.AlignLeft
314 color: enabled ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
318 pageDelegate: PanelMenuPage {
319 readonly property bool isCurrent: modelIndex == __applicationMenus.currentMenuIndex
320 onIsCurrentChanged: {
321 if (isCurrent && menuModel) {
322 menuModel.aboutToShow(modelIndex);
326 menuModel: __applicationMenus.model
327 submenuIndex: modelIndex
329 factory: ApplicationMenuItemFactory {
330 rootModel: __applicationMenus.model
334 enabled: d.enableTouchMenus
335 opacity: d.showTouchMenu ? 1 : 0
336 visible: opacity != 0
338 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
341 if (!enabled) hide();
349 leftMargin: units.gu(1)
350 right: __indicators.left
351 rightMargin: units.gu(1)
353 height: root.minimizedPanelHeight
359 right: root.partialWidth ? parent.right : parent.left
360 rightMargin: touchMenuIcon.width
362 objectName: "panelTitle"
363 height: root.minimizedPanelHeight
364 verticalAlignment: Text.AlignVCenter
365 elide: Text.ElideRight
368 font.weight: Font.Medium
369 color: theme.palette.selected.backgroundText
370 text: (root.partialWidth && !callHint.visible) ? panelState.title : ""
371 opacity: __applicationMenus.visible && !__applicationMenus.expanded
372 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
373 visible: opacity !== 0
378 objectName: "touchMenuIcon"
381 leftMargin: rowLabel.contentWidth + units.dp(2)
382 verticalCenter: parent.verticalCenter
387 color: theme.palette.normal.backgroundText
388 opacity: !__applicationMenus.expanded && d.enableTouchMenus && !callHint.visible
389 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
390 visible: opacity !== 0
396 objectName: "indicators"
402 width: root.menuWidth
403 minimizedPanelHeight: root.minimizedPanelHeight
404 expandedPanelHeight: root.expandedPanelHeight
405 openedHeight: root.height
407 overFlowWidth: width - appMenuClear
408 enableHint: !callHint.active && !fullscreenMode
409 showOnClick: !callHint.visible
410 panelColor: panelAreaBackground.color
411 blurSource: root.blurSource
417 // On small screens, the Indicators' handle area is the entire top
418 // bar unless there is an application menu. In that case, our handle
419 // needs to allow for some room to clear the application menu.
420 property var appMenuClear: (d.enableTouchMenus && !partialWidth) ? units.gu(7) : 0
423 if (callHint.active) {
424 callHint.showLiveCall();
428 rowItemDelegate: IndicatorItem {
430 objectName: identifier+"-panelItem"
432 property int ownIndex: index
433 readonly property bool overflow: parent.width - (x - __indicators.rowContentX) > __indicators.overFlowWidth
434 readonly property bool hidden: !expanded && (overflow || !indicatorVisible || hideSessionIndicator || hideKeyboardIndicator)
435 // HACK for indicator-session
436 readonly property bool hideSessionIndicator: identifier == "ayatana-indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
437 // HACK for indicator-keyboard
438 readonly property bool hideKeyboardIndicator: identifier == "ayatana-indicator-keyboard" && !hasKeyboard
440 height: parent.height
441 expanded: indicators.expanded
442 selected: ListView.isCurrentItem
444 identifier: model.identifier
445 busName: indicatorProperties.busName
446 actionsObjectPath: indicatorProperties.actionsObjectPath
447 menuObjectPath: indicatorProperties.menuObjectPath
449 opacity: hidden ? 0.0 : 1.0
450 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
452 width: ((expanded || indicatorVisible) && !hideSessionIndicator && !hideKeyboardIndicator) ? implicitWidth : 0
454 Behavior on width { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
457 pageDelegate: PanelMenuPage {
458 objectName: modelData.identifier + "-page"
461 menuModel: delegate.menuModel
463 factory: IndicatorMenuItemFactory {
465 var context = modelData.identifier;
466 if (context && context.indexOf("fake-") === 0) {
467 context = context.substring("fake-".length)
471 rootModel: delegate.menuModel
476 busName: modelData.indicatorProperties.busName
477 actionsObjectPath: modelData.indicatorProperties.actionsObjectPath
478 menuObjectPath: modelData.indicatorProperties.menuObjectPath
482 enabled: !applicationMenus.expanded
483 opacity: !callHint.visible && !applicationMenus.expanded ? 1 : 0
485 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
488 if (!enabled) hide();
495 supportsMultiColorLed: root.supportsMultiColorLed
500 name: "onscreen" //fully opaque and visible at top edge of screen
501 when: !fullscreenMode
509 name: "offscreen" //pushed off screen
514 if (indicators.state !== "initial") return 0;
515 if (applicationMenus.state !== "initial") return 0;
516 return -minimizedPanelHeight;
518 opacity: indicators.fullyClosed && applicationMenus.fullyClosed ? 0.0 : 1.0
521 target: indicators.showDragHandle;
522 anchors.bottomMargin: -units.gu(1)
525 target: applicationMenus.showDragHandle;
526 anchors.bottomMargin: -units.gu(1)
534 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }
538 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }