Kirigami2

Action.qml
1/*
2 * SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 * SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8import QtQml
9import QtQuick
10import QtQuick.Controls as QQC2
11import QtQuick.Templates as T
12import org.kde.kirigami as Kirigami
13import org.kde.kirigami.private as P
14
15/**
16 * @brief An item that represents an abstract Action
17 * @inherit QtQuick.QQC2.Action
18 */
19QQC2.Action {
20//BEGIN properties
21 /**
22 * @brief This property holds whether the graphic representation of the action
23 * is supposed to be visible.
24 *
25 * It's up to the action representation to honor this property.
26 *
27 * default: ``true``
28 */
29 property bool visible: !fromQAction || fromQAction.visible
30
31 /**
32 * @brief This property holds the tooltip text that is shown when the cursor is hovering over the control.
33 *
34 * Leaving this undefined or setting it to an empty string means that no tooltip will be shown when
35 * the cursor is hovering over the control that triggers the tooltip.
36 * @warning Tooltips may not be supported on all platforms.
37 */
38 property string tooltip
39
40 /**
41 * @brief This property sets whether this action is a separator action.
42 *
43 * default: ``false``
44 */
45 property bool separator: false
46
47 /**
48 * @brief This property holds whether auto-exclusivity is enabled.
49 *
50 * If auto-exclusivity is enabled, checkable actions that belong to the
51 * same parent item behave as if they were part of the same ButtonGroup.
52 * Only one action can be checked at any time; checking another action
53 * automatically unchecks the previously checked one.
54 *
55 * default: ``false``
56 */
57 property bool autoExclusive: false
58
59 /**
60 * @brief This property sets whether this action becomes a title displaying
61 * its child actions as sub-items in GlobalDrawers and ContextDrawers.
62 *
63 * default: ``false``
64 *
65 * @since 2.6
66 */
67 property bool expandible: false
68
69 /**
70 * @brief This property holds the parent action.
71 */
72 property T.Action parent
73
74 /**
75 * @brief This property sets this action's display type.
76 *
77 * These are provided to implementations to indicate a preference for certain display
78 * styles.
79 *
80 * default: ``Kirigami.DisplayHint.NoPreference``
81 *
82 * @note This property contains only preferences, implementations may choose to disregard them.
83 * @see org::kde::kirigami::DisplayHint
84 * @since 2.12
85 */
86 property int displayHint: Kirigami.DisplayHint.NoPreference
87
88 /**
89 * @brief This property holds the component that should be used for displaying this action.
90 * @note This can be used to display custom components in the toolbar.
91 * @since 5.65
92 * @since 2.12
93 */
94 property Component displayComponent
95
96 /**
97 * @brief This property holds a list of child actions.
98 *
99 * This is useful for tree-like menus, such as the GlobalDrawer.
100 *
101 * Example usage:
102 * @code
103 * import QtQuick.Controls as QQC2
104 * import org.kde.kirigami as Kirigami
105 *
106 * Kirigami.Action {
107 * text: "Tools"
108 *
109 * QQC2.Action {
110 * text: "Action1"
111 * }
112 * Kirigami.Action {
113 * text: "Action2"
114 * }
115 * }
116 * @endcode
117 * @property list<T.Action> children
118 */
119 default property list<T.Action> children
120
121 /**
122 * This property holds a QAction
123 *
124 * When provided Kirigami.Action will be initialized from the given QAction.
125 *
126 * @since Kirigami 6.4.0
127 */
128 property QtObject fromQAction
129//END properties
130
131 onChildrenChanged: {
132 children
133 .filter(action => action instanceof Kirigami.Action)
134 .forEach(action => {
135 action.parent = this;
136 });
137 }
138
139 /**
140 * @brief This property holds the action's visible child actions.
141 * @property list<T.Action> visibleChildren
142 */
143 readonly property list<T.Action> visibleChildren: children
144 .filter(action => !(action instanceof Kirigami.Action) || action.visible)
145
146 shortcut: fromQAction?.shortcut
147 text: fromQAction?.text ?? ''
148 icon.name: fromQAction ? P.ActionHelper.iconName(fromQAction.icon) : ''
149 onTriggered: if (fromQAction) {
150 fromQAction.trigger();
151 }
152 checkable: fromQAction?.checkable ?? false
153 checked: fromQAction?.checked ?? false
154 enabled: !fromQAction || fromQAction.enabled
155
156 readonly property Shortcut alternateShortcut : Shortcut {
157 sequences: P.ActionHelper.alternateShortcuts(fromQAction)
158 onActivated: root.trigger()
159 }
160}
KIOCORE_EXPORT QStringList list(const QString &fileClass)
const QList< QKeySequence > & shortcut(StandardShortcut id)
QStringList filter(QStringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:51:21 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.