1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QTABBAR_H
5#define QTABBAR_H
6
7#include <QtWidgets/qtwidgetsglobal.h>
8#include <QtWidgets/qwidget.h>
9
10QT_REQUIRE_CONFIG(tabbar);
11
12QT_BEGIN_NAMESPACE
13
14class QIcon;
15class QTabBarPrivate;
16class QStyleOptionTab;
17
18class Q_WIDGETS_EXPORT QTabBar: public QWidget
19{
20 Q_OBJECT
21
22 Q_PROPERTY(Shape shape READ shape WRITE setShape)
23 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
24 Q_PROPERTY(int count READ count)
25 Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase)
26 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
27 Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
28 Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
29 Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
30 Q_PROPERTY(SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove
31 WRITE setSelectionBehaviorOnRemove)
32 Q_PROPERTY(bool expanding READ expanding WRITE setExpanding)
33 Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
34 Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
35 Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
36 Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag)
37
38public:
39 explicit QTabBar(QWidget *parent = nullptr);
40 ~QTabBar();
41
42 enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast,
43 TriangularNorth, TriangularSouth, TriangularWest, TriangularEast
44 };
45 Q_ENUM(Shape)
46
47 enum ButtonPosition {
48 LeftSide,
49 RightSide
50 };
51
52 enum SelectionBehavior {
53 SelectLeftTab,
54 SelectRightTab,
55 SelectPreviousTab
56 };
57
58 Shape shape() const;
59 void setShape(Shape shape);
60
61 int addTab(const QString &text);
62 int addTab(const QIcon &icon, const QString &text);
63
64 int insertTab(int index, const QString &text);
65 int insertTab(int index, const QIcon&icon, const QString &text);
66
67 void removeTab(int index);
68 void moveTab(int from, int to);
69
70 bool isTabEnabled(int index) const;
71 void setTabEnabled(int index, bool enabled);
72
73 bool isTabVisible(int index) const;
74 void setTabVisible(int index, bool visible);
75
76 QString tabText(int index) const;
77 void setTabText(int index, const QString &text);
78
79 QColor tabTextColor(int index) const;
80 void setTabTextColor(int index, const QColor &color);
81
82 QIcon tabIcon(int index) const;
83 void setTabIcon(int index, const QIcon &icon);
84
85 Qt::TextElideMode elideMode() const;
86 void setElideMode(Qt::TextElideMode mode);
87
88#if QT_CONFIG(tooltip)
89 void setTabToolTip(int index, const QString &tip);
90 QString tabToolTip(int index) const;
91#endif
92
93#if QT_CONFIG(whatsthis)
94 void setTabWhatsThis(int index, const QString &text);
95 QString tabWhatsThis(int index) const;
96#endif
97
98 void setTabData(int index, const QVariant &data);
99 QVariant tabData(int index) const;
100
101 QRect tabRect(int index) const;
102 int tabAt(const QPoint &pos) const;
103
104 int currentIndex() const;
105 int count() const;
106
107 QSize sizeHint() const override;
108 QSize minimumSizeHint() const override;
109
110 void setDrawBase(bool drawTheBase);
111 bool drawBase() const;
112
113 QSize iconSize() const;
114 void setIconSize(const QSize &size);
115
116 bool usesScrollButtons() const;
117 void setUsesScrollButtons(bool useButtons);
118
119 bool tabsClosable() const;
120 void setTabsClosable(bool closable);
121
122 void setTabButton(int index, ButtonPosition position, QWidget *widget);
123 QWidget *tabButton(int index, ButtonPosition position) const;
124
125 SelectionBehavior selectionBehaviorOnRemove() const;
126 void setSelectionBehaviorOnRemove(SelectionBehavior behavior);
127
128 bool expanding() const;
129 void setExpanding(bool enabled);
130
131 bool isMovable() const;
132 void setMovable(bool movable);
133
134 bool documentMode() const;
135 void setDocumentMode(bool set);
136
137 bool autoHide() const;
138 void setAutoHide(bool hide);
139
140 bool changeCurrentOnDrag() const;
141 void setChangeCurrentOnDrag(bool change);
142
143#if QT_CONFIG(accessibility)
144 QString accessibleTabName(int index) const;
145 void setAccessibleTabName(int index, const QString &name);
146#endif
147
148public Q_SLOTS:
149 void setCurrentIndex(int index);
150
151Q_SIGNALS:
152 void currentChanged(int index);
153 void tabCloseRequested(int index);
154 void tabMoved(int from, int to);
155 void tabBarClicked(int index);
156 void tabBarDoubleClicked(int index);
157
158protected:
159 virtual QSize tabSizeHint(int index) const;
160 virtual QSize minimumTabSizeHint(int index) const;
161 virtual void tabInserted(int index);
162 virtual void tabRemoved(int index);
163 virtual void tabLayoutChange();
164
165 bool event(QEvent *) override;
166 void resizeEvent(QResizeEvent *) override;
167 void showEvent(QShowEvent *) override;
168 void hideEvent(QHideEvent *) override;
169 void paintEvent(QPaintEvent *) override;
170 void mousePressEvent(QMouseEvent *) override;
171 void mouseMoveEvent(QMouseEvent *) override;
172 void mouseReleaseEvent(QMouseEvent *) override;
173 void mouseDoubleClickEvent(QMouseEvent *) override;
174#if QT_CONFIG(wheelevent)
175 void wheelEvent(QWheelEvent *event) override;
176#endif
177 void keyPressEvent(QKeyEvent *) override;
178 void changeEvent(QEvent *) override;
179 void timerEvent(QTimerEvent *event) override;
180 virtual void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
181
182#if QT_CONFIG(accessibility)
183 friend class QAccessibleTabBar;
184#endif
185private:
186 Q_DISABLE_COPY(QTabBar)
187 Q_DECLARE_PRIVATE(QTabBar)
188 Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs())
189 Q_PRIVATE_SLOT(d_func(), void _q_closeTab())
190};
191
192QT_END_NAMESPACE
193
194#endif // QTABBAR_H
195

source code of qtbase/src/widgets/widgets/qtabbar.h