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 QTABWIDGET_H
41#define QTABWIDGET_H
42
43#include <QtWidgets/qtwidgetsglobal.h>
44#include <QtWidgets/qwidget.h>
45#include <QtGui/qicon.h>
46
47QT_REQUIRE_CONFIG(tabwidget);
48
49QT_BEGIN_NAMESPACE
50
51class QTabBar;
52class QTabWidgetPrivate;
53class QStyleOptionTabWidgetFrame;
54
55class Q_WIDGETS_EXPORT QTabWidget : public QWidget
56{
57 Q_OBJECT
58 Q_PROPERTY(TabPosition tabPosition READ tabPosition WRITE setTabPosition)
59 Q_PROPERTY(TabShape tabShape READ tabShape WRITE setTabShape)
60 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
61 Q_PROPERTY(int count READ count)
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 documentMode READ documentMode WRITE setDocumentMode)
66 Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
67 Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
68 Q_PROPERTY(bool tabBarAutoHide READ tabBarAutoHide WRITE setTabBarAutoHide)
69
70public:
71 explicit QTabWidget(QWidget *parent = nullptr);
72 ~QTabWidget();
73
74 int addTab(QWidget *widget, const QString &);
75 int addTab(QWidget *widget, const QIcon& icon, const QString &label);
76
77 int insertTab(int index, QWidget *widget, const QString &);
78 int insertTab(int index, QWidget *widget, const QIcon& icon, const QString &label);
79
80 void removeTab(int index);
81
82 bool isTabEnabled(int index) const;
83 void setTabEnabled(int index, bool enabled);
84
85 bool isTabVisible(int index) const;
86 void setTabVisible(int index, bool visible);
87
88 QString tabText(int index) const;
89 void setTabText(int index, const QString &text);
90
91 QIcon tabIcon(int index) const;
92 void setTabIcon(int index, const QIcon & icon);
93
94#ifndef QT_NO_TOOLTIP
95 void setTabToolTip(int index, const QString & tip);
96 QString tabToolTip(int index) const;
97#endif
98
99#if QT_CONFIG(whatsthis)
100 void setTabWhatsThis(int index, const QString &text);
101 QString tabWhatsThis(int index) const;
102#endif
103
104 int currentIndex() const;
105 QWidget *currentWidget() const;
106 QWidget *widget(int index) const;
107 int indexOf(QWidget *widget) const;
108 int count() const;
109
110 enum TabPosition { North, South, West, East };
111 Q_ENUM(TabPosition)
112 TabPosition tabPosition() const;
113 void setTabPosition(TabPosition position);
114
115 bool tabsClosable() const;
116 void setTabsClosable(bool closeable);
117
118 bool isMovable() const;
119 void setMovable(bool movable);
120
121 enum TabShape { Rounded, Triangular };
122 Q_ENUM(TabShape)
123 TabShape tabShape() const;
124 void setTabShape(TabShape s);
125
126 QSize sizeHint() const override;
127 QSize minimumSizeHint() const override;
128 int heightForWidth(int width) const override;
129 bool hasHeightForWidth() const override;
130
131 void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner);
132 QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
133
134 Qt::TextElideMode elideMode() const;
135 void setElideMode(Qt::TextElideMode mode);
136
137 QSize iconSize() const;
138 void setIconSize(const QSize &size);
139
140 bool usesScrollButtons() const;
141 void setUsesScrollButtons(bool useButtons);
142
143 bool documentMode() const;
144 void setDocumentMode(bool set);
145
146 bool tabBarAutoHide() const;
147 void setTabBarAutoHide(bool enabled);
148
149 void clear();
150
151 QTabBar* tabBar() const;
152
153public Q_SLOTS:
154 void setCurrentIndex(int index);
155 void setCurrentWidget(QWidget *widget);
156
157Q_SIGNALS:
158 void currentChanged(int index);
159 void tabCloseRequested(int index);
160 void tabBarClicked(int index);
161 void tabBarDoubleClicked(int index);
162
163protected:
164 virtual void tabInserted(int index);
165 virtual void tabRemoved(int index);
166
167 void showEvent(QShowEvent *) override;
168 void resizeEvent(QResizeEvent *) override;
169 void keyPressEvent(QKeyEvent *) override;
170 void paintEvent(QPaintEvent *) override;
171 void setTabBar(QTabBar *);
172 void changeEvent(QEvent *) override;
173 bool event(QEvent *) override;
174 void initStyleOption(QStyleOptionTabWidgetFrame *option) const;
175
176
177private:
178 Q_DECLARE_PRIVATE(QTabWidget)
179 Q_DISABLE_COPY(QTabWidget)
180 Q_PRIVATE_SLOT(d_func(), void _q_showTab(int))
181 Q_PRIVATE_SLOT(d_func(), void _q_removeTab(int))
182 Q_PRIVATE_SLOT(d_func(), void _q_tabMoved(int, int))
183 void setUpLayout(bool = false);
184};
185
186QT_END_NAMESPACE
187
188#endif // QTABWIDGET_H
189