MauiKit Controls

TabViewButton.qml
1import QtQuick
2import QtQml
3
4import QtQuick.Controls
5import QtQuick.Layouts
6
7import org.mauikit.controls as Maui
8
9/**
10 * @inherit TabButton
11 * @brief A TabButton crafted to be use along with the MauiKit TabView.
12 *
13 * This control only adds some extra functionality to integrate well with MauiKit TabView. If you consider changing the tab button of the TabView for a custom one, use this as the base.
14 *
15 * This control adds the DnD features, and integrates with the attached Controls metadata properties.
16 */
17Maui.TabButton
18{
19 id: control
20
21 autoExclusive: true
22
23 /**
24 * @brief The index of this tab button in the TabBar
25 */
26 readonly property int mindex : control.TabBar.index
28 /**
29 * @brief The TabView to which this tab button belongs to.
30 * By default this is set to its parent.
31 * @warning When creating a custom tab button for the TabView, you might need to bind this to the TabView ID.
32 */
33 property Item tabView : control.parent
35 /**
36 * @brief The object map containing information about this tab.
37 * The information was provided using the Controls metadata attached properties.
38 * @see Controls
39 */
40 readonly property var tabInfo: control.tabView.contentModel.get(mindex).Maui.Controls
41
42 /**
43 * @brief The color to be used in a bottom strip.
44 * By default this checks for the `Controls.color` attached property, if it has not been set, it fallbacks to being transparent.
45 */
46 property color color : tabInfo.color ? tabInfo.color : "transparent"
47
48 width: control.tabView.mobile ? ListView.view.width : Math.max(160, Math.min(260, implicitWidth))
49
50 checked: control.mindex === control.tabView.currentIndex
51 text: tabInfo.title
52
53 icon.name: tabInfo.iconName
54
55 Maui.Controls.badgeText: tabInfo.badgeText
56 Maui.Controls.status: tabInfo.status
57
58 ToolTip.delay: 1000
59 ToolTip.timeout: 5000
60 ToolTip.visible: control.hovered && !Maui.Handy.isMobile && ToolTip.text.length
61 ToolTip.text: tabInfo.toolTipText
62
63 Drag.active: dragArea.drag.active
64 Drag.source: control
65 Drag.hotSpot.x: width / 2
66 Drag.hotSpot.y: height / 2
67 Drag.dragType: Drag.Automatic
68 Drag.proposedAction: Qt.IgnoreAction
69
70 Rectangle
71 {
72 parent: control.background
73 color: control.color
74 height: 2
75 width: parent.width*0.9
76 anchors.bottom: parent.bottom
77 anchors.horizontalCenter: parent.horizontalCenter
78 }
79
80 MouseArea
81 {
82 id: dragArea
83 anchors.fill: parent
84 enabled: !Maui.Handy.isMobile && control.tabView.count > 1
85
86 cursorShape: drag.active ? Qt.OpenHandCursor : undefined
87
88 drag.target: this
89 drag.axis: Drag.XAxis
90
91 onClicked: (mouse) =>
92 {
93 if(mouse.button === Qt.RightButton)
94 {
95 control.rightClicked(mouse)
96 return
97 }
98 control.clicked()
99 }
100
101 onPositionChanged:
102 {
103 control.grabToImage(function(result)
104 {
105 control.Drag.imageSource = result.url;
106 })
107 }
108 }
109
110 Timer
111 {
112 id: _dropAreaTimer
113 interval: 250
114 onTriggered:
115 {
116 if(_dropArea.containsDrag)
117 {
118 control.tabView.setCurrentIndex(mindex)
119 }
120 }
121 }
122
123 DropArea
124 {
125 id: _dropArea
126 anchors.fill: parent
127 onDropped: (drop) =>
128 {
129 if(!drop.source)
130 return
131
132 const from = drop.source.mindex
133 const to = control.mindex
134
135 if(to === from)
136 {
137 return
138 }
139
140 console.log("Move ", drop.source.mindex, control.mindex)
141 control.tabView.moveTab(from , to)
142 }
143
144 onEntered: (drag) =>
145 {
146 if(drag.source && drag.source.mindex >= 0)
147 {
148 return
149 }
150 _dropAreaTimer.restart()
151 }
152
153 onExited:
154 {
155 _dropAreaTimer.stop()
156 }
157 }
158}
color color
The color to be used in a bottom strip.
var tabInfo
The object map containing information about this tab.
KIOWIDGETS_EXPORT DropJob * drop(const QDropEvent *dropEvent, const QUrl &destUrl, DropJobFlags dropjobFlags, JobFlags flags=DefaultFlags)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:16:12 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.