Warning, /maui/mauikit/src/controls.5/ToolButtonMenu.qml is written in an unsupported language. File is not indexed.

0001 import QtQuick 2.15
0002 import QtQuick.Controls 2.15
0003 
0004 import org.mauikit.controls 1.3 as Maui
0005 
0006 
0007 /*!
0008 \since org.mauikit.controls 1.0
0009 \inqmlmodule org.mauikit.controls
0010 \brief A tool button that triggers a contextual menu.
0011 
0012 This provides a quick way to have a menu attached to a tool button.
0013 All child items will be positioned in a menu.
0014 */
0015 ToolButton
0016 {
0017     id: control
0018 
0019     /*!
0020       \qmlproperty list<QtObject> ToolButtonMenu::content
0021       List of items, such as MenuItems to populate the contextual menu.
0022       This is the default property, so declaring the menu entries is straight forward.
0023     */
0024     default property alias content : _menu.contentData
0025 
0026     /*!
0027       \qmlproperty Menu ToolButtonMenu::menu
0028 
0029       Alias to the actual menu component holding the menu entries.
0030       This can be modified for fine tuning the menu position or look.
0031     */
0032     property alias menu : _menu
0033     subMenu: _menu.count > 0
0034     focusPolicy: Qt.NoFocus
0035     checked: _menu.visible
0036     display: ToolButton.IconOnly
0037     
0038     onClicked:
0039     {
0040         if(_menu.visible)
0041         {
0042             close()
0043         }else
0044         {
0045             open()
0046         }
0047     }
0048 
0049     Maui.ContextualMenu
0050     {
0051         id: _menu
0052     }
0053     
0054     function open()
0055     {
0056         _menu.show(0, height + Maui.Style.space.medium)
0057         _menu.forceActiveFocus()
0058     }
0059     
0060     function popup()
0061     {
0062         _menu.popup()
0063         _menu.forceActiveFocus()
0064     }
0065 
0066     function close()
0067     {
0068         _menu.close()
0069     }
0070 }