| 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_P_H |
| 5 | #define QDYNAMICDOCKWIDGET_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtWidgets/private/qtwidgetsglobal_p.h> |
| 19 | #include "QtWidgets/qstyleoption.h" |
| 20 | #include "private/qwidget_p.h" |
| 21 | #include "QtWidgets/qboxlayout.h" |
| 22 | #include "QtWidgets/qdockwidget.h" |
| 23 | |
| 24 | #if QT_CONFIG(tabwidget) |
| 25 | # include "QtWidgets/qtabwidget.h" |
| 26 | #endif |
| 27 | |
| 28 | QT_REQUIRE_CONFIG(dockwidget); |
| 29 | |
| 30 | QT_BEGIN_NAMESPACE |
| 31 | |
| 32 | class QGridLayout; |
| 33 | class QWidgetResizeHandler; |
| 34 | class QDockWidgetTitleButton; |
| 35 | class QSpacerItem; |
| 36 | class QDockWidgetItem; |
| 37 | |
| 38 | class QDockWidgetPrivate : public QWidgetPrivate |
| 39 | { |
| 40 | Q_DECLARE_PUBLIC(QDockWidget) |
| 41 | |
| 42 | struct DragState { |
| 43 | QPoint pressPos; |
| 44 | QPoint globalPressPos; |
| 45 | QPoint widgetInitialPos; |
| 46 | bool dragging; |
| 47 | QLayoutItem *widgetItem; |
| 48 | bool ownWidgetItem; |
| 49 | bool nca; |
| 50 | bool ctrlDrag; |
| 51 | }; |
| 52 | |
| 53 | public: |
| 54 | enum class DragScope { |
| 55 | Group, |
| 56 | Widget |
| 57 | }; |
| 58 | |
| 59 | enum class EndDragMode { |
| 60 | LocationChange, |
| 61 | Abort |
| 62 | }; |
| 63 | |
| 64 | enum class WindowState { |
| 65 | Unplug = 0x01, |
| 66 | Floating = 0x02, |
| 67 | }; |
| 68 | Q_DECLARE_FLAGS(WindowStates, WindowState) |
| 69 | |
| 70 | void init(); |
| 71 | void toggleView(bool); |
| 72 | void toggleTopLevel(); |
| 73 | |
| 74 | void updateButtons(); |
| 75 | static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos); |
| 76 | |
| 77 | #if QT_CONFIG(tabwidget) |
| 78 | QTabWidget::TabPosition tabPosition = QTabWidget::North; |
| 79 | #endif |
| 80 | |
| 81 | DragState *state = nullptr; |
| 82 | |
| 83 | QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable |
| 84 | | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable; |
| 85 | Qt::DockWidgetAreas allowedAreas = Qt::AllDockWidgetAreas; |
| 86 | |
| 87 | QFont font; |
| 88 | |
| 89 | #ifndef QT_NO_ACTION |
| 90 | QAction *toggleViewAction = nullptr; |
| 91 | #endif |
| 92 | |
| 93 | // QMainWindow *findMainWindow(QWidget *widget) const; |
| 94 | QRect undockedGeometry; |
| 95 | QString fixedWindowTitle; |
| 96 | QString dockedWindowTitle; |
| 97 | bool inDestructor = false; |
| 98 | |
| 99 | bool mousePressEvent(QMouseEvent *event); |
| 100 | bool mouseDoubleClickEvent(QMouseEvent *event); |
| 101 | bool mouseMoveEvent(QMouseEvent *event); |
| 102 | bool mouseReleaseEvent(QMouseEvent *event); |
| 103 | void setWindowState(WindowStates states, const QRect &rect = QRect()); |
| 104 | void nonClientAreaMouseEvent(QMouseEvent *event); |
| 105 | void initDrag(const QPoint &pos, bool nca); |
| 106 | void startDrag(DragScope scope); |
| 107 | void endDrag(EndDragMode mode); |
| 108 | void moveEvent(QMoveEvent *event); |
| 109 | void recalculatePressPos(QResizeEvent *event); |
| 110 | |
| 111 | void unplug(const QRect &rect); |
| 112 | void plug(const QRect &rect); |
| 113 | void setResizerActive(bool active); |
| 114 | void setFloating(bool floating); |
| 115 | |
| 116 | bool isAnimating() const; |
| 117 | bool isTabbed() const; |
| 118 | |
| 119 | private: |
| 120 | QWidgetResizeHandler *resizer = nullptr; |
| 121 | }; |
| 122 | |
| 123 | class Q_WIDGETS_EXPORT QDockWidgetLayout : public QLayout |
| 124 | { |
| 125 | Q_OBJECT |
| 126 | public: |
| 127 | explicit QDockWidgetLayout(QWidget *parent = nullptr); |
| 128 | ~QDockWidgetLayout(); |
| 129 | void addItem(QLayoutItem *item) override; |
| 130 | QLayoutItem *itemAt(int index) const override; |
| 131 | QLayoutItem *takeAt(int index) override; |
| 132 | int count() const override; |
| 133 | |
| 134 | QSize maximumSize() const override; |
| 135 | QSize minimumSize() const override; |
| 136 | QSize sizeHint() const override; |
| 137 | |
| 138 | QSize sizeFromContent(const QSize &content, bool floating) const; |
| 139 | |
| 140 | void setGeometry(const QRect &r) override; |
| 141 | |
| 142 | enum Role { Content, CloseButton, FloatButton, TitleBar, RoleCount }; |
| 143 | QWidget *widgetForRole(Role r) const; |
| 144 | void setWidgetForRole(Role r, QWidget *w); |
| 145 | QLayoutItem *itemForRole(Role r) const; |
| 146 | |
| 147 | QRect titleArea() const { return _titleArea; } |
| 148 | |
| 149 | int minimumTitleWidth() const; |
| 150 | int titleHeight() const; |
| 151 | void updateMaxSize(); |
| 152 | static bool wmSupportsNativeWindowDeco(); |
| 153 | bool nativeWindowDeco() const; |
| 154 | bool nativeWindowDeco(bool floating) const; |
| 155 | |
| 156 | void setVerticalTitleBar(bool b); |
| 157 | |
| 158 | bool verticalTitleBar; |
| 159 | |
| 160 | private: |
| 161 | QList<QLayoutItem *> item_list; |
| 162 | QRect _titleArea; |
| 163 | }; |
| 164 | |
| 165 | /* The size hints of a QDockWidget will depend on whether it is docked or not. |
| 166 | This layout item always returns the size hints as if the dock widget was docked. */ |
| 167 | |
| 168 | class QDockWidgetItem : public QWidgetItem |
| 169 | { |
| 170 | public: |
| 171 | QDockWidgetItem(QDockWidget *dockWidget); |
| 172 | QSize minimumSize() const override; |
| 173 | QSize maximumSize() const override; |
| 174 | QSize sizeHint() const override; |
| 175 | |
| 176 | private: |
| 177 | inline QLayoutItem *dockWidgetChildItem() const; |
| 178 | inline QDockWidgetLayout *dockWidgetLayout() const; |
| 179 | }; |
| 180 | |
| 181 | inline QLayoutItem *QDockWidgetItem::dockWidgetChildItem() const |
| 182 | { |
| 183 | if (QDockWidgetLayout *layout = dockWidgetLayout()) |
| 184 | return layout->itemForRole(r: QDockWidgetLayout::Content); |
| 185 | return nullptr; |
| 186 | } |
| 187 | |
| 188 | inline QDockWidgetLayout *QDockWidgetItem::dockWidgetLayout() const |
| 189 | { |
| 190 | QWidget *w = widget(); |
| 191 | if (w != nullptr) |
| 192 | return qobject_cast<QDockWidgetLayout*>(object: w->layout()); |
| 193 | return nullptr; |
| 194 | } |
| 195 | |
| 196 | QT_END_NAMESPACE |
| 197 | |
| 198 | #endif // QDYNAMICDOCKWIDGET_P_H |
| 199 | |