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 QDYNAMICTOOLBAR_H |
5 | #define QDYNAMICTOOLBAR_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtGui/qaction.h> |
9 | #include <QtWidgets/qwidget.h> |
10 | |
11 | QT_REQUIRE_CONFIG(toolbar); |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QToolBarPrivate; |
16 | |
17 | class QAction; |
18 | class QIcon; |
19 | class QMainWindow; |
20 | class QStyleOptionToolBar; |
21 | |
22 | class Q_WIDGETS_EXPORT QToolBar : public QWidget |
23 | { |
24 | Q_OBJECT |
25 | |
26 | Q_PROPERTY(bool movable READ isMovable WRITE setMovable NOTIFY movableChanged) |
27 | Q_PROPERTY(Qt::ToolBarAreas allowedAreas READ allowedAreas WRITE setAllowedAreas |
28 | NOTIFY allowedAreasChanged) |
29 | Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation |
30 | NOTIFY orientationChanged) |
31 | Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged) |
32 | Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle |
33 | NOTIFY toolButtonStyleChanged) |
34 | Q_PROPERTY(bool floating READ isFloating) |
35 | Q_PROPERTY(bool floatable READ isFloatable WRITE setFloatable) |
36 | |
37 | public: |
38 | explicit QToolBar(const QString &title, QWidget *parent = nullptr); |
39 | explicit QToolBar(QWidget *parent = nullptr); |
40 | ~QToolBar(); |
41 | |
42 | void setMovable(bool movable); |
43 | bool isMovable() const; |
44 | |
45 | void setAllowedAreas(Qt::ToolBarAreas areas); |
46 | Qt::ToolBarAreas allowedAreas() const; |
47 | |
48 | inline bool isAreaAllowed(Qt::ToolBarArea area) const |
49 | { return (allowedAreas() & area) == area; } |
50 | |
51 | void setOrientation(Qt::Orientation orientation); |
52 | Qt::Orientation orientation() const; |
53 | |
54 | void clear(); |
55 | |
56 | using QWidget::addAction; |
57 | #if QT_WIDGETS_REMOVED_SINCE(6, 3) |
58 | QAction *addAction(const QString &text); |
59 | QAction *addAction(const QIcon &icon, const QString &text); |
60 | QAction *addAction(const QString &text, const QObject *receiver, const char* member); |
61 | QAction *addAction(const QIcon &icon, const QString &text, |
62 | const QObject *receiver, const char* member); |
63 | #endif |
64 | |
65 | QAction *addSeparator(); |
66 | QAction *insertSeparator(QAction *before); |
67 | |
68 | QAction *addWidget(QWidget *widget); |
69 | QAction *insertWidget(QAction *before, QWidget *widget); |
70 | |
71 | QRect actionGeometry(QAction *action) const; |
72 | QAction *actionAt(const QPoint &p) const; |
73 | inline QAction *actionAt(int x, int y) const; |
74 | |
75 | QAction *toggleViewAction() const; |
76 | |
77 | QSize iconSize() const; |
78 | Qt::ToolButtonStyle toolButtonStyle() const; |
79 | |
80 | QWidget *widgetForAction(QAction *action) const; |
81 | |
82 | bool isFloatable() const; |
83 | void setFloatable(bool floatable); |
84 | bool isFloating() const; |
85 | |
86 | public Q_SLOTS: |
87 | void setIconSize(const QSize &iconSize); |
88 | void setToolButtonStyle(Qt::ToolButtonStyle toolButtonStyle); |
89 | |
90 | Q_SIGNALS: |
91 | void actionTriggered(QAction *action); |
92 | void movableChanged(bool movable); |
93 | void allowedAreasChanged(Qt::ToolBarAreas allowedAreas); |
94 | void orientationChanged(Qt::Orientation orientation); |
95 | void iconSizeChanged(const QSize &iconSize); |
96 | void toolButtonStyleChanged(Qt::ToolButtonStyle toolButtonStyle); |
97 | void topLevelChanged(bool topLevel); |
98 | void visibilityChanged(bool visible); |
99 | |
100 | protected: |
101 | void actionEvent(QActionEvent *event) override; |
102 | void changeEvent(QEvent *event) override; |
103 | void paintEvent(QPaintEvent *event) override; |
104 | bool event(QEvent *event) override; |
105 | virtual void initStyleOption(QStyleOptionToolBar *option) const; |
106 | |
107 | |
108 | private: |
109 | Q_DECLARE_PRIVATE(QToolBar) |
110 | Q_DISABLE_COPY(QToolBar) |
111 | Q_PRIVATE_SLOT(d_func(), void _q_toggleView(bool)) |
112 | Q_PRIVATE_SLOT(d_func(), void _q_updateIconSize(const QSize &)) |
113 | Q_PRIVATE_SLOT(d_func(), void _q_updateToolButtonStyle(Qt::ToolButtonStyle)) |
114 | |
115 | friend class QMainWindow; |
116 | friend class QMainWindowLayout; |
117 | friend class QToolBarLayout; |
118 | friend class QToolBarAreaLayout; |
119 | }; |
120 | |
121 | inline QAction *QToolBar::actionAt(int ax, int ay) const |
122 | { return actionAt(p: QPoint(ax, ay)); } |
123 | |
124 | QT_END_NAMESPACE |
125 | |
126 | #endif // QDYNAMICTOOLBAR_H |
127 | |