MauiKit Controls

ActionGroup.qml
1/*
2 * Copyright 2018-2020 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick
21import QtQuick.Controls
22import QtQuick.Layouts
23
24import org.mauikit.controls as Maui
25
26Pane
27{
28 id: control
29
30 implicitWidth: implicitContentWidth + leftPadding + rightPadding
31 implicitHeight: implicitContentHeight + topPadding + bottomPadding
32
33 spacing: Maui.Style.space.medium
34 padding: 0
35 background: null
36
37 /**
38 *
39 */
40 default property list<QtObject> items
41
42 /**
43 *
44 */
45 property list<QtObject> hiddenItems
46
47 /**
48 *
49 */
50 property int currentIndex : 0
51
52 /**
53 *
54 */
55 readonly property int count : control.items.length + control.hiddenItems.length
56
57 property int display: ToolButton.TextBesideIcon
58 /**
59 *
60 */
61 signal clicked(int index)
62
63 /**
64 *
65 */
66 signal pressAndHold(int index)
67
68 signal itemVisibilityChanged(int index,bool visible)
69 /**
70 *
71 */
72 signal doubleClicked(int index)
73
74 Behavior on implicitWidth
75 {
76 NumberAnimation
77 {
78 duration: Maui.Style.units.shortDuration
79 easing.type: Easing.InOutQuad
80 }
81 }
82
83 property Component delegate : ToolButton
84 {
85 id: _buttonDelegate
86 // Layout.alignment: Qt.AlignCenter
87 autoExclusive: true
88 visible: modelData.visible
89 onVisibleChanged: control.itemVisibilityChanged(index, visible)
90 checked: index === control.currentIndex
91
92 leftPadding: Maui.Style.space.big
93 rightPadding: Maui.Style.space.big
94
95 icon.name: modelData.Maui.Controls.iconName
96 text: modelData.Maui.Controls.title
97
98 display: checked ? (!isWide ? ToolButton.IconOnly : ToolButton.TextBesideIcon) : ToolButton.IconOnly
99
100 Maui.Controls.badgeText: modelData.Maui.Controls.badgeText
101
102 onClicked:
103 {
104 if(index === control.currentIndex )
105 {
106 return
107 }
108
109 control.currentIndex = index
110 control.clicked(index)
111 }
112
113 DropArea
114 {
115 anchors.fill: parent
116 onEntered: control.currentIndex = index
117 }
118 }
119
120 contentItem: RowLayout
121 {
122 id: _layout
123 spacing: control.spacing
124
125 Repeater
126 {
127 model: control.items
128 delegate: control.delegate
129 }
130
131 ToolButton
132 {
133 // Layout.alignment: Qt.AlignCenter
134// padding: Maui.Style.space.medium
135 leftPadding: Maui.Style.space.big
136 rightPadding: Maui.Style.space.big
137 readonly property QtObject obj : control.currentIndex >= control.items.length && control.currentIndex < control.count? control.hiddenItems[control.currentIndex - control.items.length] : null
138
139 visible: obj && obj.visible
140 checked: visible
141 autoExclusive: true
142 icon.name: obj ? obj.Maui.Controls.iconName : ""
143
144 // flat: display === ToolButton.IconOnly
145
146 display: checked ? (!isWide ? ToolButton.IconOnly : ToolButton.TextBesideIcon) : ToolButton.IconOnly
147
148 text: obj ? obj.Maui.Controls.title : ""
149 }
150
151 Maui.ToolButtonMenu
152 {
153 id: _menuButton
154 icon.name: "overflow-menu"
155 visible: control.hiddenItems.length > 0
156
157 Layout.alignment: Qt.AlignCenter
158 display: checked ? ToolButton.TextBesideIcon : ToolButton.IconOnly
159
160 Behavior on implicitWidth
161 {
162 NumberAnimation
163 {
164 duration: Maui.Style.units.shortDuration
165 easing.type: Easing.InOutQuad
166 }
167 }
168
169 Repeater
170 {
171 model: control.hiddenItems
172
173 MenuItem
174 {
175 text: modelData.Maui.Controls.title
176 icon.name: modelData.Maui.Controls.iconName
177 autoExclusive: true
178 checkable: true
179 checked: control.currentIndex === control.items.length + index
180 showIcon: true
181
182 onTriggered:
183 {
184 if(control.items.length + index === control.currentIndex)
185 {
186 return
187 }
188
189 control.currentIndex = control.items.length + index
190 control.clicked(control.currentIndex)
191 }
192 }
193 }
194 }
195 }
196}
The Controls class.
Definition controls.h:18
A control to host into a Menu popup, a set of MenuItem or Actions as its children.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.