Qt 4.8
qtoolbox.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 QTOOLBOX_H
43 #define QTOOLBOX_H
44 
45 #include <QtGui/qframe.h>
46 #include <QtGui/qicon.h>
47 
49 
51 
52 QT_MODULE(Gui)
53 
54 #ifndef QT_NO_TOOLBOX
55 
56 class QToolBoxPrivate;
57 
59 {
60  Q_OBJECT
62  int count;
63 
64 public:
65  explicit QToolBox(QWidget *parent = 0, Qt::WindowFlags f = 0);
66  ~QToolBox();
67 
68  int addItem(QWidget *widget, const QString &text);
69  int addItem(QWidget *widget, const QIcon &icon, const QString &text);
70  int insertItem(int index, QWidget *widget, const QString &text);
71  int insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text);
72 
73  void removeItem(int index);
74 
75  void setItemEnabled(int index, bool enabled);
76  bool isItemEnabled(int index) const;
77 
78  void setItemText(int index, const QString &text);
79  QString itemText(int index) const;
80 
81  void setItemIcon(int index, const QIcon &icon);
82  QIcon itemIcon(int index) const;
83 
84 #ifndef QT_NO_TOOLTIP
85  void setItemToolTip(int index, const QString &toolTip);
86  QString itemToolTip(int index) const;
87 #endif
88 
89  int currentIndex() const;
90  QWidget *currentWidget() const;
91  QWidget *widget(int index) const;
92  int indexOf(QWidget *widget) const;
93  int count() const;
94 
95 public Q_SLOTS:
96  void setCurrentIndex(int index);
97  void setCurrentWidget(QWidget *widget);
98 
99 Q_SIGNALS:
100  void currentChanged(int index);
101 
102 protected:
103  bool event(QEvent *e);
104  virtual void itemInserted(int index);
105  virtual void itemRemoved(int index);
106  void showEvent(QShowEvent *e);
107  void changeEvent(QEvent *);
108 
109 public:
110 #ifdef QT3_SUPPORT
111  QT3_SUPPORT_CONSTRUCTOR QToolBox(QWidget *parent, const char *name, Qt::WindowFlags f = 0);
112  inline QT3_SUPPORT void setItemLabel(int index, const QString &text) { setItemText(index, text); }
113  inline QT3_SUPPORT QString itemLabel(int index) const { return itemText(index); }
114  inline QT3_SUPPORT QWidget *currentItem() const { return widget(currentIndex()); }
115  inline QT3_SUPPORT void setCurrentItem(QWidget *item) { setCurrentIndex(indexOf(item)); }
116  inline QT3_SUPPORT void setItemIconSet(int index, const QIcon &icon) { setItemIcon(index, icon); }
117  inline QT3_SUPPORT QIcon itemIconSet(int index) const { return itemIcon(index); }
118  inline QT3_SUPPORT int removeItem(QWidget *item)
119  { int i = indexOf(item); removeItem(i); return i; }
120  inline QT3_SUPPORT QWidget *item(int index) const { return widget(index); }
121  QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
122  QT3_SUPPORT int margin() const
123  { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy); return margin; }
124 #endif
125 
126 private:
129  Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked())
130  Q_PRIVATE_SLOT(d_func(), void _q_widgetDestroyed(QObject*))
131 };
132 
133 
134 inline int QToolBox::addItem(QWidget *item, const QString &text)
135 { return insertItem(-1, item, QIcon(), text); }
136 inline int QToolBox::addItem(QWidget *item, const QIcon &iconSet,
137  const QString &text)
138 { return insertItem(-1, item, iconSet, text); }
139 inline int QToolBox::insertItem(int index, QWidget *item, const QString &text)
140 { return insertItem(index, item, QIcon(), text); }
141 
142 #endif // QT_NO_TOOLBOX
143 
145 
147 
148 #endif // QTOOLBOX_H
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
The QToolBox class provides a column of tabbed widget items.
Definition: qtoolbox.h:58
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#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
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qframe.cpp:574
void getContentsMargins(int *left, int *top, int *right, int *bottom) const
Returns the widget&#39;s contents margins for left, top, right, and bottom.
Definition: qwidget.cpp:7509
void setContentsMargins(int left, int top, int right, int bottom)
Sets the margins around the contents of the widget to have the sizes left, top, right, and bottom.
Definition: qwidget.cpp:7449
const char * name
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
#define Q_OBJECT
Definition: qobjectdefs.h:157
bool event(QEvent *e)
Reimplemented Function
Definition: qframe.cpp:587
int insertItem(int index, QWidget *widget, const QString &text)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtoolbox.h:139
int count
The number of items contained in the toolbox.
Definition: qtoolbox.h:62
quint16 index
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
int currentIndex
the index of the current item
Definition: qtoolbox.h:61
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
The QFrame class is the base class of widgets that can have a frame.
Definition: qframe.h:55
#define QT_END_HEADER
Definition: qglobal.h:137
#define enabled
#define text
Definition: qobjectdefs.h:80
int addItem(QWidget *widget, const QString &text)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qtoolbox.h:134
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60