1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui 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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://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 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTABWIDGET_H
43 #define QTABWIDGET_H
44 
45 #include <QtGui/qwidget.h>
46 #include <QtGui/qicon.h>
47 
48 QT_BEGIN_HEADER
49 
50 QT_BEGIN_NAMESPACE
51 
52 QT_MODULE(Gui)
53 
54 #ifndef QT_NO_TABWIDGET
55 
56 class QTabBar;
57 class QTabWidgetPrivate;
58 class QStyleOptionTabWidgetFrame;
59 
60 class Q_GUI_EXPORT QTabWidget : public QWidget
61 {
62     Q_OBJECT
63     Q_ENUMS(TabPosition TabShape)
64     Q_PROPERTY(TabPosition tabPosition READ tabPosition WRITE setTabPosition)
65     Q_PROPERTY(TabShape tabShape READ tabShape WRITE setTabShape)
66     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
67     Q_PROPERTY(int count READ count)
68     Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize)
69     Q_PROPERTY(Qt::TextElideMode elideMode READ elideMode WRITE setElideMode)
70     Q_PROPERTY(bool usesScrollButtons READ usesScrollButtons WRITE setUsesScrollButtons)
71     Q_PROPERTY(bool documentMode READ documentMode WRITE setDocumentMode)
72     Q_PROPERTY(bool tabsClosable READ tabsClosable WRITE setTabsClosable)
73     Q_PROPERTY(bool movable READ isMovable WRITE setMovable)
74 
75 public:
76     explicit QTabWidget(QWidget *parent = 0);
77     ~QTabWidget();
78 
79     int addTab(QWidget *widget, const QString &);
80     int addTab(QWidget *widget, const QIcon& icon, const QString &label);
81 
82     int insertTab(int index, QWidget *widget, const QString &);
83     int insertTab(int index, QWidget *widget, const QIcon& icon, const QString &label);
84 
85     void removeTab(int index);
86 
87     bool isTabEnabled(int index) const;
88     void setTabEnabled(int index, bool);
89 
90     QString tabText(int index) const;
91     void setTabText(int index, const QString &);
92 
93     QIcon tabIcon(int index) const;
94     void setTabIcon(int index, const QIcon & icon);
95 
96 #ifndef QT_NO_TOOLTIP
97     void setTabToolTip(int index, const QString & tip);
98     QString tabToolTip(int index) const;
99 #endif
100 
101 #ifndef QT_NO_WHATSTHIS
102     void setTabWhatsThis(int index, const QString &text);
103     QString tabWhatsThis(int index) const;
104 #endif
105 
106     int currentIndex() const;
107     QWidget *currentWidget() const;
108     QWidget *widget(int index) const;
109     int indexOf(QWidget *widget) const;
110     int count() const;
111 
112     enum TabPosition { North, South, West, East
113 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
114         , Top = North, Bottom = South
115 #endif
116     };
117     TabPosition tabPosition() const;
118     void setTabPosition(TabPosition);
119 
120     bool tabsClosable() const;
121     void setTabsClosable(bool closeable);
122 
123     bool isMovable() const;
124     void setMovable(bool movable);
125 
126     enum TabShape { Rounded, Triangular };
127     TabShape tabShape() const;
128     void setTabShape(TabShape s);
129 
130     QSize sizeHint() const;
131     QSize minimumSizeHint() const;
132     int heightForWidth(int width) const;
133 
134     void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner);
135     QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
136 
137     Qt::TextElideMode elideMode() const;
138     void setElideMode(Qt::TextElideMode);
139 
140     QSize iconSize() const;
141     void setIconSize(const QSize &size);
142 
143     bool usesScrollButtons() const;
144     void setUsesScrollButtons(bool useButtons);
145 
146     bool documentMode() const;
147     void setDocumentMode(bool set);
148 
149     void clear();
150 
151 public Q_SLOTS:
152     void setCurrentIndex(int index);
153     void setCurrentWidget(QWidget *widget);
154 
155 Q_SIGNALS:
156     void currentChanged(int index);
157     void tabCloseRequested(int index);
158 
159 protected:
160     virtual void tabInserted(int index);
161     virtual void tabRemoved(int index);
162 
163     void showEvent(QShowEvent *);
164     void resizeEvent(QResizeEvent *);
165     void keyPressEvent(QKeyEvent *);
166     void paintEvent(QPaintEvent *);
167     void setTabBar(QTabBar *);
168     QTabBar* tabBar() const;
169     void changeEvent(QEvent *);
170     bool event(QEvent *);
171     void initStyleOption(QStyleOptionTabWidgetFrame *option) const;
172 
173 #ifdef QT3_SUPPORT
174 public:
175     QT3_SUPPORT_CONSTRUCTOR QTabWidget(QWidget *parent, const char *name, Qt::WindowFlags f = 0);
176 
177     inline QT3_SUPPORT void insertTab(QWidget * w, const QString &s, int index = -1) { insertTab(index, w, s); }
178     inline QT3_SUPPORT void insertTab(QWidget *child, const QIcon& icon,
179                                     const QString &label, int index = -1) { insertTab(index, child, icon, label); }
180 
changeTab(QWidget * w,const QString & s)181     inline QT3_SUPPORT void changeTab(QWidget *w, const QString &s) {setTabText(indexOf(w), s); }
changeTab(QWidget * w,const QIcon & icon,const QString & label)182     inline QT3_SUPPORT void changeTab(QWidget *w, const QIcon& icon,
183                                     const QString &label) { int idx = indexOf(w); setTabText(idx, label); setTabIcon(idx, icon); }
184 
isTabEnabled(QWidget * w)185     inline QT3_SUPPORT bool isTabEnabled( QWidget *w) const {return isTabEnabled(indexOf(w)); }
setTabEnabled(QWidget * w,bool b)186     inline QT3_SUPPORT void setTabEnabled(QWidget *w, bool b) { setTabEnabled(indexOf(w), b); }
187 
tabLabel(QWidget * w)188     inline QT3_SUPPORT QString tabLabel(QWidget *w) const  {return tabText(indexOf(w)); }
setTabLabel(QWidget * w,const QString & l)189     inline QT3_SUPPORT void setTabLabel(QWidget *w, const QString &l) { setTabText(indexOf(w), l); }
190 
tabIconSet(QWidget * w)191     inline QT3_SUPPORT QIcon tabIconSet(QWidget * w) const  {return tabIcon(indexOf(w)); }
setTabIconSet(QWidget * w,const QIcon & icon)192     inline QT3_SUPPORT void setTabIconSet(QWidget * w, const QIcon & icon) { setTabIcon(indexOf(w), icon); }
193 
removeTabToolTip(QWidget * w)194     inline QT3_SUPPORT void removeTabToolTip(QWidget * w) {
195 #ifndef QT_NO_TOOLTIP
196         setTabToolTip(indexOf(w), QString());
197 #else
198         Q_UNUSED(w);
199 #endif
200     }
setTabToolTip(QWidget * w,const QString & tip)201     inline QT3_SUPPORT void setTabToolTip(QWidget * w, const QString & tip) {
202 #ifndef QT_NO_TOOLTIP
203         setTabToolTip(indexOf(w), tip);
204 #else
205         Q_UNUSED(w);
206         Q_UNUSED(tip);
207 #endif
208     }
209 
tabToolTip(QWidget * w)210     inline QT3_SUPPORT QString tabToolTip(QWidget * w) const {
211 #ifndef QT_NO_TOOLTIP
212         return tabToolTip(indexOf(w));
213 #else
214         Q_UNUSED(w);
215         return QString();
216 #endif
217     }
218 
currentPage()219     inline QT3_SUPPORT QWidget * currentPage() const { return currentWidget(); }
page(int index)220     inline QT3_SUPPORT QWidget *page(int index) const { return widget(index); }
label(int index)221     inline QT3_SUPPORT QString label(int index) const { return tabText(index); }
currentPageIndex()222     inline QT3_SUPPORT int currentPageIndex() const { return currentIndex(); }
223 
margin()224     inline QT3_SUPPORT int margin() const { return 0; }
setMargin(int)225     inline QT3_SUPPORT void setMargin(int) {}
226 
227 public Q_SLOTS:
setCurrentPage(int index)228     inline QT_MOC_COMPAT void setCurrentPage(int index) { setCurrentIndex(index); }
showPage(QWidget * w)229     inline QT_MOC_COMPAT void showPage(QWidget *w) { setCurrentIndex(indexOf(w)); }
removePage(QWidget * w)230     inline QT_MOC_COMPAT void removePage(QWidget *w) { removeTab(indexOf(w)); }
231 
232 Q_SIGNALS:
233     QT_MOC_COMPAT void currentChanged(QWidget *);
234     QT_MOC_COMPAT void selected(const QString&);
235 #endif // QT3_SUPPORT
236 
237 private:
238     Q_DECLARE_PRIVATE(QTabWidget)
239     Q_DISABLE_COPY(QTabWidget)
240     Q_PRIVATE_SLOT(d_func(), void _q_showTab(int))
241     Q_PRIVATE_SLOT(d_func(), void _q_removeTab(int))
242     Q_PRIVATE_SLOT(d_func(), void _q_tabMoved(int, int))
243     void setUpLayout(bool = false);
244     friend class Q3TabDialog;
245 };
246 
247 #endif // QT_NO_TABWIDGET
248 
249 QT_END_NAMESPACE
250 
251 QT_END_HEADER
252 
253 #endif // QTABWIDGET_H
254