Warning, /frameworks/kirigami/src/controls/ActionToolBar.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.7 0008 import QtQml 2.15 0009 import QtQuick.Layouts 1.2 0010 import QtQuick.Controls 2.4 as QQC2 0011 import org.kde.kirigami 2.14 as Kirigami 0012 import "private" as P 0013 0014 /** 0015 * @brief A toolbar built out of a list of actions. 0016 * 0017 * The default representation for visible actions is a QtQuick.Controls.ToolButton, 0018 * but it can be changed by setting Action::displayComponent to a different component. 0019 * 0020 * The ActionToolBar component will try to display as many 0021 * action delegates as possible but it will place those that do not fit into an 0022 * overflow menu. 0023 * 0024 * How actions are displayed can be changed by setting the `displayHint` 0025 * in an action. For example, when setting it to ``DisplayHint.KeepVisible``, 0026 * it will try to keep that action in view as long as possible, using an icon-only 0027 * button if the full-sized delegate does not fit. 0028 * 0029 * @see <a href="https://develop.kde.org/hig/components/navigation/toolbar">KDE Human Interface Guidelines on Toolbars</a> 0030 * @see ToolBarLayout 0031 * @since org.kde.kirigami 2.5 0032 * @inherit QtQuick.Controls.Control 0033 */ 0034 QQC2.Control { 0035 id: root 0036 0037 //BEGIN properties 0038 /** 0039 * @brief This property holds a list of visible actions. 0040 * 0041 * The ActionToolBar will try to display as many actions as possible. 0042 * Those that do not fit go into a overflow menu. 0043 * 0044 * @property list<Action> actions 0045 */ 0046 property alias actions: layout.actions 0047 0048 /** 0049 * @brief This property holds a list of hidden actions. 0050 * 0051 * These actions will always be displayed in the overflow menu, even if there is enough space. 0052 * 0053 * @deprecated Since 2.14, set ``displayHint`` to ``DisplayHint.AlwaysHide`` in actions instead. 0054 * @since org.kde.kirigami 2.6 0055 * @property list<Action> hiddenActions 0056 */ 0057 property list<QtObject> hiddenActions 0058 onHiddenActionsChanged: print("ActionToolBar::hiddenActions is deprecated, use the AlwaysHide hint on your actions instead") 0059 0060 /** 0061 * @brief This property holds whether the buttons will have a flat appearance. 0062 * 0063 * default: ``true`` 0064 */ 0065 property bool flat: true 0066 0067 /** 0068 * @brief This property determines how the icon and text are displayed within the button. 0069 * 0070 * The following values are allowed: 0071 * * ``Button.IconOnly`` 0072 * * ``Button.TextOnly`` 0073 * * ``Button.TextBesideIcon`` 0074 * * ``Button.TextUnderIcon`` 0075 * 0076 * default: ``Controls.Button.TextBesideIcon`` 0077 * 0078 * @see <a href="https://doc.qt.io/qt-5/qml-qtquick-controls2-abstractbutton.html#display-prop">AbstractButton.display</a> 0079 */ 0080 property int display: QQC2.Button.TextBesideIcon 0081 0082 /** 0083 * @brief This property holds the alignment of the buttons. 0084 * 0085 * When there is more space available than required by the visible delegates, 0086 * we need to determine how to place the delegates. 0087 * 0088 * When there is more space available than required by the visible action delegates, 0089 * we need to determine where to position them. 0090 * 0091 * default: ``Qt.AlignRight`` 0092 * 0093 * @see <a href="https://doc.qt.io/qt-5/qt.html#AlignmentFlag-enum">Qt::Alignment</a> 0094 * @property Qt::Alignment alignment 0095 */ 0096 property alias alignment: layout.alignment 0097 0098 /** 0099 * @brief This property holds the position of the toolbar. 0100 * 0101 * If this ActionToolBar is the contentItem of a QQC2 Toolbar, the position is bound to the ToolBar's position 0102 * 0103 * The following values are allowed: 0104 * * ``Controls.ToolBar.Header``: The toolbar is at the top, as a window or page header. 0105 * * ``Controls.ToolBar.Footer``: The toolbar is at the bottom, as a window or page footer. 0106 * 0107 * @property int position 0108 */ 0109 property int position: parent && parent.hasOwnProperty("position") 0110 ? parent.position 0111 : QQC2.ToolBar.Header 0112 0113 /** 0114 * @brief This property holds the maximum width of the content of this ToolBar. 0115 * 0116 * If the toolbar's width is larger than this value, empty space will 0117 * be added on the sides, according to the Alignment property. 0118 * 0119 * The value of this property is derived from the ToolBar's actions and their properties. 0120 * 0121 * @property int maximumContentWidth 0122 */ 0123 readonly property alias maximumContentWidth: layout.implicitWidth 0124 0125 /** 0126 * @brief This property holds the Freedesktop standard icon name to use for the overflow menu button. 0127 * 0128 * default: ``"overflow-menu"`` 0129 * 0130 * @since KDE Frameworks 5.65 0131 * @since org.kde.kirigami 2.12 0132 */ 0133 property string overflowIconName: "overflow-menu" 0134 0135 /** 0136 * @brief This property holds the combined width of all visible delegates. 0137 * @property int visibleWidth 0138 */ 0139 property alias visibleWidth: layout.visibleWidth 0140 0141 /** 0142 * @brief This property sets the handling method for items that do not match the toolbar's height. 0143 * 0144 * When toolbar items do not match the height of the toolbar, there are 0145 * several ways we can deal with this. This property sets the preferred way. 0146 * 0147 * The following values are allowed: 0148 * * ``HeightMode.AlwaysCenter`` 0149 * * ``HeightMode.AlwaysFill`` 0150 * * ``HeightMode.ConstrainIfLarger`` 0151 * 0152 * default: ``HeightMode::ConstrainIfLarger`` 0153 * 0154 * @see ToolBarLayout::heightMode 0155 * @see ToolBarLayout::HeightMode 0156 * @property ToolBarLayout::HeightMode heightMode 0157 */ 0158 property alias heightMode: layout.heightMode 0159 //END properties 0160 0161 implicitHeight: layout.implicitHeight 0162 implicitWidth: layout.implicitWidth 0163 0164 Layout.minimumWidth: layout.minimumWidth 0165 Layout.preferredWidth: 0 0166 Layout.fillWidth: true 0167 0168 leftPadding: 0 0169 rightPadding: 0 0170 topPadding: 0 0171 bottomPadding: 0 0172 0173 contentItem: Kirigami.ToolBarLayout { 0174 id: layout 0175 spacing: Kirigami.Units.smallSpacing 0176 layoutDirection: root.LayoutMirroring.enabled ? Qt.RightToLeft : Qt.LeftToRight 0177 0178 fullDelegate: P.PrivateActionToolButton { 0179 flat: root.flat 0180 display: root.display 0181 action: Kirigami.ToolBarLayout.action 0182 } 0183 0184 iconDelegate: P.PrivateActionToolButton { 0185 flat: root.flat 0186 display: QQC2.Button.IconOnly 0187 action: Kirigami.ToolBarLayout.action 0188 0189 showMenuArrow: false 0190 0191 menuActions: { 0192 if (action.displayComponent) { 0193 return [action] 0194 } 0195 0196 if (action.hasOwnProperty("children") && action.children.length > 0) { 0197 return Array.prototype.map.call(action.children, i => i) 0198 } 0199 0200 return [] 0201 } 0202 } 0203 0204 moreButton: P.PrivateActionToolButton { 0205 flat: root.flat 0206 0207 action: Kirigami.Action { 0208 tooltip: qsTr("More Actions") 0209 icon.name: root.overflowIconName 0210 displayHint: Kirigami.DisplayHint.IconOnly | Kirigami.DisplayHint.HideChildIndicator 0211 } 0212 0213 menuActions: { 0214 if (root.hiddenActions.length === 0) { 0215 return root.actions 0216 } else { 0217 const result = [] 0218 result.concat(Array.prototype.map.call(root.actions, i => i)) 0219 result.concat(Array.prototype.map.call(hiddenActions, i => i)) 0220 return result 0221 } 0222 } 0223 0224 menuComponent: P.ActionsMenu { 0225 submenuComponent: P.ActionsMenu { 0226 Binding { 0227 target: parentItem 0228 property: "visible" 0229 value: layout.hiddenActions.includes(parentAction) 0230 && (parentAction.visible === undefined || parentAction.visible) 0231 restoreMode: Binding.RestoreBinding 0232 } 0233 } 0234 0235 itemDelegate: P.ActionMenuItem { 0236 visible: layout.hiddenActions.includes(action) 0237 && (action.visible === undefined || action.visible) 0238 } 0239 0240 loaderDelegate: Loader { 0241 property var action 0242 height: visible ? implicitHeight : 0 0243 visible: layout.hiddenActions.includes(action) 0244 && (action.visible === undefined || action.visible) 0245 } 0246 0247 separatorDelegate: QQC2.MenuSeparator { 0248 property var action 0249 visible: layout.hiddenActions.includes(action) 0250 && (action.visible === undefined || action.visible) 0251 } 0252 } 0253 } 0254 } 0255 }