9import QtQuick.Controls as QQC2
10import QtQuick.Templates as T
12import org.kde.kirigami as Kirigami
17 signal menuAboutToShow()
21 display: QQC2.ToolButton.TextBesideIcon
23 property bool showMenuArrow: !Kirigami.DisplayHint.displayHintSet(action, Kirigami.DisplayHint.HideChildIndicator)
25 property list<T.Action> menuActions: {
26 if (action instanceof Kirigami.Action) {
27 return action.children;
32 property Component menuComponent: ActionsMenu {
33 submenuComponent: ActionsMenu { }
36 property T.Menu menu: null
41 onMenuActionsChanged: {
42 if (menuComponent && menuActions.length > 0) {
44 const setupIncubatedMenu = incubatedMenu => {
47 menu.closePolicy = QQC2.Popup.CloseOnEscape | QQC2.Popup.CloseOnPressOutsideParent
48 menu.closed.connect(() => control.checked =
false)
49 menu.actions = control.menuActions
51 const incubator = menuComponent.incubateObject(control, { actions: menuActions })
52 if (incubator.status !== Component.Ready) {
53 incubator.onStatusChanged =
status => {
54 if (
status === Component.Ready) {
55 setupIncubatedMenu(incubator.object)
59 setupIncubatedMenu(incubator.object);
62 menu.actions = menuActions
67 visible: action instanceof Kirigami.Action ? action.visible :
true
68 autoExclusive: action instanceof Kirigami.Action ? action.autoExclusive :
false
74 value: (control.action?.checkable ??
false) || (control.menuActions.length > 0)
75 restoreMode: Binding.RestoreBinding
83 function onVisibleChanged() {
84 if (!control.visible && control.menu && control.menu.visible) {
85 control.menu.dismiss()
91 if (menuActions.length > 0 && menu) {
93 control.menuAboutToShow();
94 menu.popup(control, 0, control.height)
102 visible: control.hovered && text.length > 0 && !(control.menu && control.menu.visible) && !control.pressed
104 const a = control.action;
108 }
else if (control.display === QQC2.Button.IconOnly) {
117 Accessible.role: (control.showMenuArrow && control.menuActions.length > 0) ? Accessible.ButtonMenu : Accessible.
Button
118 Accessible.ignored: !visible
119 Accessible.onPressAction: {
120 if (control.checkable) {
123 control.action.trigger();
Q_SCRIPTABLE CaptureState status()