MauiKit Controls

TabViewButton.qml
1import QtQuick
2import QtQml
3
4import QtQuick.Controls
5import QtQuick.Layouts
6import Qt5Compat.GraphicalEffects
7
8import org.mauikit.controls 1.3 as Maui
9
10/**
11 * @inherit TabButton
12 * @brief A TabButton crafted to be use along with the MauiKit TabView.
13 *
14 * 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.
15 *
16 * This control adds the DnD features, and integrates wiht the TabViewInfo data.
17 */
18Maui.TabButton
19{
20 id: control
21
22 autoExclusive: true
23
24 /**
25 * @brief The index of this tab button in the TabBar
26 */
27 readonly property int mindex : control.TabBar.index
29 /**
30 * @brief The TabView to which this tab button belongs to.
31 * By default this is set to its parent.
32 * @warning When creating a custom tab button for the TabView, you might need to bind this to the TabView ID.
33 */
34 property Item tabView : control.parent
36 /**
37 * @brief The object map containing information about this tab.
38 * The information was provided using the TabViewInfo attached properties.
39 * @see TabViewInfo
40 */
41 readonly property var tabInfo: control.tabView.contentModel.get(mindex).Maui.TabViewInfo
42
43 /**
44 * @brief The color to be used in a bottom strip.
45 * By default this checks for the `TabViewInfo.tabColor` attached property, if it has not been set, it fallbacks to being transparent.
46 */
47 property color color : tabInfo.tabColor ? tabInfo.tabColor : "transparent"
48
49 width: control.tabView.mobile ? ListView.view.width : Math.max(160, implicitWidth)
50
51 checked: control.mindex === control.tabView.currentIndex
52 text: tabInfo.tabTitle
53
54 icon.name: tabInfo.tabIcon
55
56 ToolTip.delay: 1000
57 ToolTip.timeout: 5000
58 ToolTip.visible: control.hovered && !Maui.Handy.isMobile && ToolTip.text.length
59 ToolTip.text: tabInfo.tabToolTipText
60
61 Drag.active: dragArea.drag.active
62 Drag.source: control
63 Drag.hotSpot.x: width / 2
64 Drag.hotSpot.y: height / 2
65 Drag.dragType: Drag.Automatic
66 Drag.proposedAction: Qt.IgnoreAction
67
68 Rectangle
69 {
70 parent: control.background
71 color: control.color
72 height: 2
73 width: parent.width*0.9
74 anchors.bottom: parent.bottom
75 anchors.horizontalCenter: parent.horizontalCenter
76 }
77
78 MouseArea
79 {
80 id: dragArea
81 anchors.fill: parent
82 enabled: !control.mobile && control.tabView.count > 1
83 propagateComposedEvents: true
84
85 cursorShape: drag.active ? Qt.OpenHandCursor : undefined
86
87 drag.filterChildren: true
88 drag.target: parent
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 mouse.accepted = false
100 }
101
102 onPositionChanged:
103 {
104 control.grabToImage(function(result)
105 {
106 control.Drag.imageSource = result.url;
107 })
108 }
109 }
110
111 Timer
112 {
113 id: _dropAreaTimer
114 interval: 250
115 onTriggered:
116 {
117 if(_dropArea.containsDrag)
118 {
119 control.tabView.setCurrentIndex(mindex)
120 }
121 }
122 }
123
124 DropArea
125 {
126 id: _dropArea
127 anchors.fill: parent
128 onDropped: (drop) =>
129 {
130 if(!drop.source)
131 return
132
133 const from = drop.source.mindex
134 const to = control.mindex
135
136 if(to === from)
137 {
138 return
139 }
140
141 console.log("Move ", drop.source.mindex, control.mindex)
142 control.tabView.moveTab(from , to)
143 }
144
145 onEntered: (drag) =>
146 {
147 if(drag.source && drag.source.mindex >= 0)
148 {
149 return
150 }
151 _dropAreaTimer.restart()
152 }
153
154 onExited:
155 {
156 _dropAreaTimer.stop()
157 }
158 }
159}
int timeout
bool active
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-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.