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
53 property var blurSource : null
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 : theme.palette.normal.background
162 height: minimizedPanelHeight
164 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration } }
168 id: decorationMouseArea
169 objectName: "windowControlArea"
174 height: minimizedPanelHeight
175 hoverEnabled: !__indicators.shown
177 if (callHint.visible) {
178 callHint.showLiveCall();
183 if (!callHint.visible) {
184 // let it fall through to the window decoration of the maximized window behind, if any
185 mouse.accepted = false;
187 var menubar = menuBarLoader.item;
189 menubar.invokeMenu(mouse);
197 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
198 // cf. https://bugreports.qt.io/browse/QTBUG-32909
199 WindowControlButtons {
200 id: windowControlButtons
201 objectName: "panelWindowControlButtons"
202 height: indicators.minimizedPanelHeight
203 opacity: d.showWindowDecorationControls ? 1 : 0
204 visible: opacity != 0
205 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
207 active: panelState.decorationsVisible || panelState.decorationsAlwaysVisible
208 windowIsMaximized: true
209 onCloseClicked: panelState.closeClicked()
210 onMinimizeClicked: panelState.minimizeClicked()
211 onMaximizeClicked: panelState.restoreClicked()
212 closeButtonShown: panelState.closeButtonShown
217 objectName: "menuBarLoader"
218 height: parent.height
219 enabled: d.enablePointerMenu
220 opacity: d.showPointerMenu ? 1 : 0
221 visible: opacity != 0
222 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
223 active: d.showPointerMenu && !callHint.visible
225 width: parent.width - windowControlButtons.width - units.gu(2) - __indicators.barWidth
227 readonly property bool menusRequested: menuBarLoader.item ? menuBarLoader.item.showRequested : false
229 sourceComponent: MenuBar {
231 objectName: "menuBar"
232 anchors.left: menuBarLoader ? menuBarLoader.left : undefined
233 anchors.margins: units.gu(1)
234 height: menuBarLoader.height
235 enableKeyFilter: valid && panelState.decorationsVisible
236 lomiriMenuModel: __applicationMenus.model
237 panelState: root.panelState
240 target: __applicationMenus
241 onShownChanged: bar.dismiss();
246 onShownChanged: bar.dismiss();
249 onDoubleClicked: panelState.restoreClicked()
250 onPressed: mouse.accepted = false // let the parent mouse area handle this, so it can both unsnap window and show menu
257 objectName: "callHint"
259 anchors.centerIn: parent
260 height: minimizedPanelHeight
262 visible: active && indicators.state == "initial" && __applicationMenus.state == "initial"
263 greeterShown: root.greeterShown
268 id: __applicationMenus
271 model: registeredMenuModel.model
272 width: root.menuWidth
274 minimizedPanelHeight: root.minimizedPanelHeight
275 expandedPanelHeight: root.expandedPanelHeight
276 openedHeight: root.height
277 alignment: Qt.AlignLeft
278 enableHint: !callHint.active && !fullscreenMode
280 panelColor: panelAreaBackground.color
281 blurSource: root.blurSource
288 if (callHint.active) {
289 callHint.showLiveCall();
294 rowItemDelegate: ActionItem {
296 property int ownIndex: index
297 objectName: "appMenuItem"+index
298 enabled: model.sensitive
300 width: _title.width + units.gu(2)
301 height: parent.height
304 text: model.label.replace("_", "&")
309 anchors.centerIn: parent
310 text: actionItem.text
311 horizontalAlignment: Text.AlignLeft
312 color: enabled ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
316 pageDelegate: PanelMenuPage {
317 readonly property bool isCurrent: modelIndex == __applicationMenus.currentMenuIndex
318 onIsCurrentChanged: {
319 if (isCurrent && menuModel) {
320 menuModel.aboutToShow(modelIndex);
324 menuModel: __applicationMenus.model
325 submenuIndex: modelIndex
327 factory: ApplicationMenuItemFactory {
328 rootModel: __applicationMenus.model
332 enabled: d.enableTouchMenus
333 opacity: d.showTouchMenu ? 1 : 0
334 visible: opacity != 0
336 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
339 if (!enabled) hide();
347 leftMargin: units.gu(1)
348 right: __indicators.left
349 rightMargin: units.gu(1)
351 height: root.minimizedPanelHeight
357 right: root.partialWidth ? parent.right : parent.left
358 rightMargin: touchMenuIcon.width
360 objectName: "panelTitle"
361 height: root.minimizedPanelHeight
362 verticalAlignment: Text.AlignVCenter
363 elide: Text.ElideRight
366 font.weight: Font.Medium
367 color: theme.palette.selected.backgroundText
368 text: (root.partialWidth && !callHint.visible) ? panelState.title : ""
369 opacity: __applicationMenus.visible && !__applicationMenus.expanded
370 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
371 visible: opacity !== 0
376 objectName: "touchMenuIcon"
379 leftMargin: rowLabel.contentWidth + units.dp(2)
380 verticalCenter: parent.verticalCenter
385 color: theme.palette.normal.backgroundText
386 opacity: !__applicationMenus.expanded && d.enableTouchMenus && !callHint.visible
387 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
388 visible: opacity !== 0
394 objectName: "indicators"
400 width: root.menuWidth
401 minimizedPanelHeight: root.minimizedPanelHeight
402 expandedPanelHeight: root.expandedPanelHeight
403 openedHeight: root.height
405 overFlowWidth: width - appMenuClear
406 enableHint: !callHint.active && !fullscreenMode
407 showOnClick: !callHint.visible
408 panelColor: panelAreaBackground.color
409 blurSource: root.blurSource
415 // On small screens, the Indicators' handle area is the entire top
416 // bar unless there is an application menu. In that case, our handle
417 // needs to allow for some room to clear the application menu.
418 property var appMenuClear: (d.enableTouchMenus && !partialWidth) ? units.gu(7) : 0
421 if (callHint.active) {
422 callHint.showLiveCall();
426 rowItemDelegate: IndicatorItem {
428 objectName: identifier+"-panelItem"
430 property int ownIndex: index
431 readonly property bool overflow: parent.width - (x - __indicators.rowContentX) > __indicators.overFlowWidth
432 readonly property bool hidden: !expanded && (overflow || !indicatorVisible || hideSessionIndicator || hideKeyboardIndicator)
433 // HACK for indicator-session
434 readonly property bool hideSessionIndicator: identifier == "ayatana-indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
435 // HACK for indicator-keyboard
436 readonly property bool hideKeyboardIndicator: identifier == "ayatana-indicator-keyboard" && !hasKeyboard
438 height: parent.height
439 expanded: indicators.expanded
440 selected: ListView.isCurrentItem
442 identifier: model.identifier
443 busName: indicatorProperties.busName
444 actionsObjectPath: indicatorProperties.actionsObjectPath
445 menuObjectPath: indicatorProperties.menuObjectPath
447 opacity: hidden ? 0.0 : 1.0
448 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
450 width: ((expanded || indicatorVisible) && !hideSessionIndicator && !hideKeyboardIndicator) ? implicitWidth : 0
452 Behavior on width { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
455 pageDelegate: PanelMenuPage {
456 objectName: modelData.identifier + "-page"
459 menuModel: delegate.menuModel
461 factory: IndicatorMenuItemFactory {
463 var context = modelData.identifier;
464 if (context && context.indexOf("fake-") === 0) {
465 context = context.substring("fake-".length)
469 rootModel: delegate.menuModel
474 busName: modelData.indicatorProperties.busName
475 actionsObjectPath: modelData.indicatorProperties.actionsObjectPath
476 menuObjectPath: modelData.indicatorProperties.menuObjectPath
480 enabled: !applicationMenus.expanded
481 opacity: !callHint.visible && !applicationMenus.expanded ? 1 : 0
483 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
486 if (!enabled) hide();
493 supportsMultiColorLed: root.supportsMultiColorLed
498 name: "onscreen" //fully opaque and visible at top edge of screen
499 when: !fullscreenMode
507 name: "offscreen" //pushed off screen
512 if (indicators.state !== "initial") return 0;
513 if (applicationMenus.state !== "initial") return 0;
514 return -minimizedPanelHeight;
516 opacity: indicators.fullyClosed && applicationMenus.fullyClosed ? 0.0 : 1.0
519 target: indicators.showDragHandle;
520 anchors.bottomMargin: -units.gu(1)
523 target: applicationMenus.showDragHandle;
524 anchors.bottomMargin: -units.gu(1)
532 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }
536 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }