Qt 4.8
qtabbar.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 QTABBAR_H
43 #define QTABBAR_H
44 
45 #include <QtGui/qwidget.h>
46 
48 
50 
51 QT_MODULE(Gui)
52 
53 #ifndef QT_NO_TABBAR
54 
55 class QIcon;
56 class QTabBarPrivate;
57 class QStyleOptionTab;
58 
60 {
61  Q_OBJECT
62 
63  Q_ENUMS(Shape)
64  Shape shape;
65  int currentIndex;
66  int count;
67  bool drawBase;
68  QSize iconSize;
69  Qt::TextElideMode elideMode;
70  bool usesScrollButtons;
71  bool tabsClosable;
72  SelectionBehavior selectionBehaviorOnRemove;
73  bool expanding;
74  bool movable;
75  bool documentMode;
76 
77 public:
78  explicit QTabBar(QWidget* parent=0);
79  ~QTabBar();
80 
81  enum Shape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast,
82  TriangularNorth, TriangularSouth, TriangularWest, TriangularEast
83 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
84  , RoundedAbove = RoundedNorth, RoundedBelow = RoundedSouth,
85  TriangularAbove = TriangularNorth, TriangularBelow = TriangularSouth
86 #endif
87  };
88 
91  RightSide
92  };
93 
97  SelectPreviousTab
98  };
99 
100  Shape shape() const;
101  void setShape(Shape shape);
102 
103  int addTab(const QString &text);
104  int addTab(const QIcon &icon, const QString &text);
105 
106  int insertTab(int index, const QString &text);
107  int insertTab(int index, const QIcon&icon, const QString &text);
108 
109  void removeTab(int index);
110  void moveTab(int from, int to);
111 
112  bool isTabEnabled(int index) const;
113  void setTabEnabled(int index, bool);
114 
115  QString tabText(int index) const;
116  void setTabText(int index, const QString &text);
117 
118  QColor tabTextColor(int index) const;
119  void setTabTextColor(int index, const QColor &color);
120 
121  QIcon tabIcon(int index) const;
122  void setTabIcon(int index, const QIcon &icon);
123 
124  Qt::TextElideMode elideMode() const;
125  void setElideMode(Qt::TextElideMode);
126 
127 #ifndef QT_NO_TOOLTIP
128  void setTabToolTip(int index, const QString &tip);
129  QString tabToolTip(int index) const;
130 #endif
131 
132 #ifndef QT_NO_WHATSTHIS
133  void setTabWhatsThis(int index, const QString &text);
134  QString tabWhatsThis(int index) const;
135 #endif
136 
137  void setTabData(int index, const QVariant &data);
138  QVariant tabData(int index) const;
139 
140  QRect tabRect(int index) const;
141  int tabAt(const QPoint &pos) const;
142 
143  int currentIndex() const;
144  int count() const;
145 
146  QSize sizeHint() const;
147  QSize minimumSizeHint() const;
148 
149  void setDrawBase(bool drawTheBase);
150  bool drawBase() const;
151 
152  QSize iconSize() const;
153  void setIconSize(const QSize &size);
154 
155  bool usesScrollButtons() const;
156  void setUsesScrollButtons(bool useButtons);
157 
158  bool tabsClosable() const;
159  void setTabsClosable(bool closable);
160 
161  void setTabButton(int index, ButtonPosition position, QWidget *widget);
162  QWidget *tabButton(int index, ButtonPosition position) const;
163 
164  SelectionBehavior selectionBehaviorOnRemove() const;
165  void setSelectionBehaviorOnRemove(SelectionBehavior behavior);
166 
167  bool expanding() const;
168  void setExpanding(bool enabled);
169 
170  bool isMovable() const;
171  void setMovable(bool movable);
172 
173  bool documentMode() const;
174  void setDocumentMode(bool set);
175 
176 public Q_SLOTS:
177  void setCurrentIndex(int index);
178 
179 Q_SIGNALS:
180  void currentChanged(int index);
181  void tabCloseRequested(int index);
182  void tabMoved(int from, int to);
183 
184 protected:
185  virtual QSize tabSizeHint(int index) const;
186  virtual void tabInserted(int index);
187  virtual void tabRemoved(int index);
188  virtual void tabLayoutChange();
189 
190  bool event(QEvent *);
191  void resizeEvent(QResizeEvent *);
192  void showEvent(QShowEvent *);
193  void hideEvent(QHideEvent *);
194  void paintEvent(QPaintEvent *);
195  void mousePressEvent (QMouseEvent *);
196  void mouseMoveEvent (QMouseEvent *);
198 #ifndef QT_NO_WHEELEVENT
200 #endif
201  void keyPressEvent(QKeyEvent *);
202  void changeEvent(QEvent *);
203  void initStyleOption(QStyleOptionTab *option, int tabIndex) const;
204 
205 #ifdef QT3_SUPPORT
206 public Q_SLOTS:
207  QT_MOC_COMPAT void setCurrentTab(int index) { setCurrentIndex(index); }
208 Q_SIGNALS:
209  QT_MOC_COMPAT void selected(int);
210 #endif
211 
212  friend class QAccessibleTabBar;
213 private:
216  Q_PRIVATE_SLOT(d_func(), void _q_scrollTabs())
217  Q_PRIVATE_SLOT(d_func(), void _q_closeTab())
218 };
219 
220 #endif // QT_NO_TABBAR
221 
223 
225 
226 #endif // QTABBAR_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
#define QT_MOC_COMPAT
Definition: qglobal.h:1128
The QKeyEvent class describes a key event.
Definition: qevent.h:224
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual QSize minimumSizeHint() const
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QWheelEvent class contains parameters that describe a wheel event.
Definition: qevent.h:139
virtual void mouseReleaseEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse release even...
Definition: qwidget.cpp:9286
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
ButtonPosition
This enum type lists the location of the widget on a tab.
Definition: qtabbar.h:89
TextElideMode
Definition: qnamespace.h:263
virtual void mousePressEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
Definition: qwidget.cpp:9261
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QTabBar class provides a tab bar, e.g.
Definition: qtabbar.h:59
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_SIGNALS
Definition: qobjectdefs.h:72
virtual QSize sizeHint() const
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
virtual void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qwidget.cpp:9548
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
Shape
This enum type lists the built-in shapes supported by QTabBar.
Definition: qtabbar.h:81
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
static const char * data(const QByteArray &arr)
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
virtual void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwidget.cpp:9375
#define Q_OBJECT
Definition: qobjectdefs.h:157
The QMouseEvent class contains parameters that describe a mouse event.
Definition: qevent.h:85
SelectionBehavior
This enum type lists the behavior of QTabBar when a tab is removed and the tab being removed is also ...
Definition: qtabbar.h:94
virtual void wheelEvent(QWheelEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive wheel events for t...
Definition: qwidget.cpp:9326
virtual void hideEvent(QHideEvent *)
This event handler can be reimplemented in a subclass to receive widget hide events.
Definition: qwidget.cpp:9864
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Definition: qnamespace.h:54
quint16 index
The QStyleOptionTab class is used to describe the parameters for drawing a tab bar.
Definition: qstyleoption.h:304
The QAccessibleTabBar class implements the QAccessibleInterface for tab bars.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
virtual void mouseMoveEvent(QMouseEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events ...
Definition: qwidget.cpp:9239
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
#define enabled
#define text
Definition: qobjectdefs.h:80
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60