QtGui/qtabwidget.h Source File

qtabwidget.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/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 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
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 
49 
51 
52 QT_MODULE(Gui)
53 
54 #ifndef QT_NO_TABWIDGET
55 
56 class QTabBar;
57 class QTabWidgetPrivate;
59 
60 class Q_GUI_EXPORT QTabWidget : public QWidget
61 {
62  Q_OBJECT
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)
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 
181  inline QT3_SUPPORT void changeTab(QWidget *w, const QString &s) {setTabText(indexOf(w), s); }
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 
185  inline QT3_SUPPORT bool isTabEnabled( QWidget *w) const {return isTabEnabled(indexOf(w)); }
186  inline QT3_SUPPORT void setTabEnabled(QWidget *w, bool b) { setTabEnabled(indexOf(w), b); }
187 
188  inline QT3_SUPPORT QString tabLabel(QWidget *w) const {return tabText(indexOf(w)); }
189  inline QT3_SUPPORT void setTabLabel(QWidget *w, const QString &l) { setTabText(indexOf(w), l); }
190 
191  inline QT3_SUPPORT QIcon tabIconSet(QWidget * w) const {return tabIcon(indexOf(w)); }
192  inline QT3_SUPPORT void setTabIconSet(QWidget * w, const QIcon & icon) { setTabIcon(indexOf(w), icon); }
193 
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  }
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 
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 
219  inline QT3_SUPPORT QWidget * currentPage() const { return currentWidget(); }
220  inline QT3_SUPPORT QWidget *page(int index) const { return widget(index); }
221  inline QT3_SUPPORT QString label(int index) const { return tabText(index); }
222  inline QT3_SUPPORT int currentPageIndex() const { return currentIndex(); }
223 
224  inline QT3_SUPPORT int margin() const { return 0; }
225  inline QT3_SUPPORT void setMargin(int) {}
226 
227 public Q_SLOTS:
228  inline QT_MOC_COMPAT void setCurrentPage(int index) { setCurrentIndex(index); }
229  inline QT_MOC_COMPAT void showPage(QWidget *w) { setCurrentIndex(indexOf(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 
250 
252 
253 #endif // QTABWIDGET_H
bool event(QEvent *)
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
Corner
Definition: qnamespace.h:1456
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
GLenum GLsizei width
Definition: GLee.h:873
virtual void keyPressEvent(QKeyEvent *)
Definition: qnamespace.h:54
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
virtual void resizeEvent(QResizeEvent *)
#define Q_SLOTS
Definition: qobjectdefs.h:71
#define Q_SIGNALS
Definition: qobjectdefs.h:72
Definition: qicon.h:60
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
virtual QSize sizeHint() const
GLuint GLuint GLsizei count
Definition: GLee.h:872
#define Q_OBJECT
Definition: qobjectdefs.h:157
TextElideMode
Definition: qnamespace.h:263
GLubyte GLubyte b
Definition: GLee.h:5404
virtual void showEvent(QShowEvent *)
Definition: qsize.h:53
GLuint const GLchar * name
Definition: GLee.h:1704
virtual void paintEvent(QPaintEvent *)
virtual int heightForWidth(int) const
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
virtual QSize minimumSizeHint() const
GLdouble s
Definition: GLee.h:1173
#define QT_END_HEADER
Definition: qglobal.h:142
GLclampf f
Definition: GLee.h:9303
GLsizeiptr size
Definition: GLee.h:1561
GLuint index
Definition: GLee.h:1704
virtual void changeEvent(QEvent *)