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 NOTIFY topLevelChanged) |
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_DEBUG_STREAM |
68 | friend Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QDockWidget *dockWidget); |
69 | #endif |
70 | |
71 | #ifndef QT_NO_ACTION |
72 | QAction *toggleViewAction() const; |
73 | #endif |
74 | |
75 | Q_SIGNALS: |
76 | void featuresChanged(QDockWidget::DockWidgetFeatures features); |
77 | void topLevelChanged(bool topLevel); |
78 | void allowedAreasChanged(Qt::DockWidgetAreas allowedAreas); |
79 | void visibilityChanged(bool visible); // ### Qt7: Deprecate this. Better listen to hide/show events |
80 | void dockLocationChanged(Qt::DockWidgetArea area); |
81 | |
82 | protected: |
83 | void changeEvent(QEvent *event) override; |
84 | void closeEvent(QCloseEvent *event) override; |
85 | void paintEvent(QPaintEvent *event) override; |
86 | bool event(QEvent *event) override; |
87 | virtual void initStyleOption(QStyleOptionDockWidget *option) const; |
88 | |
89 | private: |
90 | Q_DECLARE_PRIVATE(QDockWidget) |
91 | Q_DISABLE_COPY(QDockWidget) |
92 | friend class QDockAreaLayout; |
93 | friend class QDockWidgetItem; |
94 | friend class QMainWindowLayout; |
95 | friend class QDockWidgetLayout; |
96 | friend class QDockAreaLayoutInfo; |
97 | }; |
98 | |
99 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDockWidget::DockWidgetFeatures) |
100 | |
101 | QT_END_NAMESPACE |
102 | |
103 | #endif // QDYNAMICDOCKWIDGET_H |
104 | |