1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtWidgets module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QDYNAMICDOCKWIDGET_H 41 #define QDYNAMICDOCKWIDGET_H 42 43 #include <QtWidgets/qtwidgetsglobal.h> 44 #include <QtWidgets/qwidget.h> 45 46 QT_REQUIRE_CONFIG(dockwidget); 47 48 QT_BEGIN_NAMESPACE 49 50 class QDockAreaLayout; 51 class QDockWidgetPrivate; 52 class QMainWindow; 53 class QStyleOptionDockWidget; 54 55 class Q_WIDGETS_EXPORT QDockWidget : public QWidget 56 { 57 Q_OBJECT 58 59 Q_PROPERTY(bool floating READ isFloating WRITE setFloating) 60 Q_PROPERTY(DockWidgetFeatures features READ features WRITE setFeatures NOTIFY featuresChanged) 61 Q_PROPERTY(Qt::DockWidgetAreas allowedAreas READ allowedAreas 62 WRITE setAllowedAreas NOTIFY allowedAreasChanged) 63 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle DESIGNABLE true) 64 65 public: 66 explicit QDockWidget(const QString &title, QWidget *parent = nullptr, 67 Qt::WindowFlags flags = Qt::WindowFlags()); 68 explicit QDockWidget(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); 69 ~QDockWidget(); 70 71 QWidget *widget() const; 72 void setWidget(QWidget *widget); 73 74 enum DockWidgetFeature { 75 DockWidgetClosable = 0x01, 76 DockWidgetMovable = 0x02, 77 DockWidgetFloatable = 0x04, 78 DockWidgetVerticalTitleBar = 0x08, 79 80 DockWidgetFeatureMask = 0x0f, 81 #if QT_DEPRECATED_SINCE(5, 15) 82 AllDockWidgetFeatures Q_DECL_ENUMERATOR_DEPRECATED = 83 DockWidgetClosable|DockWidgetMovable|DockWidgetFloatable, // ### Qt 6: remove 84 #endif 85 NoDockWidgetFeatures = 0x00, 86 87 Reserved = 0xff 88 }; 89 Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature) 90 Q_FLAG(DockWidgetFeatures) 91 92 void setFeatures(DockWidgetFeatures features); 93 DockWidgetFeatures features() const; 94 95 void setFloating(bool floating); isFloating()96 inline bool isFloating() const { return isWindow(); } 97 98 void setAllowedAreas(Qt::DockWidgetAreas areas); 99 Qt::DockWidgetAreas allowedAreas() const; 100 101 void setTitleBarWidget(QWidget *widget); 102 QWidget *titleBarWidget() const; 103 isAreaAllowed(Qt::DockWidgetArea area)104 inline bool isAreaAllowed(Qt::DockWidgetArea area) const 105 { return (allowedAreas() & area) == area; } 106 107 #ifndef QT_NO_ACTION 108 QAction *toggleViewAction() const; 109 #endif 110 111 Q_SIGNALS: 112 void featuresChanged(QDockWidget::DockWidgetFeatures features); 113 void topLevelChanged(bool topLevel); 114 void allowedAreasChanged(Qt::DockWidgetAreas allowedAreas); 115 void visibilityChanged(bool visible); 116 void dockLocationChanged(Qt::DockWidgetArea area); 117 118 protected: 119 void changeEvent(QEvent *event) override; 120 void closeEvent(QCloseEvent *event) override; 121 void paintEvent(QPaintEvent *event) override; 122 bool event(QEvent *event) override; 123 void initStyleOption(QStyleOptionDockWidget *option) const; 124 125 private: 126 Q_DECLARE_PRIVATE(QDockWidget) 127 Q_DISABLE_COPY(QDockWidget) 128 Q_PRIVATE_SLOT(d_func(), void _q_toggleView(bool)) 129 Q_PRIVATE_SLOT(d_func(), void _q_toggleTopLevel()) 130 friend class QDockAreaLayout; 131 friend class QDockWidgetItem; 132 friend class QMainWindowLayout; 133 friend class QDockWidgetLayout; 134 friend class QDockAreaLayoutInfo; 135 }; 136 137 Q_DECLARE_OPERATORS_FOR_FLAGS(QDockWidget::DockWidgetFeatures) 138 139 QT_END_NAMESPACE 140 141 #endif // QDYNAMICDOCKWIDGET_H 142