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/>.
20import Lomiri.Components 1.3
21import Lomiri.Layouts 1.0
22import QtMir.Application 0.1
23import Lomiri.Indicators 0.1
25import Lomiri.ApplicationMenu 0.1
27import QtQuick.Window 2.2
29import "../ApplicationMenus"
31import "../Components/PanelState"
38 readonly property real panelHeight: panelArea.y + minimizedPanelHeight
39 readonly property bool fullyClosed: indicators.fullyClosed && applicationMenus.fullyClosed
41 property real minimizedPanelHeight: units.gu(3)
42 property real expandedPanelHeight: units.gu(7)
43 property real menuWidth: partialWidth ? units.gu(40) : width
44 property alias applicationMenuContentX: __applicationMenus.menuContentX
46 property alias applicationMenus: __applicationMenus
47 property alias indicators: __indicators
48 property bool fullscreenMode: false
49 property real panelAreaShowProgress: 1.0
50 property bool greeterShown: false
51 property bool hasKeyboard: false
52 property bool supportsMultiColorLed: true
53 property var blurSource : null
54 property bool lightMode : false
56 // Whether our expanded menus should take up the full width of the panel
57 property bool partialWidth: width >= units.gu(60)
59 property string mode: "staged"
60 property PanelState panelState
62 property bool temporarilyShown: false
64 function temporarilyShow() {
65 temporarilyShown = true
66 temporaryShowTimeout.restart()
70 id: temporaryShowTimeout
74 temporarilyShown = false
81 anchors.topMargin: panelHeight
82 visible: !indicators.fullyClosed || !applicationMenus.fullyClosed
84 hoverEnabled: true // should also eat hover events, otherwise they will pass through
87 __applicationMenus.hide();
94 restoreMode: Binding.RestoreBinding
95 property: "panelHeight"
96 value: minimizedPanelHeight
99 RegisteredApplicationMenuModel {
100 id: registeredMenuModel
101 persistentSurfaceId: panelState.focusedPersistentSurfaceId
107 property bool revealControls: !greeterShown &&
108 !applicationMenus.shown &&
110 (decorationMouseArea.containsMouse || menuBarLoader.menusRequested)
112 property bool showWindowDecorationControls: (revealControls && panelState.decorationsVisible) ||
113 panelState.decorationsAlwaysVisible
115 property bool showPointerMenu: revealControls &&
116 (panelState.decorationsVisible || mode == "windowed")
118 property bool enablePointerMenu: applicationMenus.available &&
119 applicationMenus.model
121 property bool showTouchMenu: !greeterShown &&
123 !showWindowDecorationControls
125 property bool enableTouchMenus: showTouchMenu &&
126 applicationMenus.available &&
127 applicationMenus.model
132 objectName: "panelArea"
136 transform: Translate {
137 y: indicators.state === "initial"
138 ? (1.0 - panelAreaShowProgress) * - minimizedPanelHeight
143 id: indicatorsDropShadow
146 margins: -units.gu(1)
148 visible: !__indicators.fullyClosed
149 source: "graphics/rectangular_dropshadow.sci"
153 id: appmenuDropShadow
155 fill: __applicationMenus
156 margins: -units.gu(1)
158 visible: !__applicationMenus.fullyClosed
159 source: "graphics/rectangular_dropshadow.sci"
165 fill: panelAreaBackground
166 bottomMargin: -units.gu(1)
168 visible: panelState.dropShadow
169 source: "graphics/rectangular_dropshadow.sci"
173 id: panelAreaBackground
174 color: callHint.visible ? theme.palette.normal.activity :
175 (root.lightMode ? "#FFFFFF" : "#000000")
181 height: minimizedPanelHeight
183 Behavior on color { ColorAnimation { duration: LomiriAnimation.FastDuration } }
187 id: decorationMouseArea
188 objectName: "windowControlArea"
193 height: minimizedPanelHeight
194 hoverEnabled: !__indicators.shown
196 if (callHint.visible) {
197 callHint.showLiveCall();
202 if (!callHint.visible) {
203 // let it fall through to the window decoration of the maximized window behind, if any
204 mouse.accepted = false;
206 var menubar = menuBarLoader.item;
208 menubar.invokeMenu(mouse);
216 // WindowControlButtons inside the mouse area, otherwise QML doesn't grok nested hover events :/
217 // cf. https://bugreports.qt.io/browse/QTBUG-32909
218 WindowControlButtons {
219 id: windowControlButtons
220 objectName: "panelWindowControlButtons"
221 height: indicators.minimizedPanelHeight
222 opacity: d.showWindowDecorationControls ? 1 : 0
223 visible: opacity != 0
224 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
226 active: panelState.decorationsVisible || panelState.decorationsAlwaysVisible
227 windowIsMaximized: true
228 onCloseClicked: panelState.closeClicked()
229 onMinimizeClicked: panelState.minimizeClicked()
230 onMaximizeClicked: panelState.restoreClicked()
231 closeButtonShown: panelState.closeButtonShown
236 objectName: "menuBarLoader"
237 height: parent.height
238 enabled: d.enablePointerMenu
239 opacity: d.showPointerMenu ? 1 : 0
240 visible: opacity != 0
241 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
242 active: d.showPointerMenu && !callHint.visible
244 width: parent.width - windowControlButtons.width - units.gu(2) - __indicators.barWidth
246 readonly property bool menusRequested: menuBarLoader.item ? menuBarLoader.item.showRequested : false
248 sourceComponent: MenuBar {
250 objectName: "menuBar"
251 anchors.left: menuBarLoader ? menuBarLoader.left : undefined
252 anchors.margins: units.gu(1)
253 height: menuBarLoader.height
254 enableKeyFilter: valid && panelState.decorationsVisible
255 lomiriMenuModel: __applicationMenus.model
256 panelState: root.panelState
259 target: __applicationMenus
260 function onShownChanged() { bar.dismiss(); }
265 function onShownChanged() { bar.dismiss(); }
268 onDoubleClicked: panelState.restoreClicked()
269 onPressed: mouse.accepted = false // let the parent mouse area handle this, so it can both unsnap window and show menu
276 objectName: "callHint"
278 anchors.centerIn: parent
279 height: minimizedPanelHeight
281 visible: active && indicators.state == "initial" && __applicationMenus.state == "initial"
282 greeterShown: root.greeterShown
287 id: __applicationMenus
290 model: registeredMenuModel.model
291 width: root.menuWidth
293 minimizedPanelHeight: root.minimizedPanelHeight
294 expandedPanelHeight: root.expandedPanelHeight
295 openedHeight: root.height
296 alignment: Qt.AlignLeft
297 enableHint: !callHint.active && !fullscreenMode
299 panelColor: panelAreaBackground.color
300 blurSource: root.blurSource
305 lightMode: root.lightMode
308 if (callHint.active) {
309 callHint.showLiveCall();
314 rowItemDelegate: ActionItem {
316 property int ownIndex: index
317 objectName: "appMenuItem"+index
318 enabled: model.sensitive
320 width: _title.width + units.gu(2)
321 height: parent.height
324 text: model.label.replace("_", "&")
329 anchors.centerIn: parent
330 text: actionItem.text
331 horizontalAlignment: Text.AlignLeft
332 color: enabled ? theme.palette.normal.backgroundText : theme.palette.disabled.backgroundText
336 pageDelegate: PanelMenuPage {
337 readonly property bool isCurrent: modelIndex == __applicationMenus.currentMenuIndex
338 onIsCurrentChanged: {
339 if (isCurrent && menuModel) {
340 menuModel.aboutToShow(modelIndex);
344 menuModel: __applicationMenus.model
345 submenuIndex: modelIndex
347 factory: ApplicationMenuItemFactory {
348 rootModel: __applicationMenus.model
352 enabled: d.enableTouchMenus
353 opacity: d.showTouchMenu ? 1 : 0
354 visible: opacity != 0
356 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
359 if (!enabled) hide();
367 leftMargin: units.gu(1)
368 right: __indicators.left
369 rightMargin: units.gu(1)
371 height: root.minimizedPanelHeight
377 right: root.partialWidth ? parent.right : parent.left
378 rightMargin: touchMenuIcon.width
380 objectName: "panelTitle"
381 height: root.minimizedPanelHeight
382 verticalAlignment: Text.AlignVCenter
383 elide: Text.ElideRight
386 font.weight: Font.Medium
387 color: theme.palette.selected.backgroundText
388 text: (root.partialWidth && !callHint.visible) ? panelState.title : ""
389 opacity: __applicationMenus.visible && !__applicationMenus.expanded
390 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
391 visible: opacity !== 0
396 objectName: "touchMenuIcon"
399 leftMargin: rowLabel.contentWidth + units.dp(2)
400 verticalCenter: parent.verticalCenter
405 color: theme.palette.normal.backgroundText
406 opacity: !__applicationMenus.expanded && d.enableTouchMenus && !callHint.visible
407 Behavior on opacity { NumberAnimation { duration: LomiriAnimation.SnapDuration } }
408 visible: opacity !== 0
414 objectName: "indicators"
420 width: root.menuWidth
421 minimizedPanelHeight: root.minimizedPanelHeight
422 expandedPanelHeight: root.expandedPanelHeight
423 openedHeight: root.height
425 overFlowWidth: width - appMenuClear
426 enableHint: !callHint.active && !fullscreenMode
427 showOnClick: !callHint.visible
428 panelColor: panelAreaBackground.color
429 blurSource: root.blurSource
435 // On small screens, the Indicators' handle area is the entire top
436 // bar unless there is an application menu. In that case, our handle
437 // needs to allow for some room to clear the application menu.
438 property var appMenuClear: (d.enableTouchMenus && !partialWidth) ? units.gu(7) : 0
441 if (callHint.active) {
442 callHint.showLiveCall();
446 rowItemDelegate: IndicatorItem {
448 objectName: identifier+"-panelItem"
450 property int ownIndex: index
451 readonly property bool overflow: parent.width - (x - __indicators.rowContentX) > __indicators.overFlowWidth
452 readonly property bool hidden: !expanded && (overflow || !indicatorVisible || hideSessionIndicator || hideKeyboardIndicator)
453 // HACK for indicator-session
454 readonly property bool hideSessionIndicator: identifier == "ayatana-indicator-session" && Math.min(Screen.width, Screen.height) <= units.gu(60)
455 // HACK for indicator-keyboard
456 readonly property bool hideKeyboardIndicator: identifier == "ayatana-indicator-keyboard" && !hasKeyboard
458 height: parent.height
459 expanded: indicators.expanded
460 selected: ListView.isCurrentItem
462 identifier: model.identifier
463 busName: indicatorProperties.busName
464 actionsObjectPath: indicatorProperties.actionsObjectPath
465 menuObjectPath: indicatorProperties.menuObjectPath
467 opacity: hidden ? 0.0 : 1.0
468 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
470 width: ((expanded || indicatorVisible) && !hideSessionIndicator && !hideKeyboardIndicator) ? implicitWidth : 0
472 Behavior on width { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
475 pageDelegate: PanelMenuPage {
476 objectName: modelData.identifier + "-page"
479 menuModel: delegate.menuModel
481 factory: IndicatorMenuItemFactory {
483 var context = modelData.identifier;
484 if (context && context.indexOf("fake-") === 0) {
485 context = context.substring("fake-".length)
489 rootModel: delegate.menuModel
494 busName: modelData.indicatorProperties.busName
495 actionsObjectPath: modelData.indicatorProperties.actionsObjectPath
496 menuObjectPath: modelData.indicatorProperties.menuObjectPath
500 enabled: !applicationMenus.expanded
501 opacity: !callHint.visible && !applicationMenus.expanded ? 1 : 0
503 Behavior on opacity { LomiriNumberAnimation { duration: LomiriAnimation.SnapDuration } }
506 if (!enabled) hide();
513 supportsMultiColorLed: root.supportsMultiColorLed
518 name: "onscreen" //fully opaque and visible at top edge of screen
519 when: !fullscreenMode || temporarilyShown
527 name: "offscreen" //pushed off screen
532 if (indicators.state !== "initial") return 0;
533 if (applicationMenus.state !== "initial") return 0;
534 return -minimizedPanelHeight;
536 opacity: indicators.fullyClosed && applicationMenus.fullyClosed ? 0.0 : 1.0
539 target: indicators.showDragHandle;
540 anchors.bottomMargin: -units.gu(1)
543 target: applicationMenus.showDragHandle;
544 anchors.bottomMargin: -units.gu(1)
552 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }
556 LomiriNumberAnimation { target: panelArea; properties: "anchors.topMargin,opacity" }