DtkWidget
DTK Widget module
载入中...
搜索中...
未找到
dtabbar.h
浏览该文件的文档.
1// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DTABBAR_H
6#define DTABBAR_H
7
8#include <QTabBar>
9
10#include <dtkwidget_global.h>
11#include <dobject.h>
12
13QT_BEGIN_NAMESPACE
14class QMimeData;
15QT_END_NAMESPACE
16
17DCORE_USE_NAMESPACE
18DWIDGET_BEGIN_NAMESPACE
19
20class DTabBarPrivate;
21class DTabBar : public QWidget, public DObject
22{
23 Q_OBJECT
24
25 Q_PROPERTY(bool visibleAddButton READ visibleAddButton WRITE setVisibleAddButton)
26 Q_PROPERTY(QTabBar::Shape shape READ shape WRITE setShape)
27 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
28 Q_PROPERTY(int count READ count)
29 Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase)
30 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
31 Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
32 Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
33 Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
34 Q_PROPERTY(QTabBar::SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove WRITE setSelectionBehaviorOnRemove)
35 Q_PROPERTY(bool expanding READ expanding WRITE setExpanding)
36 Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
37 Q_PROPERTY(bool dragable READ isDragable WRITE setDragable)
38 Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
39 Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
40 Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag)
41 Q_PROPERTY(int startDragDistance READ startDragDistance WRITE setStartDragDistance)
42 // on drag enter
43 Q_PROPERTY(QColor maskColor READ maskColor WRITE setMaskColor)
44 // on inserted tab from mime data
45 Q_PROPERTY(QColor flashColor READ flashColor WRITE setFlashColor)
46
47public:
48 explicit DTabBar(QWidget *parent = 0);
49
50 void setTabMinimumSize(int index, const QSize &size);
51 void setTabMaximumSize(int index, const QSize &size);
52
53 bool visibleAddButton() const;
54
55 QTabBar::Shape shape() const;
56 void setShape(QTabBar::Shape shape);
57
58 int addTab(const QString &text);
59 int addTab(const QIcon &icon, const QString &text);
60
61 int insertTab(int index, const QString &text);
62 int insertTab(int index, const QIcon&icon, const QString &text);
63
64 void removeTab(int index);
65 void moveTab(int from, int to);
66
67 bool isTabEnabled(int index) const;
68 void setTabEnabled(int index, bool);
69
70 QString tabText(int index) const;
71 void setTabText(int index, const QString &text);
72
73 QIcon tabIcon(int index) const;
74 void setTabIcon(int index, const QIcon &icon);
75
76 Qt::TextElideMode elideMode() const;
77 void setElideMode(Qt::TextElideMode mode);
78
79#ifndef QT_NO_TOOLTIP
80 void setTabToolTip(int index, const QString &tip);
81 QString tabToolTip(int index) const;
82#endif
83
84#ifndef QT_NO_WHATSTHIS
85 void setTabWhatsThis(int index, const QString &text);
86 QString tabWhatsThis(int index) const;
87#endif
88
89 void setTabData(int index, const QVariant &data);
90 QVariant tabData(int index) const;
91
92 QRect tabRect(int index) const;
93 int tabAt(const QPoint &pos) const;
94
95 int currentIndex() const;
96 int count() const;
97
98 void setDrawBase(bool drawTheBase);
99 bool drawBase() const;
100
101 QSize iconSize() const;
102 void setIconSize(const QSize &size);
103
104 bool usesScrollButtons() const;
105 void setUsesScrollButtons(bool useButtons);
106
107 bool tabsClosable() const;
108 void setTabsClosable(bool closable);
109
110 void setTabButton(int index, QTabBar::ButtonPosition position, QWidget *widget);
111 QWidget *tabButton(int index, QTabBar::ButtonPosition position) const;
112
113 QTabBar::SelectionBehavior selectionBehaviorOnRemove() const;
114 void setSelectionBehaviorOnRemove(QTabBar::SelectionBehavior behavior);
115
116 bool expanding() const;
117 void setExpanding(bool enabled);
118
119 bool isMovable() const;
120 void setMovable(bool movable);
121
122 bool isDragable() const;
123 void setDragable(bool dragable);
124
125 bool documentMode() const;
126 void setDocumentMode(bool set);
127
128 bool autoHide() const;
129 void setAutoHide(bool hide);
130
131 bool changeCurrentOnDrag() const;
132 void setChangeCurrentOnDrag(bool change);
133
134 int startDragDistance() const;
135
136 QColor maskColor() const;
137 QColor flashColor() const;
138
139 QWindow *dragIconWindow() const;
140
141 void setEnabledEmbedStyle(bool enable);
142
143 void setTabLabelAlignment(Qt::Alignment alignment);
144
145Q_SIGNALS:
146 void currentChanged(int index);
147 void tabCloseRequested(int index);
148 void tabMoved(int from, int to);
149 void tabIsInserted(int index);
150 void tabIsRemoved(int index);
151 void tabBarClicked(int index);
152 void tabBarDoubleClicked(int index);
154 void tabReleaseRequested(int index);
155 void tabDroped(int index, Qt::DropAction action, QObject *target);
156 void dragActionChanged(Qt::DropAction action);
158 void dragEnd(Qt::DropAction action);
159
160public Q_SLOTS:
161 void setCurrentIndex(int index);
162 void setVisibleAddButton(bool visibleAddButton);
163 void setStartDragDistance(int startDragDistance);
164
165 void setMaskColor(QColor maskColor);
166 void setFlashColor(QColor flashColor);
167
168 void startDrag(int index);
169 void stopDrag(Qt::DropAction action);
170
171protected:
172 void dragEnterEvent(QDragEnterEvent *e) override;
173 void dragLeaveEvent(QDragLeaveEvent *e) override;
174 void dragMoveEvent(QDragMoveEvent *e) override;
175 void dropEvent(QDropEvent *e) override;
176 void resizeEvent(QResizeEvent *e) override;
177
178 void startTabFlash(int index);
179
180 virtual void paintTab(QPainter *painter, int index, const QStyleOptionTab &option) const;
181
182 virtual QPixmap createDragPixmapFromTab(int index, const QStyleOptionTab &option, QPoint *hotspot) const;
183 virtual QMimeData *createMimeDataFromTab(int index, const QStyleOptionTab &option) const;
184 virtual bool canInsertFromMimeData(int index, const QMimeData *source) const;
185 virtual void insertFromMimeData(int index, const QMimeData *source);
186 virtual void insertFromMimeDataOnDragEnter(int index, const QMimeData *source);
187
188 virtual void tabInserted(int index);
189 virtual void tabLayoutChange();
190 virtual void tabRemoved(int index);
191
192 virtual QSize tabSizeHint(int index) const;
193 virtual QSize minimumTabSizeHint(int index) const;
194 virtual QSize maximumTabSizeHint(int index) const;
195
196private:
197 DTabBarPrivate* d_func();
198 const DTabBarPrivate* d_func() const;
199 friend class DTabBarPrivate;
200};
201
202DWIDGET_END_NAMESPACE
203
204#endif // DTABBAR_H
Definition dtabbar.h:22
void setTabText(int index, const QString &text)
设置标签索引位置文本.
Definition dtabbar.cpp:1873
int addTab(const QString &text)
添加一个新的标签,返回新标签的索引.
Definition dtabbar.cpp:1759
void setTabData(int index, const QVariant &data)
设置标签索引位置数据.
Definition dtabbar.cpp:1966
void tabIsInserted(int index)
新标签已插入.
void tabAddRequested()
新标签加入.
QString tabToolTip(int index) const
返回标签索引位置提示文本.
Definition dtabbar.cpp:1942
void currentChanged(int index)
当前索引位置改变.
void tabIsRemoved(int index)
标签已删除.
void removeTab(int index)
移除标签索引位置
Definition dtabbar.cpp:1813
void setTabLabelAlignment(Qt::Alignment alignment)
设置 tab 标签文字对齐方式.
Definition dtabbar.cpp:2257
void tabCloseRequested(int index)
点击关闭后发出.
void dragActionChanged(Qt::DropAction action)
鼠标形状发生变化.
void setCurrentIndex(int index)
设置当前标签索引位置.
Definition dtabbar.cpp:2268
void setTabToolTip(int index, const QString &tip)
设置标签索引位置提示文本.
Definition dtabbar.cpp:1931
void setTabMaximumSize(int index, const QSize &size)
设置索引标签的最大尺寸.
Definition dtabbar.cpp:1682
void moveTab(int from, int to)
移动标签索引位置
Definition dtabbar.cpp:1825
void setTabIcon(int index, const QIcon &icon)
设置标签索引位置图标.
Definition dtabbar.cpp:1896
void setEnabledEmbedStyle(bool enable)
启用直角样式的 Tabbar. 此风格适用于切换窗口的操作,多用于支持多开的应用.
Definition dtabbar.cpp:2226
void tabDroped(int index, Qt::DropAction action, QObject *target)
标签拖放.
void setElideMode(Qt::TextElideMode mode)
设置缩略模式
Definition dtabbar.cpp:1918
QRect tabRect(int index) const
返回标签索引位置矩形.
Definition dtabbar.cpp:1990
void setTabEnabled(int index, bool)
设置标签索引位置启用状态
Definition dtabbar.cpp:1849
bool isTabEnabled(int index) const
是否启用标签索引位置
Definition dtabbar.cpp:1837
void tabReleaseRequested(int index)
索引标签鼠标释放.
void setTabMinimumSize(int index, const QSize &size)
设置索引标签的最小尺寸.
Definition dtabbar.cpp:1662
void tabMoved(int from, int to)
索引位置发生变化
void dragStarted()
开始拖起.
void setTabsClosable(bool closable)
设置标签栏是否可关闭.
Definition dtabbar.cpp:2092
void tabBarClicked(int index)
点击索引标签.
QVariant tabData(int index) const
返回标签索引位置数据.
Definition dtabbar.cpp:1978
void setMaskColor(QColor maskColor)
设置颜色.
Definition dtabbar.cpp:2304
QString tabText(int index) const
返回标签索引位置文本.
Definition dtabbar.cpp:1861
void tabBarDoubleClicked(int index)
双击索引标签.
void setIconSize(const QSize &size)
设置图标大小.
Definition dtabbar.cpp:2060
void setVisibleAddButton(bool visibleAddButton)
设置新建标签按钮是否显示.
Definition dtabbar.cpp:2279
void dragEnd(Qt::DropAction action)
拖放结束.
QIcon tabIcon(int index) const
返回标签索引位置图标.
Definition dtabbar.cpp:1885
int tabAt(const QPoint &pos) const
根据位置返回标签索引位置.
Definition dtabbar.cpp:2006
int insertTab(int index, const QString &text)
插入一个文本标签.
Definition dtabbar.cpp:1787
void setStartDragDistance(int startDragDistance)
设置开始拖动距离.
Definition dtabbar.cpp:2293
void setShape(QTabBar::Shape shape)
设置标签栏形状.
Definition dtabbar.cpp:1726
Definition dtabbar.cpp:122