Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdockarealayout_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QDOCKAREALAYOUT_P_H
6#define QDOCKAREALAYOUT_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtWidgets/private/qtwidgetsglobal_p.h>
20#include "QtWidgets/qlayout.h"
21#include "QtCore/qlist.h"
22#include "QtCore/qrect.h"
23
25
26QT_BEGIN_NAMESPACE
27
28class QLayoutItem;
29class QWidget;
30class QLayoutItem;
31class QDockAreaLayoutInfo;
32class QPlaceHolderItem;
33class QDockWidget;
34class QMainWindow;
35class QWidgetAnimator;
36class QMainWindowLayout;
37struct QLayoutStruct;
38class QTabBar;
39
40// The classes in this file represent the tree structure that represents all the docks
41// Also see the wiki internal documentation
42// At the root of the tree is: QDockAreaLayout, which handles all 4 sides, so there is only one.
43// For each side it has one QDockAreaLayoutInfo child. (See QDockAreaLayout::docks.)
44// The QDockAreaLayoutInfo have QDockAreaLayoutItems as children (See QDockAreaLayoutInfo::item_list),
45// which then has one QDockAreaLayoutInfo as a child. (QDockAreaLayoutItem::subInfo) or
46// a widgetItem if this is a node of the tree (QDockAreaLayoutItem::widgetItem)
47//
48// A path indetifies uniquely one object in this tree, the first number being the side and all the following
49// indexes into the QDockAreaLayoutInfo::item_list.
50
51struct Q_AUTOTEST_EXPORT QDockAreaLayoutItem
52{
53 enum ItemFlags { NoFlags = 0, GapItem = 1, KeepSize = 2 };
54
55 explicit QDockAreaLayoutItem(QLayoutItem *_widgetItem = nullptr);
56 explicit QDockAreaLayoutItem(QDockAreaLayoutInfo *_subinfo);
57 explicit QDockAreaLayoutItem(QPlaceHolderItem *_placeHolderItem);
58 QDockAreaLayoutItem(const QDockAreaLayoutItem &other);
59 ~QDockAreaLayoutItem();
60
61 QDockAreaLayoutItem &operator = (const QDockAreaLayoutItem &other);
62
63 bool skip() const;
64 QSize minimumSize() const;
65 QSize maximumSize() const;
66 QSize sizeHint() const;
67 bool expansive(Qt::Orientation o) const;
68 bool hasFixedSize(Qt::Orientation o) const;
69
70 QLayoutItem *widgetItem;
71 QDockAreaLayoutInfo *subinfo;
72 QPlaceHolderItem *placeHolderItem;
73 int pos;
74 int size;
75 uint flags;
76#ifndef QT_NO_DEBUG_STREAM
77 friend Q_AUTOTEST_EXPORT QDebug operator<<(QDebug dbg, const QDockAreaLayoutItem &item);
78 friend Q_AUTOTEST_EXPORT QDebug operator<<(QDebug dbg, const QDockAreaLayoutItem *item);
79#endif
80};
81
82class Q_AUTOTEST_EXPORT QPlaceHolderItem
83{
84public:
85 QPlaceHolderItem() : hidden(false), window(false) {}
86 explicit QPlaceHolderItem(QWidget *w);
87
88 QString objectName;
89 bool hidden, window;
90 QRect topLevelRect;
91};
92
93class Q_AUTOTEST_EXPORT QDockAreaLayoutInfo
94{
95public:
96 QDockAreaLayoutInfo();
97 QDockAreaLayoutInfo(const int *_sep, QInternal::DockPosition _dockPos, Qt::Orientation _o,
98 int tbhape, QMainWindow *window);
99
100 QSize minimumSize() const;
101 QSize maximumSize() const;
102 QSize sizeHint() const;
103 QSize size() const;
104
105 bool insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem);
106 QLayoutItem *plug(const QList<int> &path);
107 QLayoutItem *unplug(const QList<int> &path);
108 enum TabMode { NoTabs, AllowTabs, ForceTabs };
109 QList<int> gapIndex(const QPoint &pos, bool nestingEnabled,
110 TabMode tabMode) const;
111 void remove(const QList<int> &path);
112 void remove(QWidget *widget);
113 void unnest(int index);
114 void split(int index, Qt::Orientation orientation, QLayoutItem *dockWidgetItem);
115#if QT_CONFIG(tabbar)
116 void tab(int index, QLayoutItem *dockWidgetItem);
117#endif
118 QDockAreaLayoutItem &item(const QList<int> &path);
119 QDockAreaLayoutInfo *info(const QList<int> &path);
120 QDockAreaLayoutInfo *info(QWidget *widget);
121
122 enum { // sentinel values used to validate state data
123 SequenceMarker = 0xfc,
124 TabMarker = 0xfa,
125 WidgetMarker = 0xfb
126 };
127 void saveState(QDataStream &stream) const;
128 bool restoreState(QDataStream &stream, QList<QDockWidget*> &widgets, bool testing);
129
130 void fitItems();
131 bool expansive(Qt::Orientation o) const;
132 int changeSize(int index, int size, bool below);
133 QRect itemRect(int index, bool isGap = false) const;
134 QRect itemRect(const QList<int> &path) const;
135 QRect separatorRect(int index) const;
136 QRect separatorRect(const QList<int> &path) const;
137
138 void clear();
139 bool isEmpty() const;
140 bool hasGapItem(const QList<int> &path) const;
141 bool onlyHasPlaceholders() const;
142 bool hasFixedSize() const;
143 QList<int> findSeparator(const QPoint &pos) const;
144 int next(int idx) const;
145 int prev(int idx) const;
146
147 QList<int> indexOf(const QWidget *widget) const;
148 QList<int> indexOfPlaceHolder(const QString &objectName) const;
149 std::unique_ptr<QLayoutItem> takeWidgetItem(QWidget *widget);
150
151 QDockWidget *apply(bool animate);
152
153 void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip,
154 const QPoint &mouse) const;
155 QRegion separatorRegion() const;
156 int separatorMove(int index, int delta);
157 int separatorMove(const QList<int> &separator, const QPoint &origin, const QPoint &dest);
158
159 QLayoutItem *itemAt(int *x, int index) const;
160 QLayoutItem *takeAt(int *x, int index);
161 void add(QWidget *widget);
162 void deleteAllLayoutItems();
163
164 QMainWindowLayout *mainWindowLayout() const;
165
166 const int *sep;
167 mutable QList<QWidget *> separatorWidgets;
168 QInternal::DockPosition dockPos;
169 Qt::Orientation o;
170 QRect rect;
171 QMainWindow *mainWindow;
172 QList<QDockAreaLayoutItem> item_list;
173#if QT_CONFIG(tabbar)
174 void updateSeparatorWidgets() const;
175 QSet<QWidget*> usedSeparatorWidgets() const;
176
177 quintptr currentTabId() const;
178 void setCurrentTab(QWidget *widget);
179 void setCurrentTabId(quintptr id);
180 QRect tabContentRect() const;
181 bool tabbed;
182 QTabBar *tabBar;
183 int tabBarShape;
184
185 void reparentWidgets(QWidget *p);
186 bool updateTabBar() const;
187 void setTabBarShape(int shape);
188 QSize tabBarMinimumSize() const;
189 QSize tabBarSizeHint() const;
190
191 QSet<QTabBar*> usedTabBars() const;
192
193 int tabIndexToListIndex(int) const;
194 void moveTab(int from, int to);
195#endif // QT_CONFIG(tabbar)
196};
197
198class Q_AUTOTEST_EXPORT QDockAreaLayout
199{
200public:
201 enum { EmptyDropAreaSize = 80 }; // when a dock area is empty, how "wide" is it?
202
203 Qt::DockWidgetArea corners[4]; // use a Qt::Corner for indexing
204 QRect rect;
205 QLayoutItem *centralWidgetItem;
206 QMainWindow *mainWindow;
207 QRect centralWidgetRect;
208 QDockAreaLayout(QMainWindow *win);
209 QDockAreaLayoutInfo docks[4];
210 int sep; // margin between a dock widget and its frame
211 bool fallbackToSizeHints; //determines if we should use the sizehint for the dock areas (true until the layout is restored or the separator is moved by user)
212 mutable QList<QWidget *> separatorWidgets;
213
214 bool isValid() const;
215
216 enum { DockWidgetStateMarker = 0xfd, FloatingDockWidgetTabMarker = 0xf9 };
217 static QRect constrainedRect(QRect rect, QWidget *widget);
218 void saveState(QDataStream &stream) const;
219 bool restoreState(QDataStream &stream, const QList<QDockWidget*> &widgets, bool testing = false);
220
221 QList<int> indexOfPlaceHolder(const QString &objectName) const;
222 QList<int> indexOf(const QWidget *dockWidget) const;
223 QList<int> gapIndex(const QPoint &pos, bool disallowTabs) const;
224 QList<int> findSeparator(const QPoint &pos) const;
225
226 QDockAreaLayoutItem &item(const QList<int> &path);
227 QDockAreaLayoutInfo *info(const QList<int> &path);
228 const QDockAreaLayoutInfo *info(const QList<int> &path) const;
229 QDockAreaLayoutInfo *info(QWidget *widget);
230 QRect itemRect(const QList<int> &path) const;
231 QRect separatorRect(int index) const;
232 QRect separatorRect(const QList<int> &path) const;
233
234 bool insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem);
235 QLayoutItem *plug(const QList<int> &path);
236 QLayoutItem *unplug(const QList<int> &path);
237 void remove(const QList<int> &path);
238 void removePlaceHolder(const QString &name);
239
240 void fitLayout();
241
242 void clear();
243
244 QSize sizeHint() const;
245 QSize minimumSize() const;
246 QSize minimumStableSize() const;
247 template<typename SizePMF, typename CenterPMF>
248 QSize size_helper(SizePMF sizeFn, CenterPMF centerFn) const;
249
250 void addDockWidget(QInternal::DockPosition pos, QDockWidget *dockWidget, Qt::Orientation orientation);
251 bool restoreDockWidget(QDockWidget *dockWidget);
252 void splitDockWidget(QDockWidget *after, QDockWidget *dockWidget,
253 Qt::Orientation orientation);
254#if QT_CONFIG(tabbar)
255 void tabifyDockWidget(QDockWidget *first, QDockWidget *second);
256#endif
257 void resizeDocks(const QList<QDockWidget *> &docks, const QList<int> &sizes, Qt::Orientation o);
258
259 void apply(bool animate);
260
261 void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip,
262 const QPoint &mouse) const;
263 QRegion separatorRegion() const;
264 int separatorMove(const QList<int> &separator, const QPoint &origin, const QPoint &dest);
265#if QT_CONFIG(tabbar)
266 void updateSeparatorWidgets() const;
267#endif // QT_CONFIG(tabbar)
268
269 QLayoutItem *itemAt(int *x, int index) const;
270 QLayoutItem *takeAt(int *x, int index);
271 void deleteAllLayoutItems();
272
273 void getGrid(QList<QLayoutStruct> *ver_struct_list, QList<QLayoutStruct> *hor_struct_list);
274 void setGrid(QList<QLayoutStruct> *ver_struct_list, QList<QLayoutStruct> *hor_struct_list);
275
276 QRect gapRect(const QList<int> &path) const;
277 QRect gapRect(QInternal::DockPosition dockPos) const;
278
279 void keepSize(QDockWidget *w);
280#if QT_CONFIG(tabbar)
281 QSet<QTabBar*> usedTabBars() const;
282 QSet<QWidget*> usedSeparatorWidgets() const;
283#endif // QT_CONFIG(tabbar)
284 void styleChangedEvent();
285};
286
287QT_END_NAMESPACE
288
289#endif // QDOCKAREALAYOUT_P_H
friend class QWidget
Definition qpainter.h:431
static int grow(QLayoutStruct &ls, int delta)
static QRect dockedGeometry(QWidget *widget)
static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos)
static int realMinSize(const QDockAreaLayoutInfo &info)
static int qMax(int i1, int i2, int i3)
static int shrink(QLayoutStruct &ls, int delta)
static const int zero
static int separatorMoveHelper(QList< QLayoutStruct > &list, int index, int delta, int sep)
static QInternal::DockPosition dockPosHelper(const QRect &rect, const QPoint &_pos, Qt::Orientation o, bool nestingEnabled, QDockAreaLayoutInfo::TabMode tabMode)
static void paintSep(QPainter *p, QWidget *w, const QRect &r, Qt::Orientation o, bool mouse_over)
static int realMaxSize(const QDockAreaLayoutInfo &info)
QMainWindowLayout * qt_mainwindow_layout(const QMainWindow *window)
@ StateFlagFloating
@ StateFlagVisible
QT_REQUIRE_CONFIG(dockwidget)