Kirigami2

PageRowGlobalToolBarUI.qml
1/*
2 * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7import QtQuick
8import QtQuick.Controls as QQC2
9import QtQuick.Layouts
10import org.kde.kirigami as Kirigami
11import "../../templates" as KT
12import "../../templates/private" as TP
13import "../" as P
14
15Kirigami.AbstractApplicationHeader {
16 id: header
17 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
18 + (leftHandleAnchor.visible ? leftHandleAnchor.width : 0)
19 + (menuButton.visible ? menuButton.width : 0)
20 readonly property int rightReservedSpace: rightHandleAnchor.visible ? rightHandleAnchor.width + Kirigami.Units.smallSpacing : 0
21
22 readonly property alias leftHandleAnchor: leftHandleAnchor
23 readonly property alias rightHandleAnchor: rightHandleAnchor
24
25 readonly property bool breadcrumbVisible: layerIsMainRow && breadcrumbLoader.active
26 readonly property bool layerIsMainRow: (root.layers.currentItem.hasOwnProperty("columnView")) ? root.layers.currentItem.columnView === root.columnView : false
27 readonly property Item currentItem: layerIsMainRow ? root.columnView : root.layers.currentItem
28
29 function __shouldHandleAnchorBeVisible(handleAnchor: Item, drawerProperty: string, itemProperty: string): bool {
30 if (typeof applicationWindow === "undefined") {
31 return false;
32 }
33 const w = applicationWindow();
34 if (!w) {
35 return false;
36 }
37 const drawer = w[drawerProperty] as KT.OverlayDrawer;
38 if (!drawer || !drawer.enabled || !drawer.handleVisible || drawer.handle.handleAnchor !== handleAnchor) {
39 return false;
40 }
41 const item = breadcrumbLoader.pageRow?.[itemProperty] as Item;
42 const style = item?.globalToolBarStyle ?? Kirigami.ApplicationHeaderStyle.None;
43 return globalToolBar.canContainHandles || style === Kirigami.ApplicationHeaderStyle.ToolBar;
44 }
45
46 height: visible ? implicitHeight : 0
47 minimumHeight: globalToolBar.minimumHeight
48 preferredHeight: globalToolBar.preferredHeight
49 maximumHeight: globalToolBar.maximumHeight
50 separatorVisible: globalToolBar.separatorVisible
51
52 Kirigami.Theme.colorSet: globalToolBar.colorSet
53
54 RowLayout {
55 anchors.fill: parent
56 spacing: 0
57
58 Item {
59 Layout.preferredWidth: applicationWindow().pageStack.globalToolBar.leftReservedSpace
60 visible: applicationWindow().pageStack !== root
61 }
62
63 Item {
64 id: leftHandleAnchor
65 visible: header.__shouldHandleAnchorBeVisible(leftHandleAnchor, "globalDrawer", "leadingVisibleItem")
66
67 Layout.preferredHeight: Math.max(backButton.implicitHeight, parent.height)
68 Layout.preferredWidth: height
69 }
70
71 P.PrivateActionToolButton {
72 id: menuButton
73 visible: !Kirigami.Settings.isMobile && applicationWindow().globalDrawer && "isMenu" in applicationWindow().globalDrawer && applicationWindow().globalDrawer.isMenu
74 icon.name: "open-menu-symbolic"
75 showMenuArrow: false
76
77 Layout.preferredHeight: Math.min(backButton.implicitHeight, parent.height)
78 Layout.preferredWidth: height
79 Layout.leftMargin: Kirigami.Units.smallSpacing
80
81 action: Kirigami.Action {
82 children: applicationWindow().globalDrawer && applicationWindow().globalDrawer.actions ? applicationWindow().globalDrawer.actions : []
83 tooltip: checked ? qsTr("Close menu") : qsTr("Open menu")
84 }
85 Accessible.name: action.tooltip
86
87 Connections {
88 // Only target the GlobalDrawer when it *is* a GlobalDrawer, since
89 // it can be something else, and that something else probably
90 // doesn't have an isMenuChanged() signal.
91 target: applicationWindow().globalDrawer as Kirigami.GlobalDrawer
92 function onIsMenuChanged() {
93 if (!applicationWindow().globalDrawer.isMenu && menuButton.menu) {
94 menuButton.menu.dismiss()
95 }
96 }
97 }
98 }
99
100 RowLayout {
101 id: buttonsLayout
102 Layout.fillHeight: true
103 Layout.preferredHeight: Math.max(backButton.visible ? backButton.implicitHeight : 0, forwardButton.visible ? forwardButton.implicitHeight : 0)
104
105 Layout.leftMargin: leftHandleAnchor.visible ? Kirigami.Units.smallSpacing : 0
106
107 visible: (globalToolBar.showNavigationButtons !== Kirigami.ApplicationHeaderStyle.NoNavigationButtons || applicationWindow().pageStack.layers.depth > 1 && !(applicationWindow().pageStack.layers.currentItem instanceof Kirigami.PageRow || header.layerIsMainRow))
108 && globalToolBar.actualStyle !== Kirigami.ApplicationHeaderStyle.None
109
110 Layout.maximumWidth: visibleChildren.length > 0 ? Layout.preferredWidth : 0
111
112 TP.BackButton {
113 id: backButton
114 Layout.leftMargin: leftHandleAnchor.visible ? 0 : Kirigami.Units.smallSpacing
115 Layout.minimumWidth: implicitHeight
116 Layout.minimumHeight: implicitHeight
117 Layout.maximumHeight: buttonsLayout.height
118 }
119 TP.ForwardButton {
120 id: forwardButton
121 Layout.minimumWidth: implicitHeight
122 Layout.minimumHeight: implicitHeight
123 Layout.maximumHeight: buttonsLayout.height
124 }
125 }
126
127 QQC2.ToolSeparator {
128 visible: (menuButton.visible || (buttonsLayout.visible && buttonsLayout.visibleChildren.length > 0)) && breadcrumbVisible && pageRow.depth > 1
129 }
130
131 Loader {
132 id: breadcrumbLoader
133 Layout.fillWidth: true
134 Layout.fillHeight: true
135 Layout.minimumHeight: -1
136 Layout.preferredHeight: -1
137 property Kirigami.PageRow pageRow: root
138
139 asynchronous: true
140
141 active: globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.Breadcrumb
142 && header.currentItem
143 && header.currentItem.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.None
144
145 source: Qt.resolvedUrl("BreadcrumbControl.qml")
146 }
147
148 Item {
149 id: rightHandleAnchor
150 visible: header.__shouldHandleAnchorBeVisible(rightHandleAnchor, "contextDrawer", "trailingVisibleItem")
151
152 Layout.preferredHeight: Math.max(backButton.implicitHeight, parent.height)
153 Layout.preferredWidth: height
154 }
155 }
156 background.opacity: breadcrumbLoader.active ? 1 : 0
157}
A specialized form of the Drawer intended for showing an application's always-available global action...
QString name(GameStandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:05:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.