Kirigami2

ToolBarApplicationHeader.qml
1 /*
2  * SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.5
8 import QtQuick.Controls 2.0 as QQC2
9 import QtQuick.Layouts 1.2
10 import org.kde.kirigami 2.4 as Kirigami
11 import "private" as P
12 
13 
14 // TODO KF6: Remove!
15 /**
16  * @brief ToolBarApplicationHeader represents a toolbar that
17  * will display the actions of the current page.
18  *
19  * Both Contextual actions and the main, left and right actions
20  */
22  id: header
23 
24  preferredHeight: 42
25  maximumHeight: preferredHeight
26  headerStyle: ApplicationHeaderStyle.Titles
27 
28  // FIXME: needs a property definition to have its own type in qml
29  property string _internal: ""
30 
31  Component.onCompleted: print("Warning: ToolbarApplicationHeader is deprecated, remove and use the automatic internal toolbar instead.")
32  pageDelegate: Item {
33  id: delegateItem
34  readonly property bool current: __appWindow.pageStack.currentIndex === index
35  implicitWidth: titleTextMetrics.width/2 + buttonTextMetrics.collapsedButtonsWidth
36 
37  RowLayout {
38  id: titleLayout
39  anchors {
40  verticalCenter: parent.verticalCenter
41  left: parent.left
42  right: actionsLayout.left
43  }
44  Kirigami.Separator {
45  id: separator
46  Layout.preferredHeight: parent.height * 0.6
47  }
48 
49  Kirigami.Heading {
50  id: title
51  Layout.fillWidth: true
52 
53  Layout.preferredWidth: implicitWidth
54  Layout.minimumWidth: Math.min(titleTextMetrics.width, delegateItem.width - buttonTextMetrics.requiredWidth)
55  leftPadding: Kirigami.Units.largeSpacing
56  opacity: delegateItem.current ? 1 : 0.4
57  maximumLineCount: 1
58  color: Kirigami.Theme.textColor
59  elide: Text.ElideRight
60  text: page ? page.title : ""
61  }
62  }
63 
64  TextMetrics {
65  id: titleTextMetrics
66  text: page ? page.title : ""
67  font: title.font
68  }
69  TextMetrics {
70  id: buttonTextMetrics
71  text: (page.actions.left ? page.actions.left.text : "") + (page.actions.main ? page.actions.main.text : "") + (page.actions.right ? page.actions.right.text : "")
72  readonly property int collapsedButtonsWidth: ctxActionsButton.width + (page.actions.left ? ctxActionsButton.width + Kirigami.Units.gridUnit : 0) + (page.actions.main ? ctxActionsButton.width + Kirigami.Units.gridUnit : 0) + (page.actions.right ? ctxActionsButton.width + Kirigami.Units.gridUnit : 0)
73  readonly property int requiredWidth: width + collapsedButtonsWidth
74  }
75 
76  RowLayout {
77  id: actionsLayout
78  anchors {
79  verticalCenter: parent.verticalCenter
80  right: ctxActionsButton.visible ? ctxActionsButton.left : parent.right
81  }
82 
83  readonly property bool toobig: delegateItem.width - titleTextMetrics.width - Kirigami.Units.gridUnit < buttonTextMetrics.requiredWidth
84 
85  P.PrivateActionToolButton {
86  Layout.alignment: Qt.AlignVCenter
87  action: page && page.actions ? page.actions.left : null
88  display: parent.toobig ? QQC2.AbstractButton.IconOnly : QQC2.AbstractButton.TextBesideIcon
89  }
90  P.PrivateActionToolButton {
91  Layout.alignment: Qt.AlignVCenter
92  Layout.rightMargin: Kirigami.Units.smallSpacing
93  action: page && page.actions ? page.actions.main : null
94  display: parent.toobig ? QQC2.AbstractButton.IconOnly : QQC2.AbstractButton.TextBesideIcon
95  flat: false
96  }
97  P.PrivateActionToolButton {
98  Layout.alignment: Qt.AlignVCenter
99  action: page && page.actions ? page.actions.right : null
100  display: parent.toobig ? QQC2.AbstractButton.IconOnly : QQC2.AbstractButton.TextBesideIcon
101  }
102  }
103 
104  P.PrivateActionToolButton {
105  id: ctxActionsButton
106  showMenuArrow: page.actions.contextualActions.length === 1
107  anchors {
108  right: parent.right
109  verticalCenter: parent.verticalCenter
110  rightMargin: Kirigami.Units.smallSpacing
111  }
112  Kirigami.Action {
113  id: overflowAction
114  icon.name: "overflow-menu"
115  tooltip: qsTr("More Actions")
116  visible: children.length > 0
117  children: page && page.actions.contextualActions ? page.actions.contextualActions : null
118  }
119 
120  action: page && page.actions.contextualActions.length === 1 ? page.actions.contextualActions[0] : overflowAction
121  }
122  }
123 }
An item that can be used as a title for the application.
QTextStream & left(QTextStream &s)
QTextStream & right(QTextStream &s)
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.