MauiKit Controls

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