Warning, /frameworks/kirigami/src/controls/private/globaltoolbar/PageRowGlobalToolBarUI.qml is written in an unsupported language. File is not indexed.
0001 /*
0002 * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org>
0003 *
0004 * SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006
0007 import QtQuick
0008 import QtQuick.Controls as QQC2
0009 import QtQuick.Layouts
0010 import org.kde.kirigami as Kirigami
0011 import "../../templates" as KT
0012 import "../../templates/private" as TP
0013 import "../" as P
0014
0015 Kirigami.AbstractApplicationHeader {
0016 id: header
0017 readonly property int leftReservedSpace: (buttonsLayout.visible && buttonsLayout.visibleChildren.length > 0 ? buttonsLayout.width + Kirigami.Units.smallSpacing : 0) // Take into account the layout margins the nav buttons have
0018 + (leftHandleAnchor.visible ? leftHandleAnchor.width : 0)
0019 + (menuButton.visible ? menuButton.width : 0)
0020 readonly property int rightReservedSpace: rightHandleAnchor.visible ? rightHandleAnchor.width + Kirigami.Units.smallSpacing : 0
0021
0022 readonly property alias leftHandleAnchor: leftHandleAnchor
0023 readonly property alias rightHandleAnchor: rightHandleAnchor
0024
0025 readonly property bool breadcrumbVisible: layerIsMainRow && breadcrumbLoader.active
0026 readonly property bool layerIsMainRow: (root.layers.currentItem.hasOwnProperty("columnView")) ? root.layers.currentItem.columnView === root.columnView : false
0027 readonly property Item currentItem: layerIsMainRow ? root.columnView : root.layers.currentItem
0028
0029 function __shouldHandleAnchorBeVisible(handleAnchor: Item, drawerProperty: string, itemProperty: string): bool {
0030 if (typeof applicationWindow === "undefined") {
0031 return false;
0032 }
0033 const w = applicationWindow();
0034 if (!w) {
0035 return false;
0036 }
0037 const drawer = w[drawerProperty] as KT.OverlayDrawer;
0038 if (!drawer || !drawer.enabled || !drawer.handleVisible || drawer.handle.handleAnchor !== handleAnchor) {
0039 return false;
0040 }
0041 const item = breadcrumbLoader.pageRow?.[itemProperty] as Item;
0042 const style = item?.globalToolBarStyle ?? Kirigami.ApplicationHeaderStyle.None;
0043 return globalToolBar.canContainHandles || style === Kirigami.ApplicationHeaderStyle.ToolBar;
0044 }
0045
0046 height: visible ? implicitHeight : 0
0047 minimumHeight: globalToolBar.minimumHeight
0048 preferredHeight: globalToolBar.preferredHeight
0049 maximumHeight: globalToolBar.maximumHeight
0050 separatorVisible: globalToolBar.separatorVisible
0051
0052 Kirigami.Theme.colorSet: globalToolBar.colorSet
0053 Kirigami.Theme.textColor: currentItem ? currentItem.Kirigami.Theme.textColor : parent.Kirigami.Theme.textColor
0054
0055 RowLayout {
0056 anchors.fill: parent
0057 spacing: 0
0058
0059 Item {
0060 Layout.preferredWidth: applicationWindow().pageStack.globalToolBar.leftReservedSpace
0061 visible: applicationWindow().pageStack !== root
0062 }
0063
0064 Item {
0065 id: leftHandleAnchor
0066 visible: header.__shouldHandleAnchorBeVisible(leftHandleAnchor, "globalDrawer", "leadingVisibleItem")
0067
0068 Layout.preferredHeight: Math.max(backButton.implicitHeight, parent.height)
0069 Layout.preferredWidth: height
0070 }
0071
0072 P.PrivateActionToolButton {
0073 id: menuButton
0074 visible: !Kirigami.Settings.isMobile && applicationWindow().globalDrawer && "isMenu" in applicationWindow().globalDrawer && applicationWindow().globalDrawer.isMenu
0075 icon.name: "open-menu-symbolic"
0076 showMenuArrow: false
0077
0078 Layout.preferredHeight: Math.min(backButton.implicitHeight, parent.height)
0079 Layout.preferredWidth: height
0080 Layout.leftMargin: Kirigami.Units.smallSpacing
0081
0082 action: Kirigami.Action {
0083 children: applicationWindow().globalDrawer && applicationWindow().globalDrawer.actions ? applicationWindow().globalDrawer.actions : []
0084 tooltip: checked ? qsTr("Close menu") : qsTr("Open menu")
0085 }
0086 Accessible.name: action.tooltip
0087
0088 Connections {
0089 // Only target the GlobalDrawer when it *is* a GlobalDrawer, since
0090 // it can be something else, and that something else probably
0091 // doesn't have an isMenuChanged() signal.
0092 target: applicationWindow().globalDrawer as Kirigami.GlobalDrawer
0093 function onIsMenuChanged() {
0094 if (!applicationWindow().globalDrawer.isMenu && menuButton.menu) {
0095 menuButton.menu.dismiss()
0096 }
0097 }
0098 }
0099 }
0100
0101 RowLayout {
0102 id: buttonsLayout
0103 Layout.fillHeight: true
0104 Layout.preferredHeight: Math.max(backButton.visible ? backButton.implicitHeight : 0, forwardButton.visible ? forwardButton.implicitHeight : 0)
0105
0106 Layout.leftMargin: leftHandleAnchor.visible ? Kirigami.Units.smallSpacing : 0
0107
0108 visible: (globalToolBar.showNavigationButtons !== Kirigami.ApplicationHeaderStyle.NoNavigationButtons || applicationWindow().pageStack.layers.depth > 1 && !(applicationWindow().pageStack.layers.currentItem instanceof Kirigami.PageRow || header.layerIsMainRow))
0109 && globalToolBar.actualStyle !== Kirigami.ApplicationHeaderStyle.None
0110
0111 Layout.maximumWidth: visibleChildren.length > 0 ? Layout.preferredWidth : 0
0112
0113 TP.BackButton {
0114 id: backButton
0115 Layout.leftMargin: leftHandleAnchor.visible ? 0 : Kirigami.Units.smallSpacing
0116 Layout.minimumWidth: implicitHeight
0117 Layout.minimumHeight: implicitHeight
0118 Layout.maximumHeight: buttonsLayout.height
0119 }
0120 TP.ForwardButton {
0121 id: forwardButton
0122 Layout.minimumWidth: implicitHeight
0123 Layout.minimumHeight: implicitHeight
0124 Layout.maximumHeight: buttonsLayout.height
0125 }
0126 }
0127
0128 QQC2.ToolSeparator {
0129 visible: (menuButton.visible || (buttonsLayout.visible && buttonsLayout.visibleChildren.length > 0)) && breadcrumbVisible && pageRow.depth > 1
0130 }
0131
0132 Loader {
0133 id: breadcrumbLoader
0134 Layout.fillWidth: true
0135 Layout.fillHeight: true
0136 Layout.minimumHeight: -1
0137 Layout.preferredHeight: -1
0138 property Kirigami.PageRow pageRow: root
0139
0140 asynchronous: true
0141
0142 active: globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.Breadcrumb
0143 && header.currentItem
0144 && header.currentItem.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.None
0145
0146 source: Qt.resolvedUrl("BreadcrumbControl.qml")
0147 }
0148
0149 Item {
0150 id: rightHandleAnchor
0151 visible: header.__shouldHandleAnchorBeVisible(rightHandleAnchor, "contextDrawer", "trailingVisibleItem")
0152
0153 Layout.preferredHeight: Math.max(backButton.implicitHeight, parent.height)
0154 Layout.preferredWidth: height
0155 }
0156 }
0157 background.opacity: breadcrumbLoader.active ? 1 : 0
0158 }