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
73 value: (control.action?.checkable ??
false) || (control.menuActions.length > 0)
74 restoreMode: Binding.RestoreBinding
82 function onVisibleChanged() {
83 if (!control.visible && control.menu && control.menu.visible) {
84 control.menu.dismiss()
90 if (menuActions.length > 0 && menu) {
92 control.menuAboutToShow();
93 menu.popup(control, 0, control.height)
101 visible: control.hovered && text.length > 0 && !(control.menu && control.menu.visible) && !control.pressed
103 const a = control.action;
107 }
else if (control.display === QQC2.Button.IconOnly) {
116 Accessible.role: (control.showMenuArrow && control.menuActions.length > 0) ? Accessible.ButtonMenu : Accessible.
Button
117 Accessible.ignored: !visible
Q_SCRIPTABLE CaptureState status()