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

KDE's Doxygen guidelines are available online.