MauiKit Controls

TabBar.qml
1import QtQuick
2import QtQuick.Layouts
3import QtQuick.Window
4
5import QtQuick.Controls as QQC
6
7import org.mauikit.controls as Maui
8import "private" as Private
9
10/**
11 * @inherit QtQuick.Controls.TabBar
12 * @brief Tab bar alternative to QQC TabBar, and based on it.
13 *
14 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-tabbar.html">This controls inherits from QQC2 TabBar, to checkout its inherited properties refer to the Qt Docs.</a>
15 *
16 * Mostly used together with the TabView control.
17 *
18 * The layout of this control is divided into three sections: left, middle and right area.
19 * The middle area is reserved for placing the tab buttons. The right and left side areas can be populated with any child item.
20 *
21 * All the child items are expected to be a TabButton or inherit from it. If you need to add an extra button, label or other item, consider adding them using the left and right containerizes.
22 * @see leftContent
23 * @see rightContent
24 *
25 * @code
26 * TabBar
27 * {
28 * leftContent: Button
29 * {
30 * text: "Button1"
31 * }
32 *
33 * rightContent: [
34 *
35 * Button
36 * {
37 * text: "Button2"
38 * },
39 *
40 * Button
41 * {
42 * text: "Button3"
43 * }
44 * ]
45 * }
46 * @endcode
47 *
48 * @section notes Notes
49 *
50 * The contents of this bar will become flickable/scrollable if the implicit width of the child elements is higher than the available width.
51 * When using it on a mobile device and a flick/swipe action is performed by the user, a signal will be emitted informing about the tab focused in the view port.
52 * @see newTabFocused
53 *
54 * @note This control supports the attached Controls.showCSD property to display the window control buttons when using CSD.
55 */
56QQC.TabBar
57{
58 id: control
59 Maui.Controls.level: Maui.Controls.showCSD ? Maui.Controls.Primary : Maui.Controls.Secondary
61 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
62 /**
63 * @brief An alias to manually add elements to the container directly. This is the middle section of the control.
64 * @property list<QtObject> TabBar::content
65 */
66 property alias content : _rightLayout.content
67
68 /**
69 * @brief An alias to add elements to the left area section.
70 * @property list<QtObject> TabBar::leftContent
71 */
72 property alias leftContent: _leftLayout.content
73
74 /**
75 * @brief An alias to add elements to the right area section.
76 * @property list<QtObject> TabBar::rightContent
77 */
78 property alias rightContent: _rightLayout.content
79
80 /**
81 * @brief Whether the control will react to touch events to flick the tabs.
82 * @property bool TabBar::interactive
83 */
84 property alias interactive: _content.interactive
86 /**
87 * @brief Whether to display a button which represents the "add new tab" action.
88 * If this button is clicked a signal is triggered.
89 * @see newTabClicked
90 */
91 property bool showNewTabButton : true
92
93 /**
94 * @brief Whether the tab buttons will be visible or not.
95 */
96 property bool showTabs : true
97
98 /**
99 * @brief This signal is emitted when the "add new tab" button has been clicked.
100 * @see showNewTabButton
101 */
102 signal newTabClicked()
103
104 /**
105 * @brief This signal is emitted when a new tab button is focused after a swipe/flick action has been performed.
106 * To set the new focused tab as the current one, use the index value passed as the argument to the currentIndex property. To make sure the tab is fully visible in the view port you can use the positioning function.
107 * @see positionViewAtIndex
108 */
109 signal newTabFocused(int index)
110
111 background: Rectangle
112 {
113 color: control.Maui.Controls.level ? control.Maui.Controls.level === Maui.Controls.Primary ? Maui.Theme.backgroundColor : Maui.Theme.alternateBackgroundColor : Maui.Theme.backgroundColor
114
115 Behavior on color
116 {
117 Maui.ColorTransition{}
118 }
119
120 Loader
121 {
122 z: 999
123
124 asynchronous: true
125 width: Maui.Style.iconSizes.medium
126 height: parent.height
127 active: !_content.atXEnd && !parent.fits
128 visible: active
129
130 anchors
131 {
132 right: parent.right
133 top: parent.top
134 bottom: parent.bottom
135 }
136
137 sourceComponent: Maui.EdgeShadow
138 {
139 edge: Qt.RightEdge
140 }
141 }
142
143 Loader
144 {
145 z: 999
146
147 asynchronous: true
148 width: Maui.Style.iconSizes.medium
149 height: parent.height
150 active: !_content.atXBeginning && !parent.fits
151 visible: active
152 anchors
153 {
154 left: parent.left
155 top: parent.top
156 bottom: parent.bottom
157 }
158
159 sourceComponent: Maui.EdgeShadow
160 {
161 edge: Qt.LeftEdge
162 }
163 }
164 }
165
166 contentItem: Item
167 {
168 implicitHeight: _layout.implicitHeight
169 readonly property bool fits : _content.contentWidth <= width
170
171 Loader
172 {
173 // active: control.draggable
174 asynchronous: true
175 anchors.fill: parent
176 sourceComponent: Item
177 {
178 DragHandler
179 {
180 target: null
181 grabPermissions: TapHandler.CanTakeOverFromAnything
182 onActiveChanged: if (active) { control.Window.window.startSystemMove(); }
183 }
184 }
185 }
186
187 RowLayout
188 {
189 id: _layout
190 width: parent.width
191 height: parent.height
192 spacing: control.spacing
193
194 Private.ToolBarSection
195 {
196 id: _leftLayout
197 spacing: control.spacing
198 Layout.fillHeight: true
199 Layout.maximumWidth: implicitWidth
200 Layout.minimumWidth: implicitWidth
201 }
202
203 QQC.ScrollView
204 {
205 Layout.fillWidth: true
206
207 orientation : Qt.Horizontal
208
209 QQC.ScrollBar.horizontal.policy: QQC.ScrollBar.AlwaysOff
210 QQC.ScrollBar.vertical.policy: QQC.ScrollBar.AlwaysOff
211
212 contentHeight: availableHeight
213 implicitHeight: _content.currentItem ? _content.currentItem.height : 0
214
215 ListView
216 {
217 id: _content
218 opacity: control.showTabs ? 1 : 0
219 visible: opacity > 0
220
221 clip: true
222
223 orientation: ListView.Horizontal
224
225 spacing: control.spacing
226
227 model: control.contentModel
228 currentIndex: control.currentIndex
229
230 interactive: Maui.Handy.isMobile
231 snapMode: ListView.SnapOneItem
232
233 highlightFollowsCurrentItem: true
234 highlightMoveDuration: 0
235 highlightResizeDuration : 0
236
237 boundsBehavior: Flickable.StopAtBounds
238 boundsMovement: Flickable.StopAtBounds
239
240 keyNavigationEnabled : true
241 keyNavigationWraps : true
242
243 onMovementEnded:
244 {
245 const newIndex = indexAt(contentX, contentY)
246 control.newTabFocused(newIndex)
247 }
248
249 moveDisplaced: Transition
250 {
251 NumberAnimation { properties: "x"; duration: Maui.Style.shortDuration }
252 }
253
254 Behavior on opacity
255 {
256 NumberAnimation
257 {
258 duration: Maui.Style.units.shortDuration
259 easing.type: Easing.InOutQuad
260 }
261 }
262 }
263 }
264
265 Loader
266 {
267 active: control.showNewTabButton
268 visible: active
269 asynchronous: true
270
271 sourceComponent: QQC.ToolButton
272 {
273 icon.name: "list-add"
274 onClicked: control.newTabClicked()
275 flat: true
276 }
277 }
278
279 Private.ToolBarSection
280 {
281 id: _rightLayout
282 spacing: control.spacing
283 Layout.fillHeight: true
284 Layout.maximumWidth: implicitWidth
285 Layout.minimumWidth: implicitWidth
286 }
287
288 Loader
289 {
290 active: control.Maui.Controls.showCSD === true
291 visible: active
292
293 asynchronous: true
294
295 sourceComponent: Maui.WindowControls {}
296 }
297 }
298 }
299
300 /**
301 * @brief Positions the TabButton at the given index to be centered and visible in the viewport.
302 */
303 function positionViewAtIndex(index)
304 {
305 _content.positionViewAtIndex(index, ListView.SnapPosition)
306 }
307
308 function itemAt(x, y)
309 {
310 return _content.itemAt(x,y)
311 }
312}
KGuiItem properties()
QQuickWindow * window() const const
bool startSystemMove()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:50:53 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.