MauiKit Controls

ToolButtonMenu.qml
1import QtQuick
2import QtQuick.Controls
3
4import org.mauikit.controls 1.3 as Maui
5
6/**
7 * @inherit QtQuick.Controls.ToolButton
8 * @since org.mauikit.controls 1.0
9 *
10 * @brief A control to host into a Menu popup, a set of MenuItem or Actions as its children.
11 *
12 * This control provides a quick way to have a menu attached to a tool button.
13 * All child items will be positioned inside a MauiKit ContextualMenu.
14 * @see ContextualMenu
15 *
16 * @image html Misc/toolbuttonmenu.png
17 *
18 * @code
19 * Maui.ToolButtonMenu
20 * {
21 * icon.name: "overflow-menu"
22 *
23 * MenuItem
24 * {
25 * text : "Menu1"
26 * }
27 *
28 * MenuItem
29 * {
30 * text : "Menu2"
31 * }
32 *
33 * MenuItem
34 * {
35 * text : "Menu3"
36 * }
37 * }
38 * @endcode
39 */
40ToolButton
41{
42 id: control
43
44 /**
45 * @brief List of items, such as MenuItem, or Action, to populate the contextual menu.
46 * This is the default property, so all the children will go into the menu.
47 * @property list<QtObject> ToolButtonMenu::content
48 */
49 default property alias content : _menu.contentData
50
51 /**
52 * @brief Alias to the actual menu component holding the menu entries.
53 * This can be modified for fine tuning the menu position or look.
54 * @property ContextualMenu ToolButtonMenu::menu
55 */
56 readonly property alias menu : _menu
57
58 subMenu: _menu.count > 0
59 focusPolicy: Qt.NoFocus
60 checked: _menu.visible
61 display: ToolButton.IconOnly
62
63 onClicked:
64 {
65 if(_menu.visible)
66 {
67 close()
68 }else
69 {
70 open()
71 }
72 }
74 Maui.ContextualMenu
75 {
76 id: _menu
77 }
78
79 /**
80 * @brief Forces to open the contextual menu.
81 * The menu will be positioned under the button.
82 * To open the menu at a position where it has been invoked, use the `popup` function instead.
83 * @see popup
84 */
85 function open()
86 {
87 _menu.show(0, height + Maui.Style.space.medium)
88 _menu.forceActiveFocus()
89 }
90
91 /**
92 * @brief Forces to popup the contextual menu.
93 * This means the menu will be opened and positioned at the event coordinates.
94 */
95 function popup()
96 {
97 _menu.popup()
98 _menu.forceActiveFocus()
99 }
100
101 /**
102 * @brief Forces to close the contextual menu.
103 */
104 function close()
105 {
106 _menu.close()
107 }
108}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.