Warning, /frameworks/kirigami/src/controls/private/PrivateActionToolButton.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 0008 import QtQml 0009 import QtQuick.Layouts 0010 import QtQuick.Controls as QQC2 0011 import QtQuick.Templates as T 0012 0013 import org.kde.kirigami as Kirigami 0014 0015 QQC2.ToolButton { 0016 id: control 0017 0018 signal menuAboutToShow() 0019 0020 hoverEnabled: true 0021 0022 display: QQC2.ToolButton.TextBesideIcon 0023 0024 property bool showMenuArrow: !Kirigami.DisplayHint.displayHintSet(action, Kirigami.DisplayHint.HideChildIndicator) 0025 0026 property list<T.Action> menuActions: { 0027 if (action instanceof Kirigami.Action) { 0028 return action.children; 0029 } 0030 return [] 0031 } 0032 0033 property Component menuComponent: ActionsMenu { 0034 submenuComponent: ActionsMenu { } 0035 } 0036 0037 property QtObject menu: null 0038 0039 // We create the menu instance only when there are any actual menu items. 0040 // This also happens in the background, avoiding slowdowns due to menu item 0041 // creation on the main thread. 0042 onMenuActionsChanged: { 0043 if (menuComponent && menuActions.length > 0) { 0044 if (!menu) { 0045 const setupIncubatedMenu = incubatedMenu => { 0046 menu = incubatedMenu 0047 // Important: We handle the press on parent in the parent, so ignore it here. 0048 menu.closePolicy = QQC2.Popup.CloseOnEscape | QQC2.Popup.CloseOnPressOutsideParent 0049 menu.closed.connect(() => control.checked = false) 0050 menu.actions = control.menuActions 0051 } 0052 const incubator = menuComponent.incubateObject(control, { actions: menuActions }) 0053 if (incubator.status !== Component.Ready) { 0054 incubator.onStatusChanged = status => { 0055 if (status === Component.Ready) { 0056 setupIncubatedMenu(incubator.object) 0057 } 0058 } 0059 } else { 0060 setupIncubatedMenu(incubator.object); 0061 } 0062 } else { 0063 menu.actions = menuActions 0064 } 0065 } 0066 } 0067 0068 visible: action instanceof Kirigami.Action ? action.visible : true 0069 0070 // Workaround for QTBUG-85941 0071 Binding { 0072 target: control 0073 property: "checkable" 0074 value: (control.action?.checkable ?? false) || (control.menuActions.length > 0) 0075 restoreMode: Binding.RestoreBinding 0076 } 0077 0078 onToggled: { 0079 if (menuActions.length > 0 && menu) { 0080 if (checked) { 0081 control.menuAboutToShow(); 0082 menu.popup(control, 0, control.height) 0083 } else { 0084 menu.dismiss() 0085 } 0086 } 0087 } 0088 0089 QQC2.ToolTip { 0090 visible: control.hovered && text.length > 0 && !(control.menu && control.menu.visible) && !control.pressed 0091 text: { 0092 const a = control.action; 0093 if (a) { 0094 if (a.tooltip) { 0095 return a.tooltip; 0096 } else if (control.display === QQC2.Button.IconOnly) { 0097 return a.text; 0098 } 0099 } 0100 return ""; 0101 } 0102 } 0103 0104 // This will set showMenuArrow when using qqc2-desktop-style. 0105 Accessible.role: (control.showMenuArrow && control.menuActions.length > 0) ? Accessible.ButtonMenu : Accessible.Button 0106 Accessible.ignored: !visible 0107 }