| 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 | Q_PROPERTY(Qt::DockWidgetArea dockLocation READ dockLocation WRITE setDockLocation |
| 29 | NOTIFY dockLocationChanged) |
| 30 | |
| 31 | public: |
| 32 | explicit QDockWidget(const QString &title, QWidget *parent = nullptr, |
| 33 | Qt::WindowFlags flags = Qt::WindowFlags()); |
| 34 | explicit QDockWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); |
| 35 | ~QDockWidget(); |
| 36 | |
| 37 | QWidget *widget() const; |
| 38 | void setWidget(QWidget *widget); |
| 39 | |
| 40 | enum DockWidgetFeature { |
| 41 | DockWidgetClosable = 0x01, |
| 42 | DockWidgetMovable = 0x02, |
| 43 | DockWidgetFloatable = 0x04, |
| 44 | DockWidgetVerticalTitleBar = 0x08, |
| 45 | |
| 46 | DockWidgetFeatureMask = 0x0f, |
| 47 | NoDockWidgetFeatures = 0x00, |
| 48 | |
| 49 | Reserved = 0xff |
| 50 | }; |
| 51 | Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature) |
| 52 | Q_FLAG(DockWidgetFeatures) |
| 53 | |
| 54 | void setFeatures(DockWidgetFeatures features); |
| 55 | DockWidgetFeatures features() const; |
| 56 | |
| 57 | void setFloating(bool floating); |
| 58 | inline bool isFloating() const { return isWindow(); } |
| 59 | |
| 60 | void setAllowedAreas(Qt::DockWidgetAreas areas); |
| 61 | Qt::DockWidgetAreas allowedAreas() const; |
| 62 | |
| 63 | void setTitleBarWidget(QWidget *widget); |
| 64 | QWidget *titleBarWidget() const; |
| 65 | |
| 66 | void setDockLocation(Qt::DockWidgetArea area); |
| 67 | Qt::DockWidgetArea dockLocation() const; |
| 68 | |
| 69 | inline bool isAreaAllowed(Qt::DockWidgetArea area) const |
| 70 | { return (allowedAreas() & area) == area; } |
| 71 | |
| 72 | #ifndef QT_NO_DEBUG_STREAM |
| 73 | friend Q_WIDGETS_EXPORT QDebug operator<<(QDebug dbg, const QDockWidget *dockWidget); |
| 74 | #endif |
| 75 | |
| 76 | #ifndef QT_NO_ACTION |
| 77 | QAction *toggleViewAction() const; |
| 78 | #endif |
| 79 | |
| 80 | Q_SIGNALS: |
| 81 | void featuresChanged(QDockWidget::DockWidgetFeatures features); |
| 82 | void topLevelChanged(bool topLevel); |
| 83 | void allowedAreasChanged(Qt::DockWidgetAreas allowedAreas); |
| 84 | void visibilityChanged(bool visible); // ### Qt7: Deprecate this. Better listen to hide/show events |
| 85 | void dockLocationChanged(Qt::DockWidgetArea area); |
| 86 | |
| 87 | protected: |
| 88 | void changeEvent(QEvent *event) override; |
| 89 | void closeEvent(QCloseEvent *event) override; |
| 90 | void paintEvent(QPaintEvent *event) override; |
| 91 | bool event(QEvent *event) override; |
| 92 | virtual void initStyleOption(QStyleOptionDockWidget *option) const; |
| 93 | |
| 94 | private: |
| 95 | Q_DECLARE_PRIVATE(QDockWidget) |
| 96 | Q_DISABLE_COPY(QDockWidget) |
| 97 | friend class QDockAreaLayout; |
| 98 | friend class QDockWidgetItem; |
| 99 | friend class QMainWindowLayout; |
| 100 | friend class QDockWidgetLayout; |
| 101 | friend class QDockAreaLayoutInfo; |
| 102 | }; |
| 103 | |
| 104 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDockWidget::DockWidgetFeatures) |
| 105 | |
| 106 | QT_END_NAMESPACE |
| 107 | |
| 108 | #endif // QDYNAMICDOCKWIDGET_H |
| 109 | |