1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTOOLBOX_H |
5 | #define QTOOLBOX_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qframe.h> |
9 | #include <QtGui/qicon.h> |
10 | |
11 | QT_REQUIRE_CONFIG(toolbox); |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QToolBoxPrivate; |
16 | |
17 | class Q_WIDGETS_EXPORT QToolBox : public QFrame |
18 | { |
19 | Q_OBJECT |
20 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentChanged) |
21 | Q_PROPERTY(int count READ count) |
22 | |
23 | public: |
24 | explicit QToolBox(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); |
25 | ~QToolBox(); |
26 | |
27 | int addItem(QWidget *widget, const QString &text); |
28 | int addItem(QWidget *widget, const QIcon &icon, const QString &text); |
29 | int insertItem(int index, QWidget *widget, const QString &text); |
30 | int insertItem(int index, QWidget *widget, const QIcon &icon, const QString &text); |
31 | |
32 | void removeItem(int index); |
33 | |
34 | void setItemEnabled(int index, bool enabled); |
35 | bool isItemEnabled(int index) const; |
36 | |
37 | void setItemText(int index, const QString &text); |
38 | QString itemText(int index) const; |
39 | |
40 | void setItemIcon(int index, const QIcon &icon); |
41 | QIcon itemIcon(int index) const; |
42 | |
43 | #if QT_CONFIG(tooltip) |
44 | void setItemToolTip(int index, const QString &toolTip); |
45 | QString itemToolTip(int index) const; |
46 | #endif |
47 | |
48 | int currentIndex() const; |
49 | QWidget *currentWidget() const; |
50 | QWidget *widget(int index) const; |
51 | int indexOf(const QWidget *widget) const; |
52 | int count() const; |
53 | |
54 | public Q_SLOTS: |
55 | void setCurrentIndex(int index); |
56 | void setCurrentWidget(QWidget *widget); |
57 | |
58 | Q_SIGNALS: |
59 | void currentChanged(int index); |
60 | |
61 | protected: |
62 | bool event(QEvent *e) override; |
63 | virtual void itemInserted(int index); |
64 | virtual void itemRemoved(int index); |
65 | void showEvent(QShowEvent *e) override; |
66 | void changeEvent(QEvent *) override; |
67 | |
68 | |
69 | private: |
70 | Q_DECLARE_PRIVATE(QToolBox) |
71 | Q_DISABLE_COPY(QToolBox) |
72 | Q_PRIVATE_SLOT(d_func(), void _q_buttonClicked()) |
73 | Q_PRIVATE_SLOT(d_func(), void _q_widgetDestroyed(QObject*)) |
74 | }; |
75 | |
76 | |
77 | inline int QToolBox::addItem(QWidget *item, const QString &text) |
78 | { return insertItem(index: -1, widget: item, icon: QIcon(), text); } |
79 | inline int QToolBox::addItem(QWidget *item, const QIcon &iconSet, |
80 | const QString &text) |
81 | { return insertItem(index: -1, widget: item, icon: iconSet, text); } |
82 | inline int QToolBox::insertItem(int index, QWidget *item, const QString &text) |
83 | { return insertItem(index, widget: item, icon: QIcon(), text); } |
84 | |
85 | QT_END_NAMESPACE |
86 | |
87 | #endif // QTOOLBOX_H |
88 | |