Kirigami2

PageRowGlobalToolBarUI.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.15
8 import QtQuick.Controls 2.15 as QQC2
9 import QtQuick.Layouts 1.15
10 import org.kde.kirigami 2.19 as Kirigami
11 import "../../templates/private" as TP
12 import "../" as P
13 
14 Kirigami.AbstractApplicationHeader {
15  id: header
16  readonly property int leftReservedSpace: (buttonsLayout.visible && buttonsLayout.visibleChildren.length > 0 ? buttonsLayout.width : 0)
17  + (leftHandleAnchor.visible ? leftHandleAnchor.width : 0)
18  + (menuButton.visible ? menuButton.width : 0)
19  readonly property int rightReservedSpace: rightHandleAnchor.visible ? backButton.background.implicitHeight : 0
20 
21  readonly property alias leftHandleAnchor: leftHandleAnchor
22  readonly property alias rightHandleAnchor: rightHandleAnchor
23 
24  readonly property bool breadcrumbVisible: layerIsMainRow && breadcrumbLoader.active
25  readonly property bool layerIsMainRow: (root.layers.currentItem.hasOwnProperty("columnView")) ? root.layers.currentItem.columnView === root.columnView : false
26  readonly property Item currentItem: layerIsMainRow ? root.columnView : root.layers.currentItem
27 
28  height: visible ? implicitHeight : 0
29  minimumHeight: globalToolBar.minimumHeight
30  preferredHeight: globalToolBar.preferredHeight
31  maximumHeight: globalToolBar.maximumHeight
32  separatorVisible: globalToolBar.separatorVisible
33 
34  Kirigami.Theme.colorSet: globalToolBar.colorSet
35  Kirigami.Theme.textColor: currentItem ? currentItem.Kirigami.Theme.textColor : parent.Kirigami.Theme.textColor
36 
37  RowLayout {
38  anchors.fill: parent
39  spacing: 0
40 
41  Item {
42  Layout.preferredWidth: applicationWindow().pageStack.globalToolBar.leftReservedSpace
43  visible: applicationWindow().pageStack !== root
44  }
45 
46  Item {
47  id: leftHandleAnchor
48  visible: (typeof applicationWindow() !== "undefined" && applicationWindow().globalDrawer && applicationWindow().globalDrawer.enabled && applicationWindow().globalDrawer.handleVisible &&
49  applicationWindow().globalDrawer.handle.handleAnchor === leftHandleAnchor) &&
50  (globalToolBar.canContainHandles || (breadcrumbLoader.pageRow.firstVisibleItem &&
51  breadcrumbLoader.pageRow.firstVisibleItem.globalToolBarStyle === Kirigami.ApplicationHeaderStyle.ToolBar))
52 
53 
54  Layout.preferredHeight: Math.min(backButton.implicitHeight, parent.height)
55  Layout.preferredWidth: height
56  }
57 
58  P.PrivateActionToolButton {
59  id: menuButton
60  visible: !Kirigami.Settings.isMobile && applicationWindow().globalDrawer && "isMenu" in applicationWindow().globalDrawer && applicationWindow().globalDrawer.isMenu
61  icon.name: "open-menu-symbolic"
62  showMenuArrow: false
63 
64  Layout.preferredHeight: Math.min(backButton.implicitHeight, parent.height)
65  Layout.preferredWidth: height
66  Layout.leftMargin: Kirigami.Units.smallSpacing
67 
68  action: Kirigami.Action {
69  children: applicationWindow().globalDrawer && applicationWindow().globalDrawer.actions ? applicationWindow().globalDrawer.actions : []
70  tooltip: checked ? qsTr("Close menu") : qsTr("Open menu")
71  }
72  Accessible.name: action.tooltip
73  }
74 
75  RowLayout {
76  id: buttonsLayout
77  Layout.fillHeight: true
78  Layout.preferredHeight: Math.max(backButton.visible ? backButton.implicitHeight : 0, forwardButton.visible ? forwardButton.implicitHeight : 0)
79 
80  Layout.leftMargin: leftHandleAnchor.visible ? Kirigami.Units.smallSpacing : 0
81 
82  // TODO KF6: make showNavigationButtons an int, and replace with strict === equality
83  visible: (globalToolBar.showNavigationButtons !== Kirigami.ApplicationHeaderStyle.NoNavigationButtons || applicationWindow().pageStack.layers.depth > 1 && !(applicationWindow().pageStack.layers.currentItem instanceof Kirigami.PageRow))
84  && globalToolBar.actualStyle !== Kirigami.ApplicationHeaderStyle.None
85 
86  Layout.maximumWidth: visibleChildren.length > 0 ? Layout.preferredWidth : 0
87 
88  TP.BackButton {
89  id: backButton
90  Layout.leftMargin: leftHandleAnchor.visible ? 0 : Kirigami.Units.smallSpacing
91  Layout.minimumWidth: implicitHeight
92  Layout.minimumHeight: implicitHeight
93  Layout.maximumHeight: buttonsLayout.height
94  }
95  TP.ForwardButton {
96  id: forwardButton
97  Layout.minimumWidth: implicitHeight
98  Layout.minimumHeight: implicitHeight
99  Layout.maximumHeight: buttonsLayout.height
100  }
101  }
102 
103  QQC2.ToolSeparator {
104  visible: (menuButton.visible || (buttonsLayout.visible && buttonsLayout.visibleChildren.length > 0)) && breadcrumbVisible && pageRow.depth > 1
105  }
106 
107  Loader {
108  id: breadcrumbLoader
109  Layout.fillWidth: true
110  Layout.fillHeight: true
111  Layout.minimumHeight: -1
112  Layout.preferredHeight: -1
113  property Kirigami.PageRow pageRow: root
114 
115  asynchronous: true
116 
117  active: (globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.TabBar || globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.Breadcrumb) && currentItem && currentItem.globalToolBarStyle !== Kirigami.ApplicationHeaderStyle.None
118 
119  // TODO: different implementation?
120  source: globalToolBar.actualStyle === Kirigami.ApplicationHeaderStyle.TabBar ? Qt.resolvedUrl("TabBarControl.qml") : Qt.resolvedUrl("BreadcrumbControl.qml")
121  }
122 
123  Item {
124  id: rightHandleAnchor
125  visible: (typeof applicationWindow() !== "undefined" &&
126  applicationWindow().contextDrawer &&
127  applicationWindow().contextDrawer.enabled &&
128  applicationWindow().contextDrawer.handleVisible &&
129  applicationWindow().contextDrawer.handle.handleAnchor === rightHandleAnchor &&
130  (globalToolBar.canContainHandles || (breadcrumbLoader.pageRow && breadcrumbLoader.pageRow.lastVisibleItem &&
131  breadcrumbLoader.pageRow.lastVisibleItem.globalToolBarStyle === Kirigami.ApplicationHeaderStyle.ToolBar)))
132  Layout.fillHeight: true
133  Layout.preferredWidth: height
134  }
135  }
136  background.opacity: breadcrumbLoader.active ? 1 : 0
137 }
int length() const const
QString name(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.