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);
107
108 QString tabText(int index) const;
109 void setTabText(int index, const QString &text);
110
111 QColor tabTextColor(int index) const;
112 void setTabTextColor(int index, const QColor &color);
113
114 QIcon tabIcon(int index) const;
115 void setTabIcon(int index, const QIcon &icon);
116
117 Qt::TextElideMode elideMode() const;
118 void setElideMode(Qt::TextElideMode);
119
120#ifndef QT_NO_TOOLTIP
121 void setTabToolTip(int index, const QString &tip);
122 QString tabToolTip(int index) const;
123#endif
124
125#if QT_CONFIG(whatsthis)
126 void setTabWhatsThis(int index, const QString &text);
127 QString tabWhatsThis(int index) const;
128#endif
129
130 void setTabData(int index, const QVariant &data);
131 QVariant tabData(int index) const;
132
133 QRect tabRect(int index) const;
134 int tabAt(const QPoint &pos) const;
135
136 int currentIndex() const;
137 int count() const;
138
139 QSize sizeHint() const override;
140 QSize minimumSizeHint() const override;
141
142 void setDrawBase(bool drawTheBase);
143 bool drawBase() const;
144
145 QSize iconSize() const;
146 void setIconSize(const QSize &size);
147
148 bool usesScrollButtons() const;
149 void setUsesScrollButtons(bool useButtons);
150
151 bool tabsClosable() const;
152 void setTabsClosable(bool closable);
153
154 void setTabButton(int index, ButtonPosition position, QWidget *widget);
155 QWidget *tabButton(int index, ButtonPosition position) const;
156
157 SelectionBehavior selectionBehaviorOnRemove() const;
158 void setSelectionBehaviorOnRemove(SelectionBehavior behavior);
159
160 bool expanding() const;
161 void setExpanding(bool enabled);
162
163 bool isMovable() const;
164 void setMovable(bool movable);
165
166 bool documentMode() const;
167 void setDocumentMode(bool set);
168
169 bool autoHide() const;
170 void setAutoHide(bool hide);
171
172 bool changeCurrentOnDrag() const;
173 void setChangeCurrentOnDrag(bool change);
174
175#ifndef QT_NO_ACCESSIBILITY
176 QString accessibleTabName(int index) const;
177 void setAccessibleTabName(int index, const QString &name);
178#endif
179
180public Q_SLOTS:
181 void setCurrentIndex(int index);
182
183Q_SIGNALS:
184 void currentChanged(int index);
185 void tabCloseRequested(int index);
186 void tabMoved(int from, int to);
187 void tabBarClicked(int index);
188 void tabBarDoubleClicked(int index);
189
190protected:
191 virtual QSize tabSizeHint(int index) const;
192 virtual QSize minimumTabSizeHint(int index) const;
193 virtual void tabInserted(int index);
194 virtual void tabRemoved(int index);
195 virtual void tabLayoutChange();
196
197 bool event(QEvent *) override;
198 void resizeEvent(QResizeEvent *) override;
199 void showEvent(QShowEvent *) override;
200 void hideEvent(QHideEvent *) override;
201 void paintEvent(QPaintEvent *) override;
202 void mousePressEvent (QMouseEvent *) override;
203 void mouseMoveEvent (QMouseEvent *) override;
204 void mouseReleaseEvent (QMouseEvent *) override;
205#if QT_CONFIG(wheelevent)
206 void wheelEvent(QWheelEvent *event) override;
207#endif
208 void keyPressEvent(QKeyEvent *) override;
209 void changeEvent(QEvent *) override;
210 void timerEvent(QTimerEvent *event) override;
211 void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
212
213#ifndef QT_NO_ACCESSIBILITY
214 friend class QAccessibleTabBar;
215#endif
216private:
217 Q_DISABLE_COPY(QTabBar)
218 Q_DECLARE_PRIVATE(QTabBar)
219 Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs())
220 Q_PRIVATE_SLOT(d_func(), void _q_closeTab())
221};
222
223QT_END_NAMESPACE
224
225#endif // QTABBAR_H
226