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"
36 readonly property real panelHeight: panelArea.y + minimizedPanelHeight
37 readonly property bool fullyClosed: indicators.fullyClosed && applicationMenus.fullyClosed
39 property real minimizedPanelHeight: units.gu(3)
40 property real expandedPanelHeight: units.gu(7)
41 property real menuWidth: partialWidth ? units.gu(40) : width
42 property alias applicationMenuContentX: __applicationMenus.menuContentX
44 property alias applicationMenus: __applicationMenus
45 property alias indicators: __indicators
46 property bool fullscreenMode: false
47 property real panelAreaShowProgress: 1.0
48 property bool greeterShown: false
49 property bool hasKeyboard: false
50 property bool supportsMultiColorLed: true
52 // Whether our expanded menus should take up the full width of the panel
53 property bool partialWidth: width >= units.gu(60)
55 property string mode: "staged"
56 property PanelState panelState
61 anchors.topMargin: panelHeight
62 visible: !indicators.fullyClosed || !applicationMenus.fullyClosed
64 hoverEnabled: true // should also eat hover events, otherwise they will pass through
67 __applicationMenus.hide();
74 property: "panelHeight"
75 value: minimizedPanelHeight
78 RegisteredApplicationMenuModel {
79 id: registeredMenuModel
80 persistentSurfaceId: panelState.focusedPersistentSurfaceId
86 property bool revealControls: !greeterShown &&
87 !applicationMenus.shown &&
89 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
91 property bool showWindowDecorationControls: (revealControls && panelState.decorationsVisible) ||
92 panelState.decorationsAlwaysVisible
94 property bool showPointerMenu: revealControls &&
95 (panelState.decorationsVisible || mode == "windowed")
97 property bool enablePointerMenu: applicationMenus.available &&
98 applicationMenus.model
100 property bool showTouchMenu: !greeterShown &&
102 !showWindowDecorationControls
104 property bool enableTouchMenus: showTouchMenu &&
105 applicationMenus.available &&
106 applicationMenus.model
111 objectName: "panelArea"
115 transform: Translate {
116 y: indicators.state === "initial"
117 ? (1.0 - panelAreaShowProgress) * - minimizedPanelHeight
122 id: indicatorsDropShadow
125 margins: -units.gu(1)
127 visible: !__indicators.fullyClosed
128 source: "graphics/rectangular_dropshadow.sci"
132 id: appmenuDropShadow
134 fill: __applicationMenus
135 margins: -units.gu(1)
137 visible: !__applicationMenus.fullyClosed
138 source: "graphics/rectangular_dropshadow.sci"
144 fill: panelAreaBackground
145 bottomMargin: -units.gu(1)
147 visible: panelState.dropShadow
148 source: "graphics/rectangular_dropshadow.sci"
152 id: panelAreaBackground
153 color: callHint.visible ? theme.palette.normal.activity : theme.palette.normal.background
159 height: minimizedPanelHeight
161 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration } }
165 id: decorationMouseArea
166 objectName: "windowControlArea"
171 height: minimizedPanelHeight
172 hoverEnabled: !__indicators.shown
174 if (callHint.visible) {
175 callHint.showLiveCall();
180 if (!callHint.visible) {
181 // let it fall through to the window decoration of the maximized window behind, if any
182 mouse.accepted = false;
184 var menubar = menuBarLoader.item;
186 menubar.invokeMenu(mouse);
194 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
195 // cf. https://bugreports.qt.io/browse/QTBUG-32909
196 WindowControlButtons {
197 id: windowControlButtons
198 objectName: "panelWindowControlButtons"
199 height: indicators.minimizedPanelHeight
200 opacity: d.showWindowDecorationControls ? 1 : 0
201 visible: opacity != 0
202 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
204 active: panelState.decorationsVisible || panelState.decorationsAlwaysVisible
205 windowIsMaximized: true
206 onCloseClicked: panelState.closeClicked()
207 onMinimizeClicked: panelState.minimizeClicked()
208 onMaximizeClicked: panelState.restoreClicked()
209 closeButtonShown: panelState.closeButtonShown
214 objectName: "menuBarLoader"
215 height: parent.height
216 enabled: d.enablePointerMenu
217 opacity: d.showPointerMenu ? 1 : 0
218 visible: opacity != 0
219 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
220 active: d.showPointerMenu && !callHint.visible
222 width: parent.width - windowControlButtons.width - units.gu(2) - __indicators.barWidth
224 readonly property bool menusRequested: menuBarLoader.item ? menuBarLoader.item.showRequested : false
226 sourceComponent: MenuBar {
228 objectName: "menuBar"
229 anchors.left: menuBarLoader ? menuBarLoader.left : undefined
230 anchors.margins: units.gu(1)
231 height: menuBarLoader.height
232 enableKeyFilter: valid && panelState.decorationsVisible
233 lomiriMenuModel: __applicationMenus.model
234 panelState: root.panelState
237 target: __applicationMenus
238 onShownChanged: bar.dismiss();
243 onShownChanged: bar.dismiss();
246 onDoubleClicked: panelState.restoreClicked()
247 onPressed: mouse.accepted = false // let the parent mouse area handle this, so it can both unsnap window and show menu
254 objectName: "callHint"
256 anchors.centerIn: parent
257 height: minimizedPanelHeight
259 visible: active && indicators.state == "initial" && __applicationMenus.state == "initial"
260 greeterShown: root.greeterShown
265 id: __applicationMenus
268 model: registeredMenuModel.model
269 width: root.menuWidth
271 minimizedPanelHeight: root.minimizedPanelHeight
272 expandedPanelHeight: root.expandedPanelHeight
273 openedHeight: root.height
274 alignment: Qt.AlignLeft
275 enableHint: !callHint.active && !fullscreenMode
277 panelColor: panelAreaBackground.color
280 if (callHint.active) {
281 callHint.showLiveCall();
286 rowItemDelegate: ActionItem {
288 property int ownIndex: index
289 objectName: "appMenuItem"+index
290 enabled: model.sensitive
292 width: _title.width + units.gu(2)
293 height: parent.height
296 text: model.label.replace("_", "&")
301 anchors.centerIn: parent
302 text: actionItem.text
303 horizontalAlignment: Text.AlignLeft
304 color: enabled ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
308 pageDelegate: PanelMenuPage {
309 readonly property bool isCurrent: modelIndex == __applicationMenus.currentMenuIndex
310 onIsCurrentChanged: {
311 if (isCurrent && menuModel) {
312 menuModel.aboutToShow(modelIndex);
316 menuModel: __applicationMenus.model
317 submenuIndex: modelIndex
319 factory: ApplicationMenuItemFactory {
320 rootModel: __applicationMenus.model
324 enabled: d.enableTouchMenus
325 opacity: d.showTouchMenu ? 1 : 0
326 visible: opacity != 0
327 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
330 if (!enabled) hide();
338 leftMargin: units.gu(1)
339 right: __indicators.left
340 rightMargin: units.gu(1)
342 height: root.minimizedPanelHeight
348 right: root.partialWidth ? parent.right : parent.left
349 rightMargin: touchMenuIcon.width
351 objectName: "panelTitle"
352 height: root.minimizedPanelHeight
353 verticalAlignment: Text.AlignVCenter
354 elide: Text.ElideRight
357 font.weight: Font.Medium
358 color: theme.palette.selected.backgroundText
359 text: (root.partialWidth && !callHint.visible) ? panelState.title : ""
360 opacity: __applicationMenus.visible && !__applicationMenus.expanded
361 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
362 visible: opacity !== 0
367 objectName: "touchMenuIcon"
370 leftMargin: rowLabel.contentWidth + units.dp(2)
371 verticalCenter: parent.verticalCenter
376 color: theme.palette.normal.backgroundText
377 opacity: !__applicationMenus.expanded && d.enableTouchMenus && !callHint.visible
378 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
379 visible: opacity !== 0
385 objectName: "indicators"
391 width: root.menuWidth
392 minimizedPanelHeight: root.minimizedPanelHeight
393 expandedPanelHeight: root.expandedPanelHeight
394 openedHeight: root.height
396 overFlowWidth: width - appMenuClear
397 enableHint: !callHint.active && !fullscreenMode
398 showOnClick: !callHint.visible
399 panelColor: panelAreaBackground.color
401 // On small screens, the Indicators' handle area is the entire top
402 // bar unless there is an application menu. In that case, our handle
403 // needs to allow for some room to clear the application menu.
404 property var appMenuClear: (d.enableTouchMenus && !partialWidth) ? units.gu(7) : 0
407 if (callHint.active) {
408 callHint.showLiveCall();
412 rowItemDelegate: IndicatorItem {
414 objectName: identifier+"-panelItem"
416 property int ownIndex: index
417 readonly property bool overflow: parent.width - (x - __indicators.rowContentX) > __indicators.overFlowWidth
418 readonly property bool hidden: !expanded && (overflow || !indicatorVisible || hideSessionIndicator || hideKeyboardIndicator)
419 // HACK for indicator-session
420 readonly property bool hideSessionIndicator: identifier == "indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
421 // HACK for indicator-keyboard
422 readonly property bool hideKeyboardIndicator: identifier == "indicator-keyboard" && !hasKeyboard
424 height: parent.height
425 expanded: indicators.expanded
426 selected: ListView.isCurrentItem
428 identifier: model.identifier
429 busName: indicatorProperties.busName
430 actionsObjectPath: indicatorProperties.actionsObjectPath
431 menuObjectPath: indicatorProperties.menuObjectPath
433 opacity: hidden ? 0.0 : 1.0
434 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
436 width: ((expanded || indicatorVisible) && !hideSessionIndicator && !hideKeyboardIndicator) ? implicitWidth : 0
438 Behavior on width { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
441 pageDelegate: PanelMenuPage {
442 objectName: modelData.identifier + "-page"
445 menuModel: delegate.menuModel
447 factory: IndicatorMenuItemFactory {
449 var context = modelData.identifier;
450 if (context && context.indexOf("fake-") === 0) {
451 context = context.substring("fake-".length)
455 rootModel: delegate.menuModel
460 busName: modelData.indicatorProperties.busName
461 actionsObjectPath: modelData.indicatorProperties.actionsObjectPath
462 menuObjectPath: modelData.indicatorProperties.menuObjectPath
466 enabled: !applicationMenus.expanded
467 opacity: !callHint.visible && !applicationMenus.expanded ? 1 : 0
468 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
471 if (!enabled) hide();
478 supportsMultiColorLed: root.supportsMultiColorLed
483 name: "onscreen" //fully opaque and visible at top edge of screen
484 when: !fullscreenMode
492 name: "offscreen" //pushed off screen
497 if (indicators.state !== "initial") return 0;
498 if (applicationMenus.state !== "initial") return 0;
499 return -minimizedPanelHeight;
501 opacity: indicators.fullyClosed && applicationMenus.fullyClosed ? 0.0 : 1.0
504 target: indicators.showDragHandle;
505 anchors.bottomMargin: -units.gu(1)
508 target: applicationMenus.showDragHandle;
509 anchors.bottomMargin: -units.gu(1)
517 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }
521 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }