qtoolbox.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QTOOLBOX_H
00043 #define QTOOLBOX_H
00044 
00045 #include <QtGui/qframe.h>
00046 #include <QtGui/qicon.h>
00047 
00048 QT_BEGIN_HEADER
00049 
00050 QT_BEGIN_NAMESPACE
00051 
00052 QT_MODULE(Gui)
00053 
00054 #ifndef QT_NO_TOOLBOX
00055 
00056 class QToolBoxPrivate;
00057 
00058 class Q_GUI_EXPORT QToolBox : public QFrame
00059 {
00060     Q_OBJECT
00061     Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged)
00062     Q_PROPERTY(int count READ count)
00063 
00064 public:
00065     explicit QToolBox(QWidget *parent = 0, Qt::WindowFlags f = 0);
00066     ~QToolBox();
00067 
00068     int addItem(QWidget *widget, const QString &text);
00069     int addItem(QWidget *widget, const QIcon &icon, const QString &text);
00070     int insertItem(int index, QWidget *widget, const QString &text);
00071     int insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text);
00072 
00073     void removeItem(int index);
00074 
00075     void setItemEnabled(int index, bool enabled);
00076     bool isItemEnabled(int index) const;
00077 
00078     void setItemText(int index, const QString &text);
00079     QString itemText(int index) const;
00080 
00081     void setItemIcon(int index, const QIcon &icon);
00082     QIcon itemIcon(int index) const;
00083 
00084 #ifndef QT_NO_TOOLTIP
00085     void setItemToolTip(int index, const QString &toolTip);
00086     QString itemToolTip(int index) const;
00087 #endif
00088 
00089     int currentIndex() const;
00090     QWidget *currentWidget() const;
00091     QWidget *widget(int index) const;
00092     int indexOf(QWidget *widget) const;
00093     int count() const;
00094 
00095 public Q_SLOTS:
00096     void setCurrentIndex(int index);
00097     void setCurrentWidget(QWidget *widget);
00098 
00099 Q_SIGNALS:
00100     void currentChanged(int index);
00101 
00102 protected:
00103     bool event(QEvent *e);
00104     virtual void itemInserted(int index);
00105     virtual void itemRemoved(int index);
00106     void showEvent(QShowEvent *e);
00107     void changeEvent(QEvent *);
00108 
00109 #ifdef QT3_SUPPORT
00110 public:
00111     QT3_SUPPORT_CONSTRUCTOR QToolBox(QWidget *parent, const char *name, Qt::WindowFlags f = 0);
00112     inline QT3_SUPPORT void setItemLabel(int index, const QString &text) { setItemText(index, text); }
00113     inline QT3_SUPPORT QString itemLabel(int index) const { return itemText(index); }
00114     inline QT3_SUPPORT QWidget *currentItem() const { return widget(currentIndex()); }
00115     inline QT3_SUPPORT void setCurrentItem(QWidget *item) { setCurrentIndex(indexOf(item)); }
00116     inline QT3_SUPPORT void setItemIconSet(int index, const QIcon &icon) { setItemIcon(index, icon); }
00117     inline QT3_SUPPORT QIcon itemIconSet(int index) const { return itemIcon(index); }
00118     inline QT3_SUPPORT int removeItem(QWidget *item)
00119     { int i = indexOf(item); removeItem(i); return i; }
00120     inline QT3_SUPPORT QWidget *item(int index) const { return widget(index); }
00121     QT3_SUPPORT void setMargin(int margin) { setContentsMargins(margin, margin, margin, margin); }
00122     QT3_SUPPORT int margin() const
00123     { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy);  return margin; }
00124 #endif
00125 
00126 private:
00127     Q_DECLARE_PRIVATE(QToolBox)
00128     Q_DISABLE_COPY(QToolBox)
00129     Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked())
00130     Q_PRIVATE_SLOT(d_func(), void _q_widgetDestroyed(QObject*))
00131 };
00132 
00133 
00134 inline int QToolBox::addItem(QWidget *item, const QString &text)
00135 { return insertItem(-1, item, QIcon(), text); }
00136 inline int QToolBox::addItem(QWidget *item, const QIcon &iconSet,
00137                               const QString &text)
00138 { return insertItem(-1, item, iconSet, text); }
00139 inline int QToolBox::insertItem(int index, QWidget *item, const QString &text)
00140 { return insertItem(index, item, QIcon(), text); }
00141 
00142 #endif // QT_NO_TOOLBOX
00143 
00144 QT_END_NAMESPACE
00145 
00146 QT_END_HEADER
00147 
00148 #endif // QTOOLBOX_H