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