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 | void init(); |
55 | void _q_toggleView(bool); // private slot |
56 | void _q_toggleTopLevel(); // private slot |
57 | |
58 | void updateButtons(); |
59 | static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos); |
60 | |
61 | #if QT_CONFIG(tabwidget) |
62 | QTabWidget::TabPosition tabPosition = QTabWidget::North; |
63 | #endif |
64 | |
65 | DragState *state = nullptr; |
66 | |
67 | QDockWidget::DockWidgetFeatures features = QDockWidget::DockWidgetClosable |
68 | | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable; |
69 | Qt::DockWidgetAreas allowedAreas = Qt::AllDockWidgetAreas; |
70 | |
71 | QFont font; |
72 | |
73 | #ifndef QT_NO_ACTION |
74 | QAction *toggleViewAction = nullptr; |
75 | #endif |
76 | |
77 | // QMainWindow *findMainWindow(QWidget *widget) const; |
78 | QRect undockedGeometry; |
79 | QString fixedWindowTitle; |
80 | QString dockedWindowTitle; |
81 | |
82 | bool mousePressEvent(QMouseEvent *event); |
83 | bool mouseDoubleClickEvent(QMouseEvent *event); |
84 | bool mouseMoveEvent(QMouseEvent *event); |
85 | bool mouseReleaseEvent(QMouseEvent *event); |
86 | void setWindowState(bool floating, bool unplug = false, const QRect &rect = QRect()); |
87 | void nonClientAreaMouseEvent(QMouseEvent *event); |
88 | void initDrag(const QPoint &pos, bool nca); |
89 | void startDrag(bool group = true); |
90 | void endDrag(bool abort = false); |
91 | void moveEvent(QMoveEvent *event); |
92 | void recalculatePressPos(QResizeEvent *event); |
93 | |
94 | void unplug(const QRect &rect); |
95 | void plug(const QRect &rect); |
96 | void setResizerActive(bool active); |
97 | |
98 | bool isAnimating() const; |
99 | |
100 | private: |
101 | QWidgetResizeHandler *resizer = nullptr; |
102 | }; |
103 | |
104 | class Q_WIDGETS_EXPORT QDockWidgetLayout : public QLayout |
105 | { |
106 | Q_OBJECT |
107 | public: |
108 | QDockWidgetLayout(QWidget *parent = nullptr); |
109 | ~QDockWidgetLayout(); |
110 | void addItem(QLayoutItem *item) override; |
111 | QLayoutItem *itemAt(int index) const override; |
112 | QLayoutItem *takeAt(int index) override; |
113 | int count() const override; |
114 | |
115 | QSize maximumSize() const override; |
116 | QSize minimumSize() const override; |
117 | QSize sizeHint() const override; |
118 | |
119 | QSize sizeFromContent(const QSize &content, bool floating) const; |
120 | |
121 | void setGeometry(const QRect &r) override; |
122 | |
123 | enum Role { Content, CloseButton, FloatButton, TitleBar, RoleCount }; |
124 | QWidget *widgetForRole(Role r) const; |
125 | void setWidgetForRole(Role r, QWidget *w); |
126 | QLayoutItem *itemForRole(Role r) const; |
127 | |
128 | QRect titleArea() const { return _titleArea; } |
129 | |
130 | int minimumTitleWidth() const; |
131 | int titleHeight() const; |
132 | void updateMaxSize(); |
133 | static bool wmSupportsNativeWindowDeco(); |
134 | bool nativeWindowDeco() const; |
135 | bool nativeWindowDeco(bool floating) const; |
136 | |
137 | void setVerticalTitleBar(bool b); |
138 | |
139 | bool verticalTitleBar; |
140 | |
141 | private: |
142 | QList<QLayoutItem *> item_list; |
143 | QRect _titleArea; |
144 | }; |
145 | |
146 | /* The size hints of a QDockWidget will depend on whether it is docked or not. |
147 | This layout item always returns the size hints as if the dock widget was docked. */ |
148 | |
149 | class QDockWidgetItem : public QWidgetItem |
150 | { |
151 | public: |
152 | QDockWidgetItem(QDockWidget *dockWidget); |
153 | QSize minimumSize() const override; |
154 | QSize maximumSize() const override; |
155 | QSize sizeHint() const override; |
156 | |
157 | private: |
158 | inline QLayoutItem *dockWidgetChildItem() const; |
159 | inline QDockWidgetLayout *dockWidgetLayout() const; |
160 | }; |
161 | |
162 | inline QLayoutItem *QDockWidgetItem::dockWidgetChildItem() const |
163 | { |
164 | if (QDockWidgetLayout *layout = dockWidgetLayout()) |
165 | return layout->itemForRole(r: QDockWidgetLayout::Content); |
166 | return nullptr; |
167 | } |
168 | |
169 | inline QDockWidgetLayout *QDockWidgetItem::dockWidgetLayout() const |
170 | { |
171 | QWidget *w = widget(); |
172 | if (w != nullptr) |
173 | return qobject_cast<QDockWidgetLayout*>(object: w->layout()); |
174 | return nullptr; |
175 | } |
176 | |
177 | QT_END_NAMESPACE |
178 | |
179 | #endif // QDYNAMICDOCKWIDGET_P_H |
180 | |