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 QDYNAMICDOCKWIDGET_H |
5 | #define QDYNAMICDOCKWIDGET_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qwidget.h> |
9 | |
10 | QT_REQUIRE_CONFIG(dockwidget); |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | class QDockAreaLayout; |
15 | class QDockWidgetPrivate; |
16 | class QMainWindow; |
17 | class QStyleOptionDockWidget; |
18 | |
19 | class Q_WIDGETS_EXPORT QDockWidget : public QWidget |
20 | { |
21 | Q_OBJECT |
22 | |
23 | Q_PROPERTY(bool floating READ isFloating WRITE setFloating) |
24 | Q_PROPERTY(DockWidgetFeatures features READ features WRITE setFeatures NOTIFY featuresChanged) |
25 | Q_PROPERTY(Qt::DockWidgetAreas allowedAreas READ allowedAreas |
26 | WRITE setAllowedAreas NOTIFY allowedAreasChanged) |
27 | Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle DESIGNABLE true) |
28 | |
29 | public: |
30 | explicit QDockWidget(const QString &title, QWidget *parent = nullptr, |
31 | Qt::WindowFlags flags = Qt::WindowFlags()); |
32 | explicit QDockWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); |
33 | ~QDockWidget(); |
34 | |
35 | QWidget *widget() const; |
36 | void setWidget(QWidget *widget); |
37 | |
38 | enum DockWidgetFeature { |
39 | DockWidgetClosable = 0x01, |
40 | DockWidgetMovable = 0x02, |
41 | DockWidgetFloatable = 0x04, |
42 | DockWidgetVerticalTitleBar = 0x08, |
43 | |
44 | DockWidgetFeatureMask = 0x0f, |
45 | NoDockWidgetFeatures = 0x00, |
46 | |
47 | Reserved = 0xff |
48 | }; |
49 | Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature) |
50 | Q_FLAG(DockWidgetFeatures) |
51 | |
52 | void setFeatures(DockWidgetFeatures features); |
53 | DockWidgetFeatures features() const; |
54 | |
55 | void setFloating(bool floating); |
56 | inline bool isFloating() const { return isWindow(); } |
57 | |
58 | void setAllowedAreas(Qt::DockWidgetAreas areas); |
59 | Qt::DockWidgetAreas allowedAreas() const; |
60 | |
61 | void setTitleBarWidget(QWidget *widget); |
62 | QWidget *titleBarWidget() const; |
63 | |
64 | inline bool isAreaAllowed(Qt::DockWidgetArea area) const |
65 | { return (allowedAreas() & area) == area; } |
66 | |
67 | #ifndef QT_NO_ACTION |
68 | QAction *toggleViewAction() const; |
69 | #endif |
70 | |
71 | Q_SIGNALS: |
72 | void featuresChanged(QDockWidget::DockWidgetFeatures features); |
73 | void topLevelChanged(bool topLevel); |
74 | void allowedAreasChanged(Qt::DockWidgetAreas allowedAreas); |
75 | void visibilityChanged(bool visible); //TODO depricate in Qt7: Better listen to hide/show events |
76 | void dockLocationChanged(Qt::DockWidgetArea area); |
77 | |
78 | protected: |
79 | void changeEvent(QEvent *event) override; |
80 | void closeEvent(QCloseEvent *event) override; |
81 | void paintEvent(QPaintEvent *event) override; |
82 | bool event(QEvent *event) override; |
83 | virtual void initStyleOption(QStyleOptionDockWidget *option) const; |
84 | |
85 | private: |
86 | Q_DECLARE_PRIVATE(QDockWidget) |
87 | Q_DISABLE_COPY(QDockWidget) |
88 | Q_PRIVATE_SLOT(d_func(), void _q_toggleView(bool)) |
89 | Q_PRIVATE_SLOT(d_func(), void _q_toggleTopLevel()) |
90 | friend class QDockAreaLayout; |
91 | friend class QDockWidgetItem; |
92 | friend class QMainWindowLayout; |
93 | friend class QDockWidgetLayout; |
94 | friend class QDockAreaLayoutInfo; |
95 | }; |
96 | |
97 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDockWidget::DockWidgetFeatures) |
98 | |
99 | QT_END_NAMESPACE |
100 | |
101 | #endif // QDYNAMICDOCKWIDGET_H |
102 | |