1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtWidgets module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QTABBAR_H
41#define QTABBAR_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qwidget.h>
45
46QT_REQUIRE_CONFIG(tabbar);
47
48QT_BEGIN_NAMESPACE
49
50class QIcon;
51class QTabBarPrivate;
52class QStyleOptionTab;
53
54class Q_WIDGETS_EXPORT QTabBar: public QWidget
55{
56 Q_OBJECT
57
58 Q_PROPERTY(Shape shape READ shape WRITE setShape)
59 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
60 Q_PROPERTY(int count READ count)
61 Q_PROPERTY(bool drawBase READ drawBase WRITE setDrawBase)
62 Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
63 Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
64 Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
65 Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
66 Q_PROPERTY(SelectionBehavior selectionBehaviorOnRemove READ selectionBehaviorOnRemove WRITE setSelectionBehaviorOnRemove)
67 Q_PROPERTY(bool expanding READ expanding WRITE setExpanding)
68 Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
69 Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
70 Q_PROPERTY(bool autoHide READ autoHide WRITE setAutoHide)
71 Q_PROPERTY(bool changeCurrentOnDrag READ changeCurrentOnDrag WRITE setChangeCurrentOnDrag)
72
73public:
74 explicit QTabBar(QWidget *parent = nullptr);
75 ~QTabBar();
76
77 enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast,
78 TriangularNorth, TriangularSouth, TriangularWest, TriangularEast
79 };
80 Q_ENUM(Shape)
81
82 enum ButtonPosition {
83 LeftSide,
84 RightSide
85 };
86
87 enum SelectionBehavior {
88 SelectLeftTab,
89 SelectRightTab,
90 SelectPreviousTab
91 };
92
93 Shape shape() const;
94 void setShape(Shape shape);
95
96 int addTab(const QString &text);
97 int addTab(const QIcon &icon, const QString &text);
98
99 int insertTab(int index, const QString &text);
100 int insertTab(int index, const QIcon&icon, const QString &text);
101
102 void removeTab(int index);
103 void moveTab(int from, int to);
104
105 bool isTabEnabled(int index) const;
106 void setTabEnabled(int index, bool enabled);
107
108 bool isTabVisible(int index) const;
109 void setTabVisible(int index, bool visible);
110
111 QString tabText(int index) const;
112 void setTabText(int index, const QString &text);
113
114 QColor tabTextColor(int index) const;
115 void setTabTextColor(int index, const QColor &color);
116
117 QIcon tabIcon(int index) const;
118 void setTabIcon(int index, const QIcon &icon);
119
120 Qt::TextElideMode elideMode() const;
121 void setElideMode(Qt::TextElideMode mode);
122
123#ifndef QT_NO_TOOLTIP
124 void setTabToolTip(int index, const QString &tip);
125 QString tabToolTip(int index) const;
126#endif
127
128#if QT_CONFIG(whatsthis)
129 void setTabWhatsThis(int index, const QString &text);
130 QString tabWhatsThis(int index) const;
131#endif
132
133 void setTabData(int index, const QVariant &data);
134 QVariant tabData(int index) const;
135
136 QRect tabRect(int index) const;
137 int tabAt(const QPoint &pos) const;
138
139 int currentIndex() const;
140 int count() const;
141
142 QSize sizeHint() const override;
143 QSize minimumSizeHint() const override;
144
145 void setDrawBase(bool drawTheBase);
146 bool drawBase() const;
147
148 QSize iconSize() const;
149 void setIconSize(const QSize &size);
150
151 bool usesScrollButtons() const;
152 void setUsesScrollButtons(bool useButtons);
153
154 bool tabsClosable() const;
155 void setTabsClosable(bool closable);
156
157 void setTabButton(int index, ButtonPosition position, QWidget *widget);
158 QWidget *tabButton(int index, ButtonPosition position) const;
159
160 SelectionBehavior selectionBehaviorOnRemove() const;
161 void setSelectionBehaviorOnRemove(SelectionBehavior behavior);
162
163 bool expanding() const;
164 void setExpanding(bool enabled);
165
166 bool isMovable() const;
167 void setMovable(bool movable);
168
169 bool documentMode() const;
170 void setDocumentMode(bool set);
171
172 bool autoHide() const;
173 void setAutoHide(bool hide);
174
175 bool changeCurrentOnDrag() const;
176 void setChangeCurrentOnDrag(bool change);
177
178#ifndef QT_NO_ACCESSIBILITY
179 QString accessibleTabName(int index) const;
180 void setAccessibleTabName(int index, const QString &name);
181#endif
182
183public Q_SLOTS:
184 void setCurrentIndex(int index);
185
186Q_SIGNALS:
187 void currentChanged(int index);
188 void tabCloseRequested(int index);
189 void tabMoved(int from, int to);
190 void tabBarClicked(int index);
191 void tabBarDoubleClicked(int index);
192
193protected:
194 virtual QSize tabSizeHint(int index) const;
195 virtual QSize minimumTabSizeHint(int index) const;
196 virtual void tabInserted(int index);
197 virtual void tabRemoved(int index);
198 virtual void tabLayoutChange();
199
200 bool event(QEvent *) override;
201 void resizeEvent(QResizeEvent *) override;
202 void showEvent(QShowEvent *) override;
203 void hideEvent(QHideEvent *) override;
204 void paintEvent(QPaintEvent *) override;
205 void mousePressEvent (QMouseEvent *) override;
206 void mouseMoveEvent (QMouseEvent *) override;
207 void mouseReleaseEvent (QMouseEvent *) override;
208#if QT_CONFIG(wheelevent)
209 void wheelEvent(QWheelEvent *event) override;
210#endif
211 void keyPressEvent(QKeyEvent *) override;
212 void changeEvent(QEvent *) override;
213 void timerEvent(QTimerEvent *event) override;
214 void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
215
216#ifndef QT_NO_ACCESSIBILITY
217 friend class QAccessibleTabBar;
218#endif
219private:
220 Q_DISABLE_COPY(QTabBar)
221 Q_DECLARE_PRIVATE(QTabBar)
222 Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs())
223 Q_PRIVATE_SLOT(d_func(), void _q_closeTab())
224};
225
226QT_END_NAMESPACE
227
228#endif // QTABBAR_H
229

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