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/private/qwidgetanimator_p.h>
21#include "QtWidgets/qlayout.h"
22#include "QtCore/qlist.h"
23#include "QtCore/qrect.h"
24
26
27QT_BEGIN_NAMESPACE
28
29class QLayoutItem;
30class QWidget;
31class QLayoutItem;
32class QDockAreaLayoutInfo;
33class QPlaceHolderItem;
34class QDockWidget;
35class QMainWindow;
36class QWidgetAnimator;
37class QMainWindowLayout;
38struct QLayoutStruct;
39class QTabBar;
40
41// The classes in this file represent the tree structure that represents all the docks
42// Also see the wiki internal documentation
43// At the root of the tree is: QDockAreaLayout, which handles all 4 sides, so there is only one.
44// For each side it has one QDockAreaLayoutInfo child. (See QDockAreaLayout::docks.)
45// The QDockAreaLayoutInfo have QDockAreaLayoutItems as children (See QDockAreaLayoutInfo::item_list),
46// which then has one QDockAreaLayoutInfo as a child. (QDockAreaLayoutItem::subInfo) or
47// a widgetItem if this is a node of the tree (QDockAreaLayoutItem::widgetItem)
48//
49// A path identifies uniquely one object in this tree, the first number being the side and all the following
50// indexes into the QDockAreaLayoutInfo::item_list.
51
52struct Q_AUTOTEST_EXPORT QDockAreaLayoutItem
53{
54 enum ItemFlags { NoFlags = 0, GapItem = 1, KeepSize = 2 };
55
56 explicit QDockAreaLayoutItem(QLayoutItem *_widgetItem = nullptr);
57 explicit QDockAreaLayoutItem(QDockAreaLayoutInfo *_subinfo);
58 explicit QDockAreaLayoutItem(QPlaceHolderItem *_placeHolderItem);
59 QDockAreaLayoutItem(const QDockAreaLayoutItem &other);
60 ~QDockAreaLayoutItem();
61
62 QDockAreaLayoutItem &operator = (const QDockAreaLayoutItem &other);
63
64 bool skip() const;
65 QSize minimumSize() const;
66 QSize maximumSize() const;
67 QSize sizeHint() const;
68 bool expansive(Qt::Orientation o) const;
69 bool hasFixedSize(Qt::Orientation o) const;
70
71 QLayoutItem *widgetItem;
72 QDockAreaLayoutInfo *subinfo;
73 QPlaceHolderItem *placeHolderItem;
74 int pos;
75 int size;
76 uint flags;
77#ifndef QT_NO_DEBUG_STREAM
78 friend Q_AUTOTEST_EXPORT QDebug operator<<(QDebug dbg, const QDockAreaLayoutItem &item);
79 friend Q_AUTOTEST_EXPORT QDebug operator<<(QDebug dbg, const QDockAreaLayoutItem *item);
80#endif
81};
82
83class Q_AUTOTEST_EXPORT QPlaceHolderItem
84{
85public:
86 QPlaceHolderItem() : hidden(false), window(false) {}
87 explicit QPlaceHolderItem(QWidget *w);
88
89 QString objectName;
90 bool hidden, window;
91 QRect topLevelRect;
92};
93
94class Q_AUTOTEST_EXPORT QDockAreaLayoutInfo
95{
96public:
97 QDockAreaLayoutInfo();
98 QDockAreaLayoutInfo(const int *_sep, QInternal::DockPosition _dockPos, Qt::Orientation _o,
99 int tbhape, QMainWindow *window);
100
101 QSize minimumSize() const;
102 QSize maximumSize() const;
103 QSize sizeHint() const;
104 QSize size() const;
105
106 bool insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem);
107 QLayoutItem *plug(const QList<int> &path);
108 QLayoutItem *unplug(const QList<int> &path);
109 enum TabMode { NoTabs, AllowTabs, ForceTabs };
110 QList<int> gapIndex(const QPoint &pos, bool nestingEnabled,
111 TabMode tabMode) const;
112 void remove(const QList<int> &path);
113 void remove(QWidget *widget);
114 void unnest(int index);
115 void split(int index, Qt::Orientation orientation, QLayoutItem *dockWidgetItem);
116#if QT_CONFIG(tabbar)
117 void tab(int index, QLayoutItem *dockWidgetItem);
118#endif
119 QDockAreaLayoutItem &item(const QList<int> &path);
120 QDockAreaLayoutInfo *info(const QList<int> &path);
121 QDockAreaLayoutInfo *info(QWidget *widget);
122
123 void saveState(QDataStream &stream) const;
124 bool restoreState(QDataStream &stream, QList<QDockWidget*> &widgets, QInternal::CallMode);
125
126 void fitItems();
127 bool expansive(Qt::Orientation o) const;
128 int changeSize(int index, int size, bool below);
129 QRect itemRect(int index, bool isGap = false) const;
130 QRect itemRect(const QList<int> &path) const;
131 QRect separatorRect(int index) const;
132 QRect separatorRect(const QList<int> &path) const;
133
134 void clear();
135 bool isEmpty() const;
136 bool hasGapItem(const QList<int> &path) const;
137 bool onlyHasPlaceholders() const;
138 bool hasFixedSize() const;
139 QList<int> findSeparator(const QPoint &pos) const;
140 int next(int idx) const;
141 int prev(int idx) const;
142
143 QList<int> indexOf(const QWidget *widget) const;
144 QList<int> indexOfPlaceHolder(const QString &objectName) const;
145 std::unique_ptr<QLayoutItem> takeWidgetItem(QWidget *widget);
146
147 QDockWidget *apply(QWidgetAnimator::AnimationRule rule);
148
149 void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip,
150 const QPoint &mouse) const;
151 QRegion separatorRegion() const;
152 int separatorMove(int index, int delta);
153 int separatorMove(const QList<int> &separator, const QPoint &origin, const QPoint &dest);
154
155 QLayoutItem *itemAt(int *x, int index) const;
156 QLayoutItem *takeAt(int *x, int index);
157 void add(QWidget *widget);
158 void deleteAllLayoutItems();
159
160 QMainWindowLayout *mainWindowLayout() const;
161
162 const int *sep;
163 mutable QList<QWidget *> separatorWidgets;
164 QInternal::DockPosition dockPos;
165 Qt::Orientation o;
166 QRect rect;
167 QMainWindow *mainWindow;
168 QList<QDockAreaLayoutItem> item_list;
169#if QT_CONFIG(tabbar)
170 void updateSeparatorWidgets() const;
171 QSet<QWidget*> usedSeparatorWidgets() const;
172
173 quintptr currentTabId() const;
174 void setCurrentTab(QWidget *widget);
175 void setCurrentTabId(quintptr id);
176 QRect tabContentRect() const;
177 bool tabbed;
178 QTabBar *tabBar;
179 int tabBarShape;
180
181 void reparentWidgets(QWidget *p);
182 bool updateTabBar() const;
183 void setTabBarShape(int shape);
184 QSize tabBarMinimumSize() const;
185 QSize tabBarSizeHint() const;
186
187 QSet<QTabBar*> usedTabBars() const;
188
189 int tabIndexToListIndex(int) const;
190 void moveTab(int from, int to);
191#endif // QT_CONFIG(tabbar)
192};
193
194class Q_AUTOTEST_EXPORT QDockAreaLayout
195{
196public:
197 enum { EmptyDropAreaSize = 80 }; // when a dock area is empty, how "wide" is it?
198
199 Qt::DockWidgetArea corners[4]; // use a Qt::Corner for indexing
200 QRect rect;
201 QLayoutItem *centralWidgetItem;
202 QMainWindow *mainWindow;
203 QRect centralWidgetRect;
204 QDockAreaLayout(QMainWindow *win);
205 QDockAreaLayoutInfo docks[4];
206 int sep; // margin between a dock widget and its frame
207 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)
208 mutable QList<QWidget *> separatorWidgets;
209
210 bool isValid() const;
211
212 static QRect constrainedRect(QRect rect, QWidget *widget);
213 void saveState(QDataStream &stream) const;
214 bool restoreState(QDataStream &stream, const QList<QDockWidget*> &_dockWidgets, QInternal::CallMode callMode);
215
216 QList<int> indexOfPlaceHolder(const QString &objectName) const;
217 QList<int> indexOf(const QWidget *dockWidget) const;
218 QList<int> gapIndex(const QPoint &pos, bool disallowTabs) const;
219 QList<int> findSeparator(const QPoint &pos) const;
220
221 QDockAreaLayoutItem &item(const QList<int> &path);
222 QDockAreaLayoutInfo *info(const QList<int> &path);
223 const QDockAreaLayoutInfo *info(const QList<int> &path) const;
224 QDockAreaLayoutInfo *info(QWidget *widget);
225 QRect itemRect(const QList<int> &path) const;
226 QRect separatorRect(int index) const;
227 QRect separatorRect(const QList<int> &path) const;
228
229 bool insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem);
230 QLayoutItem *plug(const QList<int> &path);
231 QLayoutItem *unplug(const QList<int> &path);
232 void remove(const QList<int> &path);
233 void removePlaceHolder(const QString &name);
234
235 void fitLayout();
236
237 void clear();
238
239 QSize sizeHint() const;
240 QSize minimumSize() const;
241 QSize minimumStableSize() const;
242 template<typename SizePMF, typename CenterPMF>
243 QSize size_helper(SizePMF sizeFn, CenterPMF centerFn) const;
244
245 void addDockWidget(QInternal::DockPosition pos, QDockWidget *dockWidget, Qt::Orientation orientation);
246 bool restoreDockWidget(QDockWidget *dockWidget);
247 void splitDockWidget(QDockWidget *after, QDockWidget *dockWidget,
248 Qt::Orientation orientation);
249#if QT_CONFIG(tabbar)
250 void tabifyDockWidget(QDockWidget *first, QDockWidget *second);
251#endif
252 void resizeDocks(const QList<QDockWidget *> &docks, const QList<int> &sizes, Qt::Orientation o);
253
254 void apply(QWidgetAnimator::AnimationRule rule);
255
256 void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip,
257 const QPoint &mouse) const;
258 QRegion separatorRegion() const;
259 int separatorMove(const QList<int> &separator, const QPoint &origin, const QPoint &dest);
260#if QT_CONFIG(tabbar)
261 void updateSeparatorWidgets() const;
262#endif // QT_CONFIG(tabbar)
263
264 QLayoutItem *itemAt(int *x, int index) const;
265 QLayoutItem *takeAt(int *x, int index);
266 void deleteAllLayoutItems();
267
268 void getGrid(QList<QLayoutStruct> *ver_struct_list, QList<QLayoutStruct> *hor_struct_list);
269 void setGrid(QList<QLayoutStruct> *ver_struct_list, QList<QLayoutStruct> *hor_struct_list);
270
271 QRect gapRect(const QList<int> &path) const;
272 QRect gapRect(QInternal::DockPosition dockPos) const;
273
274 void keepSize(QDockWidget *w);
275#if QT_CONFIG(tabbar)
276 QSet<QTabBar*> usedTabBars() const;
277 QSet<QWidget*> usedSeparatorWidgets() const;
278#endif // QT_CONFIG(tabbar)
279 void styleChangedEvent();
280};
281
282QT_END_NAMESPACE
283
284#endif // QDOCKAREALAYOUT_P_H
friend class QWidget
Definition qpainter.h:432
Combined button and popup list for selecting options.
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)
Q_DECLARE_FLAGS(StateFlags, StateFlag)
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)
QT_REQUIRE_CONFIG(dockwidget)