| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#ifndef GUI_DOCKWND_TOOLBOX_H |
| 24 |
#define GUI_DOCKWND_TOOLBOX_H |
| 25 |
|
| 26 |
#include <QWidget> |
| 27 |
#include <FCGlobal.h> |
| 28 |
|
| 29 |
class QToolBox; |
| 30 |
|
| 31 |
namespace Gui |
| 32 |
{ |
| 33 |
|
| 34 |
namespace DockWnd |
| 35 |
{ |
| 36 |
|
| 37 |
/** The ToolBox class provides a column of tabbed widget items. |
| 38 |
* A toolbox is a widget that displays a column of tabs one above the other, with the current item |
| 39 |
* displayed below the current tab. Every tab has an index position within the column of tabs. A |
| 40 |
* tab's item is a QWidget. |
| 41 |
* |
| 42 |
* Each item has an itemLabel(), an optional icon, itemIconSet(), an optional itemToolTip(), and a |
| 43 |
* widget. The item's attributes can be changed with setItemLabel(), setItemIconSet() and |
| 44 |
* setItemToolTip(). |
| 45 |
* |
| 46 |
* Items are added using addItem(), or inserted at particular positions using insertItem(). The |
| 47 |
* total number of items is given by count(). Items can be deleted with delete, or removed from the |
| 48 |
* toolbox with removeItem(). Combining removeItem() and insertItem() allows one to move items to |
| 49 |
* different positions. |
| 50 |
* |
| 51 |
* The current item widget is returned by currentItem() and set with setCurrentItem(). If you prefer |
| 52 |
* you can work in terms of indexes using currentIndex(), setCurrentIndex(), indexOf() and item(). |
| 53 |
* |
| 54 |
* The currentChanged() signal is emitted when the current item is changed. |
| 55 |
* |
| 56 |
* \a Note: This class implements the same API as the QToolBox does provided by Qt unless |
| 57 |
* removeItem(), which also deletes the item to be removed. |
| 58 |
* \author Werner Mayer |
| 59 |
*/ |
| 60 |
class GuiExport ToolBox: public QWidget |
| 61 |
{ |
| 62 |
Q_OBJECT |
| 63 |
|
| 64 |
public: |
| 65 |
ToolBox(QWidget* parent = nullptr); |
| 66 |
~ToolBox() override; |
| 67 |
|
| 68 |
int addItem(QWidget* w, const QString& label); |
| 69 |
int addItem(QWidget* item, const QIcon& iconSet, const QString& label); |
| 70 |
int insertItem(int index, QWidget* item, const QString& label); |
| 71 |
int insertItem(int index, QWidget* item, const QIcon& iconSet, const QString& label); |
| 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& label); |
| 79 |
QString itemText(int index) const; |
| 80 |
|
| 81 |
void setItemIcon(int index, const QIcon& iconSet); |
| 82 |
QIcon itemIcon(int index) const; |
| 83 |
|
| 84 |
void setItemToolTip(int index, const QString& toolTip); |
| 85 |
QString itemToolTip(int index) const; |
| 86 |
|
| 87 |
QWidget* currentWidget() const; |
| 88 |
|
| 89 |
int currentIndex() const; |
| 90 |
QWidget* widget(int index) const; |
| 91 |
int indexOf(QWidget* item) const; |
| 92 |
int count() const; |
| 93 |
|
| 94 |
public Q_SLOTS: |
| 95 |
void setCurrentIndex(int index); |
| 96 |
void setCurrentWidget(QWidget* item); |
| 97 |
|
| 98 |
protected: |
| 99 |
void changeEvent(QEvent* e) override; |
| 100 |
|
| 101 |
Q_SIGNALS: |
| 102 |
/** This signal is emitted when the current item changed. |
| 103 |
* The new current item's index is passed in index, or -1 if there is no current item. |
| 104 |
*/ |
| 105 |
void currentChanged(int index); |
| 106 |
|
| 107 |
private: |
| 108 |
QToolBox* _pToolBox; |
| 109 |
}; |
| 110 |
|
| 111 |
} // namespace DockWnd |
| 112 |
} // namespace Gui |
| 113 |
|
| 114 |
#endif // GUI_DOCKWND_TOOLBOX_H |