MauiKit Controls

TabButton.qml
1
2import QtQuick
3import QtQuick.Controls as QQC
4import QtQuick.Layouts
5
6import org.mauikit.controls as Maui
7
8/**
9 * @inherit QtQuick.Controls.TabButton
10 * @brief A expanded implementation of the QQC2 TabButton with a predefined horizontal layout.
11 *
12 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-tabbutton.html">This control inherits from QQC2 TabButton, to checkout its inherited properties refer to the Qt Docs.</a>
13 *
14 * By default the layout of this control is divided into three sections.
15 * Extra items can be appended to the left and right side areas, while the center area is reserved for the title text.
16 * @see leftContent
17 * @see rightContent
18 */
19QQC.TabButton
20{
21 id: control
22
23 /**
24 * @brief An alias exposed to append more elements into the main container of this control.
25 * @property list<QtObject> TabButton::content
26 */
27 default property alias content: _content.data
29 /**
30 * @brief Use this to append items to the left area of this control.
31 * @property list<QtObject> TabButton::leftContent
32 */
33 property alias leftContent: _leftContent.data
34
35 /**
36 * @brief Use this to append items to the right area of this control.
37 * @property list<QtObject> TabButton::rightContent
38 */
39 property alias rightContent: _rightContent.data
40
41 /**
42 * @brief Use this to add items between the background and the control contents.
43 * @property list<QtObject> TabButton::underlayContent
44 */
45 property alias underlayContent: _underlay.data
46
47 /**
48 * @brief Whether a close button should be shown in the far left area.
49 * If it is visible and pressed, a signal is emitted.
50 * @see closeClicked
51 * By default this is set to `true`.
52 */
53 property bool closeButtonVisible: true
54
55 /**
56 * @brief Emitted when the close button is pressed.
57 * @see closeButtonVisible
58 */
59 signal closeClicked()
60
61 /**
62 * @brief Emitted when the area of the control has been right clicked.
63 * This can be consumed in order to open a contextual menu, for example.
64 * @param mouse The object with information of the event.
65 */
66 signal rightClicked(var mouse)
67
68 contentItem: MouseArea
69 {
70 implicitWidth: _layout.implicitWidth
71 implicitHeight: _layout.implicitHeight
72
73 acceptedButtons: Qt.RightButton
74 propagateComposedEvents: true
75 preventStealing: false
76
77 onClicked: (mouse) =>
78 {
79 if(mouse.button === Qt.RightButton)
80 {
81 control.rightClicked(mouse)
82 }
83
84 mouse.accepted = false
85 }
86
87 Item
88 {
89 id: _underlay
90 anchors.fill: parent
91 }
92
93 RowLayout
94 {
95 id: _layout
96 anchors.fill: parent
97 anchors.rightMargin: _badgeLoader.visible ? 8 : 0
98
99 spacing: control.spacing
100
101 Row
102 {
103 id: _leftContent
104 }
105
106 Maui.IconLabel
107 {
108 id: _content
109 Layout.fillWidth: true
110 Layout.fillHeight: true
111 opacity: control.checked || control.hovered ? 1 : 0.7
112
113 text: control.text
114 icon: control.icon
115 color: control.Maui.Theme.textColor
116 alignment: Qt.AlignHCenter
117 display: QQC.ToolButton.TextBesideIcon
118 font: control.font
119 }
120
121 Row
122 {
123 id: _rightContent
124 }
125
126 Loader
127 {
128 asynchronous: true
129 active: control.closeButtonVisible
130
131 Layout.alignment: Qt.AlignCenter
132
133 sourceComponent: Maui.CloseButton
134 {
135 opacity: Maui.Handy.isMobile ? 1 : (control.hovered || control.checked ? 1 : 0)
136 padding: 0
137
138 implicitHeight: 16
139 implicitWidth: 16
140
141 icon.width: 16
142 icon.height: 16
143
144 onClicked: control.closeClicked()
145
146 Behavior on opacity
147 {
148 NumberAnimation
149 {
150 duration: Maui.Style.units.longDuration
151 easing.type: Easing.InOutQuad
152 }
153 }
154 }
155 }
156 }
157 }
158
159 Loader
160 {
161 id: _badgeLoader
162
163 asynchronous: true
164
165 active: control.Maui.Controls.badgeText && control.Maui.Controls.badgeText.length > 0 && control.visible
166 visible: active
167
168 anchors.horizontalCenter: parent.right
169 anchors.verticalCenter: parent.top
170 anchors.verticalCenterOffset: 10
171 anchors.horizontalCenterOffset: -5
172
173 sourceComponent: Maui.Badge
174 {
175 text: control.Maui.Controls.badgeText
176
177 padding: 2
178 font.pointSize: Maui.Style.fontSizes.tiny
179
180 Maui.Theme.colorSet: Maui.Theme.View
181 Maui.Theme.backgroundColor: Maui.Theme.negativeBackgroundColor
182 Maui.Theme.textColor: Maui.Theme.negativeTextColor
183
184 OpacityAnimator on opacity
185 {
186 from: 0
187 to: 1
188 duration: Maui.Style.units.longDuration
189 running: parent.visible
190 }
191
192 ScaleAnimator on scale
193 {
194 from: 0.5
195 to: 1
196 duration: Maui.Style.units.longDuration
197 running: parent.visible
198 easing.type: Easing.OutInQuad
199 }
200 }
201 }
202}
203
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Mar 14 2025 11:53:05 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.