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 contentItem: Kirigami.ToolBarLayout {
157 id: layout
158 spacing: Kirigami.Units.smallSpacing
159 layoutDirection: root.mirrored ? Qt.RightToLeft : Qt.LeftToRight
160
161 fullDelegate: P.PrivateActionToolButton {
162 flat: root.flat
163 display: root.display
164 action: Kirigami.ToolBarLayout.action
165 }
166
167 iconDelegate: P.PrivateActionToolButton {
168 flat: root.flat
169 display: QQC2.Button.IconOnly
170 action: Kirigami.ToolBarLayout.action
171
172 showMenuArrow: false
173
174 menuActions: {
175 if (action.displayComponent) {
176 return [action]
177 }
178
179 if (action instanceof Kirigami.Action) {
180 return action.children;
181 }
182
183 return []
184 }
185 }
186
187 separatorDelegate: QQC2.ToolSeparator {}
188
189 moreButton: P.PrivateActionToolButton {
190 flat: root.flat
191
192 action: Kirigami.Action {
193 tooltip: qsTr("More Actions")
194 icon.name: root.overflowIconName
195 displayHint: Kirigami.DisplayHint.IconOnly | Kirigami.DisplayHint.HideChildIndicator
196 }
197
198 Accessible.name: action.tooltip
199
200 menuActions: root.actions
201
202 menuComponent: P.ActionsMenu {
203 submenuComponent: P.ActionsMenu {
204 Binding {
205 target: parentItem
206 property: "visible"
207 value: layout.hiddenActions.includes(parentAction)
208 && (!(parentAction instanceof Kirigami.Action) || parentAction.visible)
209 restoreMode: Binding.RestoreBinding
210 }
211 }
212
213 itemDelegate: P.ActionMenuItem {
214 visible: layout.hiddenActions.includes(action)
215 && (!(action instanceof Kirigami.Action) || action.visible)
216 }
217
218 loaderDelegate: Loader {
219 property T.Action action
220 height: visible ? implicitHeight : 0
221 visible: layout.hiddenActions.includes(action)
222 && (!(action instanceof Kirigami.Action) || action.visible)
223 }
224
225 separatorDelegate: QQC2.MenuSeparator {
226 property T.Action action
227 visible: layout.hiddenActions.includes(action)
228 && (!(action instanceof Kirigami.Action) || action.visible)
229 }
230 }
231 }
232 }
233}
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.