Kirigami2

ActionToolBar.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.7
8 import QtQml 2.15
9 import QtQuick.Layouts 1.2
10 import QtQuick.Controls 2.4 as QQC2
11 import org.kde.kirigami 2.14 as Kirigami
12 import "private" as P
13 
14 /**
15  * @brief A toolbar built out of a list of actions.
16  *
17  * The default representation for visible actions is a QtQuick.Controls.ToolButton, but
18  * it can be changed by setting the `Action.displayComponent` for an action.
19  * The ActionToolBar component will try to display has many actions as possible but
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  */
30 QQC2.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  property alias actions: layout.actions
43 
44  /**
45  * @brief This property holds a list of hidden actions.
46  *
47  * These actions will always be displayed in the overflow menu, even if there is enough space.
48  *
49  * @deprecated since 2.14, use the AlwaysHide hint on actions instead.
50  * @property list<Action> hiddenActions
51  * @since 2.6
52  */
53  property list<QtObject> hiddenActions
54  onHiddenActionsChanged: print("ActionToolBar::hiddenActions is deprecated, use the AlwaysHide hint on your actions instead")
55 
56  /**
57  * @brief This property holds whether the buttons will have a flat appearance.
58  *
59  * default: ``true``
60  */
61  property bool flat: true
62 
63  /**
64  * @brief This property determines how the icon and text are displayed within the button.
65  *
66  * Permitted values are:
67  * * ``Button.IconOnly``
68  * * ``Button.TextOnly``
69  * * ``Button.TextBesideIcon``
70  * * ``Button.TextUnderIcon``
71  *
72  * default: ``Controls.Button.TextBesideIcon``
73  *
74  * @see QtQuick.Controls.AbstractButton
75  * @property int display
76  */
77  property int display: QQC2.Button.TextBesideIcon
78 
79  /**
80  * @brief This property holds the alignment of the buttons.
81  *
82  * When there is more space available than required by the visible delegates,
83  * we need to determine how to place the delegates.
84  *
85  * When there is more space available than required by the visible action delegates,
86  * we need to determine where to position them.
87  *
88  * default: ``Qt.AlignRight``
89  *
90  * @see Qt::AlignmentFlag
91  * @property int alignment
92  */
93  property alias alignment: layout.alignment
94 
95  /**
96  * @brief This property holds the position of the toolbar.
97  *
98  * If this ActionToolBar is the contentItem of a QQC2 Toolbar, the position is bound to the ToolBar's position
99  *
100  * Permitted values are:
101  * * ``ToolBar.Header``: The toolbar is at the top, as a window or page header.
102  * * ``ToolBar.Footer``: The toolbar is at the bottom, as a window or page footer.
103  *
104  * @property int position
105  */
106  property int position: parent && parent.hasOwnProperty("position")
107  ? parent.position
108  : QQC2.ToolBar.Header
109 
110  /**
111  * @brief This property holds the maximum width of the content of this ToolBar.
112  *
113  * If the toolbar's width is larger than this value, empty space will
114  * be added on the sides, according to the Alignment property.
115  *
116  * The value of this property is derived from the ToolBar's actions and their properties.
117  *
118  * @property int maximumContentWidth
119  */
120  readonly property alias maximumContentWidth: layout.implicitWidth
121 
122  /**
123  * @brief This property holds the name of the icon to use for the overflow menu button.
124  *
125  * default: ``"overflow-menu"``
126  *
127  * @since 5.65
128  * @since 2.12
129  */
130  property string overflowIconName: "overflow-menu"
131 
132  /**
133  * @brief This property holds the combined width of all visible delegates.
134  * @property int visibleWidth
135  */
136  property alias visibleWidth: layout.visibleWidth
137 
138  /**
139  * @brief This property sets the handling method for items that do not match the toolbar's height.
140  *
141  * When toolbar items do not match the height of the toolbar, there are
142  * several ways we can deal with this. This property sets the preferred way.
143  *
144  * Permitted values are:
145  * * ``HeightMode.AlwaysCenter``
146  * * ``HeightMode.AlwaysFill``
147  * * ``AlwaysFill.ConstrainIfLarger``
148  *
149  * default: ``HeightMode::ConstrainIfLarger``
150  *
151  * @see ToolBarLayout::heightMode
152  * @see ToolBarLayout::HeightMode
153  * @property ToolBarLayout::HeightMode heightMode
154  */
155  property alias heightMode: layout.heightMode
156 //END properties
157 
158  implicitHeight: layout.implicitHeight
159  implicitWidth: layout.implicitWidth
160 
161  Layout.minimumWidth: layout.minimumWidth
162  Layout.preferredWidth: 0
163  Layout.fillWidth: true
164 
165  leftPadding: 0
166  rightPadding: 0
167  topPadding: 0
168  bottomPadding: 0
169 
170  contentItem: Kirigami.ToolBarLayout {
171  id: layout
172  spacing: Kirigami.Units.smallSpacing
173  layoutDirection: root.LayoutMirroring.enabled ? Qt.RightToLeft : Qt.LeftToRight
174 
175  fullDelegate: P.PrivateActionToolButton {
176  flat: root.flat
177  display: root.display
178  action: Kirigami.ToolBarLayout.action
179  }
180 
181  iconDelegate: P.PrivateActionToolButton {
182  flat: root.flat
183  display: QQC2.Button.IconOnly
184  action: Kirigami.ToolBarLayout.action
185 
186  showMenuArrow: false
187 
188  menuActions: {
189  if (action.displayComponent) {
190  return [action]
191  }
192 
193  if (action.hasOwnProperty("children") && action.children.length > 0) {
194  return Array.prototype.map.call(action.children, i => i)
195  }
196 
197  return []
198  }
199  }
200 
201  moreButton: P.PrivateActionToolButton {
202  flat: root.flat
203 
204  action: Kirigami.Action {
205  tooltip: qsTr("More Actions")
206  icon.name: root.overflowIconName
207  displayHint: Kirigami.DisplayHint.IconOnly | Kirigami.DisplayHint.HideChildIndicator
208  }
209 
210  menuActions: {
211  if (root.hiddenActions.length === 0) {
212  return root.actions
213  } else {
214  const result = []
215  result.concat(Array.prototype.map.call(root.actions, i => i))
216  result.concat(Array.prototype.map.call(hiddenActions, i => i))
217  return result
218  }
219  }
220 
221  menuComponent: P.ActionsMenu {
222  submenuComponent: P.ActionsMenu {
223  Binding {
224  target: parentItem
225  property: "visible"
226  value: layout.hiddenActions.includes(parentAction)
227  && (parentAction.visible === undefined || parentAction.visible)
228  restoreMode: Binding.RestoreBinding
229  }
230  }
231 
232  itemDelegate: P.ActionMenuItem {
233  visible: layout.hiddenActions.includes(action)
234  && (action.visible === undefined || action.visible)
235  }
236 
237  loaderDelegate: Loader {
238  property var action
239  height: visible ? implicitHeight : 0
240  visible: layout.hiddenActions.includes(action)
241  && (action.visible === undefined || action.visible)
242  }
243 
244  separatorDelegate: QQC2.MenuSeparator {
245  property var action
246  visible: layout.hiddenActions.includes(action)
247  && (action.visible === undefined || action.visible)
248  }
249  }
250  }
251  }
252 }
An item that creates delegates for actions and lays them out in a row.
Definition: toolbarlayout.h:46
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:14:23 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.