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 QTOOLBARAREALAYOUT_P_H |
5 | #define QTOOLBARAREALAYOUT_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 "qmenu_p.h" |
20 | #include <QList> |
21 | #include <QSize> |
22 | #include <QRect> |
23 | |
24 | QT_REQUIRE_CONFIG(toolbar); |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | class QToolBar; |
29 | class QLayoutItem; |
30 | class QMainWindow; |
31 | class QStyleOptionToolBar; |
32 | |
33 | class QToolBarAreaLayoutItem |
34 | { |
35 | public: |
36 | QToolBarAreaLayoutItem(QLayoutItem *item = nullptr) |
37 | : widgetItem(item), pos(0), size(-1), preferredSize(-1), gap(false) {} |
38 | |
39 | bool skip() const; |
40 | QSize minimumSize() const; |
41 | QSize sizeHint() const; |
42 | QSize realSizeHint() const; |
43 | |
44 | void resize(Qt::Orientation o, int newSize) |
45 | { |
46 | newSize = qMax(a: pick(o, size: minimumSize()), b: newSize); |
47 | int sizeh = pick(o, size: sizeHint()); |
48 | if (newSize == sizeh) { |
49 | preferredSize = -1; |
50 | size = sizeh; |
51 | } else { |
52 | preferredSize = newSize; |
53 | } |
54 | } |
55 | |
56 | void extendSize(Qt::Orientation o, int extent) |
57 | { |
58 | int newSize = qMax(a: pick(o, size: minimumSize()), b: (preferredSize > 0 ? preferredSize : pick(o, size: sizeHint())) + extent); |
59 | int sizeh = pick(o, size: sizeHint()); |
60 | if (newSize == sizeh) { |
61 | preferredSize = -1; |
62 | size = sizeh; |
63 | } else { |
64 | preferredSize = newSize; |
65 | } |
66 | } |
67 | |
68 | QLayoutItem *widgetItem; |
69 | int pos; |
70 | int size; |
71 | int preferredSize; |
72 | bool gap; |
73 | }; |
74 | Q_DECLARE_TYPEINFO(QToolBarAreaLayoutItem, Q_PRIMITIVE_TYPE); |
75 | |
76 | class QToolBarAreaLayoutLine |
77 | { |
78 | public: |
79 | QToolBarAreaLayoutLine() { } // for QList, don't use |
80 | QToolBarAreaLayoutLine(Qt::Orientation orientation); |
81 | |
82 | QSize sizeHint() const; |
83 | QSize minimumSize() const; |
84 | |
85 | void fitLayout(); |
86 | bool skip() const; |
87 | |
88 | QRect rect; |
89 | Qt::Orientation o; |
90 | |
91 | QList<QToolBarAreaLayoutItem> toolBarItems; |
92 | }; |
93 | Q_DECLARE_TYPEINFO(QToolBarAreaLayoutLine, Q_RELOCATABLE_TYPE); |
94 | |
95 | class QToolBarAreaLayoutInfo |
96 | { |
97 | public: |
98 | QToolBarAreaLayoutInfo(QInternal::DockPosition pos = QInternal::TopDock); |
99 | |
100 | QSize sizeHint() const; |
101 | QSize minimumSize() const; |
102 | |
103 | void fitLayout(); |
104 | |
105 | QLayoutItem *insertToolBar(QToolBar *before, QToolBar *toolBar); |
106 | void insertItem(QToolBar *before, QLayoutItem *item); |
107 | void removeToolBar(QToolBar *toolBar); |
108 | void insertToolBarBreak(QToolBar *before); |
109 | void removeToolBarBreak(QToolBar *before); |
110 | void moveToolBar(QToolBar *toolbar, int pos); |
111 | |
112 | QList<int> gapIndex(const QPoint &pos, int *maxDistance) const; |
113 | bool insertGap(const QList<int> &path, QLayoutItem *item); |
114 | void clear(); |
115 | QRect itemRect(const QList<int> &path) const; |
116 | int distance(const QPoint &pos) const; |
117 | |
118 | QList<QToolBarAreaLayoutLine> lines; |
119 | QRect rect; |
120 | Qt::Orientation o; |
121 | QInternal::DockPosition dockPos; |
122 | bool dirty; |
123 | }; |
124 | Q_DECLARE_TYPEINFO(QToolBarAreaLayoutInfo, Q_RELOCATABLE_TYPE); |
125 | |
126 | class QToolBarAreaLayout |
127 | { |
128 | public: |
129 | enum { // sentinel values used to validate state data |
130 | ToolBarStateMarker = 0xfe, |
131 | ToolBarStateMarkerEx = 0xfc |
132 | }; |
133 | |
134 | QRect rect; |
135 | const QMainWindow *mainWindow; |
136 | QToolBarAreaLayoutInfo docks[4]; |
137 | bool visible; |
138 | |
139 | QToolBarAreaLayout(const QMainWindow *win); |
140 | |
141 | QRect fitLayout(); |
142 | |
143 | QSize minimumSize(const QSize ¢erMin) const; |
144 | QRect rectHint(const QRect &r) const; |
145 | QSize sizeHint(const QSize ¢er) const; |
146 | void apply(bool animate); |
147 | |
148 | QLayoutItem *itemAt(int *x, int index) const; |
149 | QLayoutItem *takeAt(int *x, int index); |
150 | void deleteAllLayoutItems(); |
151 | |
152 | QLayoutItem *insertToolBar(QToolBar *before, QToolBar *toolBar); |
153 | void removeToolBar(QToolBar *toolBar); |
154 | QLayoutItem *addToolBar(QInternal::DockPosition pos, QToolBar *toolBar); |
155 | void insertToolBarBreak(QToolBar *before); |
156 | void removeToolBarBreak(QToolBar *before); |
157 | void addToolBarBreak(QInternal::DockPosition pos); |
158 | void moveToolBar(QToolBar *toolbar, int pos); |
159 | |
160 | void insertItem(QInternal::DockPosition pos, QLayoutItem *item); |
161 | void insertItem(QToolBar *before, QLayoutItem *item); |
162 | |
163 | QInternal::DockPosition findToolBar(const QToolBar *toolBar) const; |
164 | bool toolBarBreak(QToolBar *toolBar) const; |
165 | |
166 | void getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const; |
167 | |
168 | QList<int> indexOf(QWidget *toolBar) const; |
169 | QList<int> gapIndex(const QPoint &pos) const; |
170 | QList<int> currentGapIndex() const; |
171 | bool insertGap(const QList<int> &path, QLayoutItem *item); |
172 | void remove(const QList<int> &path); |
173 | void remove(QLayoutItem *item); |
174 | void clear(); |
175 | QToolBarAreaLayoutItem *item(const QList<int> &path); |
176 | QRect itemRect(const QList<int> &path) const; |
177 | QLayoutItem *plug(const QList<int> &path); |
178 | QLayoutItem *unplug(const QList<int> &path, QToolBarAreaLayout *other); |
179 | |
180 | void saveState(QDataStream &stream) const; |
181 | bool restoreState(QDataStream &stream, const QList<QToolBar*> &toolBars, uchar tmarker, bool testing = false); |
182 | bool isEmpty() const; |
183 | }; |
184 | |
185 | QT_END_NAMESPACE |
186 | |
187 | #endif // QTOOLBARAREALAYOUT_P_H |
188 | |