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 /**
69 *
70 */
71 signal doubleClicked(int index)
72
73 Behavior on implicitWidth
74 {
75 NumberAnimation
76 {
77 duration: Maui.Style.units.shortDuration
78 easing.type: Easing.InOutQuad
79 }
80 }
81
82 property Component delegate : ToolButton
83 {
84 id: _buttonDelegate
85 // Layout.alignment: Qt.AlignCenter
86 autoExclusive: true
87 visible: modelData.visible
88 checked: index === control.currentIndex
89
90 leftPadding: Maui.Style.space.big
91 rightPadding: Maui.Style.space.big
92
93 icon.name: modelData.Maui.AppView.iconName
94 text: modelData.Maui.AppView.title
95
96 display: checked ? (!isWide ? ToolButton.IconOnly : ToolButton.TextBesideIcon) : ToolButton.IconOnly
97
98 Maui.Badge
99 {
100 visible: modelData.Maui.AppView.badgeText
101 text: modelData.Maui.AppView.badgeText
102
103 anchors.horizontalCenter: parent.right
104 anchors.verticalCenter: parent.top
105 anchors.verticalCenterOffset: 10
106 anchors.horizontalCenterOffset: -5
107
108 padding: 2
109 font.pointSize: Maui.Style.fontSizes.tiny
110
111
112 Maui.Theme.colorSet: Maui.Theme.View
113 Maui.Theme.backgroundColor: Maui.Theme.negativeBackgroundColor
114 Maui.Theme.textColor: Maui.Theme.negativeTextColor
115 }
116
117 onClicked:
118 {
119 if(index === control.currentIndex )
120 {
121 return
122 }
123
124 control.currentIndex = index
125 control.clicked(index)
126 }
127
128 DropArea
129 {
130 anchors.fill: parent
131 onEntered: control.currentIndex = index
132 }
133 }
134
135 contentItem: RowLayout
136 {
137 id: _layout
138 spacing: control.spacing
139
140 Repeater
141 {
142 model: control.items
143 delegate: control.delegate
144 }
145
146 ToolButton
147 {
148 // Layout.alignment: Qt.AlignCenter
149// padding: Maui.Style.space.medium
150 leftPadding: Maui.Style.space.big
151 rightPadding: Maui.Style.space.big
152 readonly property QtObject obj : control.currentIndex >= control.items.length && control.currentIndex < control.count? control.hiddenItems[control.currentIndex - control.items.length] : null
153
154 visible: obj && obj.visible
155 checked: visible
156 autoExclusive: true
157 icon.name: obj ? obj.Maui.AppView.iconName : ""
158
159 // flat: display === ToolButton.IconOnly
160
161 display: checked ? (!isWide ? ToolButton.IconOnly : ToolButton.TextBesideIcon) : ToolButton.IconOnly
162
163 text: obj ? obj.Maui.AppView.title : ""
164 }
165
166 Maui.ToolButtonMenu
167 {
168 id: _menuButton
169 icon.name: "overflow-menu"
170 visible: control.hiddenItems.length > 0
171
172 Layout.alignment: Qt.AlignCenter
173 display: checked ? ToolButton.TextBesideIcon : ToolButton.IconOnly
174
175 Behavior on implicitWidth
176 {
177 NumberAnimation
178 {
179 duration: Maui.Style.units.shortDuration
180 easing.type: Easing.InOutQuad
181 }
182 }
183
184 Repeater
185 {
186 model: control.hiddenItems
187
188 MenuItem
189 {
190 text: modelData.Maui.AppView.title
191 icon.name: modelData.Maui.AppView.iconName
192 autoExclusive: true
193 checkable: true
194 checked: control.currentIndex === control.items.length + index
195 showIcon: true
196
197 onTriggered:
198 {
199 if(control.items.length + index === control.currentIndex)
200 {
201 return
202 }
203
204 control.currentIndex = control.items.length + index
205 control.clicked(control.currentIndex)
206 }
207 }
208 }
209 }
210 }
211}
The AppView class.
Definition appview.h:42
A Badge item to display text - as a counter - or an icon as a notification hint.
Definition Badge.qml:49
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 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.