MauiKit Controls

MenuItemActionRow.qml
1// Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
2// Copyright 2018-2020 Nitrux Latinoamericana S.C.
3//
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6import QtQuick
7import QtQuick.Controls
8import QtQuick.Layouts
9
10import org.mauikit.controls 1.3 as Maui
11
12/**
13 * @inherit QtQuick.Controls.MenuItem
14 * @brief A menu item entry for placing a set of actions as the children.
15 * The actions will be represented as row of QQC2 ToolButton.
16 *
17 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-menuitem.html">This controls inherits from QQC2 MenuItem, to checkout its inherited properties refer to the Qt Docs.</a>
18 *
19 * This is mean tot be used inside a Menu, where a group of similar actions can be placed together to save vertical sspace and make the UI a bit less cluttered.
20 *
21 * @image html Misc/menuitemactionrow.png
22 *
23 * @code
24 * Maui.ContextualMenu
25{
26 id: _contextualMenu
27
28 title: "Menu Title"
29 titleIconSource: "folder"
30
31 Maui.MenuItemActionRow
32 {
33 Action
34 {
35 text: "Action1"
36 icon.name: "love"
37 }
38
39 Action
40 {
41 text: "Action2"
42 icon.name: "folder"
43 }
44
45 Action
46 {
47 text: "Action3"
48 icon.name: "anchor"
49 }
50 }
51
52 MenuSeparator {}
53
54 MenuItem
55 {
56 text: "Action3"
57 icon.name: "actor"
58 }
59
60 MenuItem
61 {
62 text: "Action4"
63 icon.name: "anchor"
64 }
65}
66 * @endcode
68 @attention When an action here defined has been triggered, then the `triggered` signal fo the actual container -aka MenuItem - will also be emitted. This is done to support the auto-closing of the menu after a menu entry has been triggered.
69 */
70MenuItem
71{
72 id: control
73
74 /**
75 * @brief The list of actions to be represented.
76 * The children of this element should be a group of QQC2 Action.
77 * @note Checkout Qt documentation on the Action element.
78 */
79 default property list<Action> actions
80
81 opacity: control.enabled ? 1 : 0.5
82
83 hoverEnabled: !Maui.Handy.isMobile
84
85 implicitHeight: implicitContentHeight + topPadding + bottomPadding
86 implicitWidth: ListView.view ? ListView.view.width : Math.max(implicitBackgroundWidth + leftInset + rightInset, implicitContentWidth + leftPadding + rightPadding)
87
88 background: null
89
90 padding: 0
91 spacing: Maui.Style.space.small
92 font: Maui.Style.defaultFont
93
94 display : width > Maui.Style.units.gridUnit * 28 && control.actions.length <= 3 ? ToolButton.TextBesideIcon : (Maui.Handy.isMobile ? ToolButton.TextUnderIcon : ToolButton.IconOnly)
95
96 contentItem: Flow
97 {
98 id: _layout
99 spacing: control.spacing
100
101 Repeater
102 {
103 id: _repeater
104 model: control.actions
105
106 delegate: ToolButton
107 {
108 id: _delegate
109 Maui.Theme.inherit: true
110
111 action: modelData
112 display: control.display
113
114 ToolTip.delay: 1000
115 ToolTip.timeout: 5000
116 ToolTip.visible: ( _delegate.hovered ) && _delegate.text.length
117 ToolTip.text: modelData.text
118
119 background: Rectangle
120 {
121 radius: Maui.Style.radiusV
122 color: _delegate.checked || _delegate.pressed || _delegate.down ? Maui.Theme.highlightColor : _delegate.highlighted || _delegate.hovered ? Maui.Theme.hoverColor : Maui.Theme.alternateBackgroundColor
123 }
124
125 Connections
126 {
127 target: _delegate.action
128 ignoreUnknownSignals: true
129 function onTriggered()
130 {
131 control.triggered()
132 }
133 }
134 }
135 }
136 }
137}
int timeout
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.