Kirigami2

ActionToolBar.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 QtQml
9import QtQuick.Layouts
10import QtQuick.Controls as QQC2
11import QtQuick.Templates as T
12import org.kde.kirigami as Kirigami
13import "private" as P
14
15/**
16 * @brief A toolbar built out of a list of actions.
17 *
18 * The default representation for visible actions is a QtQuick.Controls.ToolButton, but
19 * it can be changed by setting the `Action.displayComponent` for an action.
20 * The default behavior of ActionToolBar is to display as many actions as possible,
21 * placing those that will not fit into an overflow menu. This can be changed by
22 * setting the `displayHint` property on an Action. For example, when setting the
23 * `DisplayHint.KeepVisible` display hint, ActionToolBar will try to keep that action
24 * in view as long as possible, using an icon-only button if a button with text
25 * does not fit.
26 *
27 * @inherit QtQuick.Controls.Control
28 * @since 2.5
29 */
30QQC2.Control {
31 id: root
32
33//BEGIN properties
34 /**
35 * @brief This property holds a list of visible actions.
36 *
37 * The ActionToolBar will try to display as many actions as possible.
38 * Those that won't fit will go into an overflow menu.
39 *
40 * @property list<Action> actions
41 */
42 readonly property alias actions: layout.actions
43
44 /**
45 * @brief This property holds whether the buttons will have a flat appearance.
46 *
47 * default: ``true``
48 */
49 property bool flat: true
50
51 /**
52 * @brief This property determines how the icon and text are displayed within the button.
53 *
54 * Permitted values are:
55 * * ``Button.IconOnly``
56 * * ``Button.TextOnly``
57 * * ``Button.TextBesideIcon``
58 * * ``Button.TextUnderIcon``
59 *
60 * default: ``Controls.Button.TextBesideIcon``
61 *
62 * @see QtQuick.Controls.AbstractButton
63 * @property int display
64 */
65 property int display: QQC2.Button.TextBesideIcon
66
67 /**
68 * @brief This property holds the alignment of the buttons.
69 *
70 * When there is more space available than required by the visible delegates,
71 * we need to determine how to place the delegates.
72 *
73 * When there is more space available than required by the visible action delegates,
74 * we need to determine where to position them.
75 *
76 * default: ``Qt.AlignLeft``
77 *
78 * @see Qt::AlignmentFlag
79 * @property int alignment
80 */
81 property alias alignment: layout.alignment
82
83 /**
84 * @brief This property holds the position of the toolbar.
85 *
86 * If this ActionToolBar is the contentItem of a QQC2 Toolbar, the position is bound to the ToolBar's position
87 *
88 * Permitted values are:
89 * * ``ToolBar.Header``: The toolbar is at the top, as a window or page header.
90 * * ``ToolBar.Footer``: The toolbar is at the bottom, as a window or page footer.
91 *
92 * @property int position
93 */
94 property int position: parent instanceof T.ToolBar ? parent.position : QQC2.ToolBar.Header
95
96 /**
97 * @brief This property holds the maximum width of the content of this ToolBar.
98 *
99 * If the toolbar's width is larger than this value, empty space will
100 * be added on the sides, according to the Alignment property.
101 *
102 * The value of this property is derived from the ToolBar's actions and their properties.
103 *
104 * @property int maximumContentWidth
105 */
106 readonly property alias maximumContentWidth: layout.implicitWidth
107
108 /**
109 * @brief This property holds the name of the icon to use for the overflow menu button.
110 *
111 * default: ``"overflow-menu"``
112 *
113 * @since 5.65
114 * @since 2.12
115 */
116 property string overflowIconName: "overflow-menu"
117
118 /**
119 * @brief This property holds the combined width of all visible delegates.
120 * @property int visibleWidth
121 */
122 readonly property alias visibleWidth: layout.visibleWidth
123
124 /**
125 * @brief This property sets the handling method for items that do not match the toolbar's height.
126 *
127 * When toolbar items do not match the height of the toolbar, there are
128 * several ways we can deal with this. This property sets the preferred way.
129 *
130 * Permitted values are:
131 * * ``HeightMode.AlwaysCenter``
132 * * ``HeightMode.AlwaysFill``
133 * * ``AlwaysFill.ConstrainIfLarger``
134 *
135 * default: ``HeightMode::ConstrainIfLarger``
136 *
137 * @see ToolBarLayout::heightMode
138 * @see ToolBarLayout::HeightMode
139 * @property ToolBarLayout::HeightMode heightMode
140 */
141 property alias heightMode: layout.heightMode
142//END properties
143
144 implicitHeight: layout.implicitHeight
145 implicitWidth: layout.implicitWidth
146
147 Layout.minimumWidth: layout.minimumWidth
148 Layout.preferredWidth: 0
149 Layout.fillWidth: true
150
151 leftPadding: 0
152 rightPadding: 0
153 topPadding: 0
154 bottomPadding: 0
155
156 Accessible.role: Accessible.ToolBar
157
158 contentItem: Kirigami.ToolBarLayout {
159 id: layout
160 spacing: Kirigami.Units.smallSpacing
161 layoutDirection: root.mirrored ? Qt.RightToLeft : Qt.LeftToRight
162
163 fullDelegate: P.PrivateActionToolButton {
164 flat: root.flat
165 display: root.display
166 action: Kirigami.ToolBarLayout.action
167 }
168
169 iconDelegate: P.PrivateActionToolButton {
170 flat: root.flat
171 display: QQC2.Button.IconOnly
172 action: Kirigami.ToolBarLayout.action
173
174 showMenuArrow: false
175
176 menuActions: {
177 if (action.displayComponent) {
178 return [action]
179 }
180
181 if (action instanceof Kirigami.Action) {
182 return action.children;
183 }
184
185 return []
186 }
187 }
188
189 separatorDelegate: QQC2.ToolSeparator {}
190
191 moreButton: P.PrivateActionToolButton {
192 flat: root.flat
193
194 action: Kirigami.Action {
195 tooltip: qsTr("More Actions")
196 icon.name: root.overflowIconName
197 displayHint: Kirigami.DisplayHint.IconOnly | Kirigami.DisplayHint.HideChildIndicator
198 }
199
200 Accessible.name: action.tooltip
201
202 menuActions: root.actions
203
204 menuComponent: P.ActionsMenu {
205 submenuComponent: P.ActionsMenu {
206 Binding {
207 target: parentItem
208 property: "visible"
209 value: layout.hiddenActions.includes(parentAction)
210 && (!(parentAction instanceof Kirigami.Action) || parentAction.visible)
211 restoreMode: Binding.RestoreBinding
212 }
213 }
214
215 itemDelegate: P.ActionMenuItem {
216 visible: layout.hiddenActions.includes(action)
217 && (!(action instanceof Kirigami.Action) || action.visible)
218 }
219
220 loaderDelegate: Loader {
221 property T.Action action
222 height: visible ? implicitHeight : 0
223 visible: layout.hiddenActions.includes(action)
224 && (!(action instanceof Kirigami.Action) || action.visible)
225 }
226
227 separatorDelegate: QQC2.MenuSeparator {
228 property T.Action action
229 visible: layout.hiddenActions.includes(action)
230 && (!(action instanceof Kirigami.Action) || action.visible)
231 }
232 }
233 }
234 }
235}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.