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 QTOOLBARAREALAYOUT_P_H
41#define QTOOLBARAREALAYOUT_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 "qmenu_p.h"
56#include <QList>
57#include <QSize>
58#include <QRect>
59
60QT_REQUIRE_CONFIG(toolbar);
61
62QT_BEGIN_NAMESPACE
63
64class QToolBar;
65class QLayoutItem;
66class QMainWindow;
67class QStyleOptionToolBar;
68
69class QToolBarAreaLayoutItem
70{
71public:
72 QToolBarAreaLayoutItem(QLayoutItem *item = nullptr)
73 : widgetItem(item), pos(0), size(-1), preferredSize(-1), gap(false) {}
74
75 bool skip() const;
76 QSize minimumSize() const;
77 QSize sizeHint() const;
78 QSize realSizeHint() const;
79
80 void resize(Qt::Orientation o, int newSize)
81 {
82 newSize = qMax(a: pick(o, size: minimumSize()), b: newSize);
83 int sizeh = pick(o, size: sizeHint());
84 if (newSize == sizeh) {
85 preferredSize = -1;
86 size = sizeh;
87 } else {
88 preferredSize = newSize;
89 }
90 }
91
92 void extendSize(Qt::Orientation o, int extent)
93 {
94 int newSize = qMax(a: pick(o, size: minimumSize()), b: (preferredSize > 0 ? preferredSize : pick(o, size: sizeHint())) + extent);
95 int sizeh = pick(o, size: sizeHint());
96 if (newSize == sizeh) {
97 preferredSize = -1;
98 size = sizeh;
99 } else {
100 preferredSize = newSize;
101 }
102 }
103
104 QLayoutItem *widgetItem;
105 int pos;
106 int size;
107 int preferredSize;
108 bool gap;
109};
110Q_DECLARE_TYPEINFO(QToolBarAreaLayoutItem, Q_PRIMITIVE_TYPE);
111
112class QToolBarAreaLayoutLine
113{
114public:
115 QToolBarAreaLayoutLine() {} // for QVector, don't use
116 QToolBarAreaLayoutLine(Qt::Orientation orientation);
117
118 QSize sizeHint() const;
119 QSize minimumSize() const;
120
121 void fitLayout();
122 bool skip() const;
123
124 QRect rect;
125 Qt::Orientation o;
126
127 QVector<QToolBarAreaLayoutItem> toolBarItems;
128};
129Q_DECLARE_TYPEINFO(QToolBarAreaLayoutLine, Q_MOVABLE_TYPE);
130
131class QToolBarAreaLayoutInfo
132{
133public:
134 QToolBarAreaLayoutInfo(QInternal::DockPosition pos = QInternal::TopDock);
135
136 QSize sizeHint() const;
137 QSize minimumSize() const;
138
139 void fitLayout();
140
141 QLayoutItem *insertToolBar(QToolBar *before, QToolBar *toolBar);
142 void insertItem(QToolBar *before, QLayoutItem *item);
143 void removeToolBar(QToolBar *toolBar);
144 void insertToolBarBreak(QToolBar *before);
145 void removeToolBarBreak(QToolBar *before);
146 void moveToolBar(QToolBar *toolbar, int pos);
147
148 QList<int> gapIndex(const QPoint &pos, int *maxDistance) const;
149 bool insertGap(const QList<int> &path, QLayoutItem *item);
150 void clear();
151 QRect itemRect(const QList<int> &path) const;
152 int distance(const QPoint &pos) const;
153
154 QVector<QToolBarAreaLayoutLine> lines;
155 QRect rect;
156 Qt::Orientation o;
157 QInternal::DockPosition dockPos;
158 bool dirty;
159};
160Q_DECLARE_TYPEINFO(QToolBarAreaLayoutInfo, Q_MOVABLE_TYPE);
161
162class QToolBarAreaLayout
163{
164public:
165 enum { // sentinel values used to validate state data
166 ToolBarStateMarker = 0xfe,
167 ToolBarStateMarkerEx = 0xfc
168 };
169
170 QRect rect;
171 const QMainWindow *mainWindow;
172 QToolBarAreaLayoutInfo docks[4];
173 bool visible;
174
175 QToolBarAreaLayout(const QMainWindow *win);
176
177 QRect fitLayout();
178
179 QSize minimumSize(const QSize &centerMin) const;
180 QRect rectHint(const QRect &r) const;
181 QSize sizeHint(const QSize &center) const;
182 void apply(bool animate);
183
184 QLayoutItem *itemAt(int *x, int index) const;
185 QLayoutItem *takeAt(int *x, int index);
186 void deleteAllLayoutItems();
187
188 QLayoutItem *insertToolBar(QToolBar *before, QToolBar *toolBar);
189 void removeToolBar(QToolBar *toolBar);
190 QLayoutItem *addToolBar(QInternal::DockPosition pos, QToolBar *toolBar);
191 void insertToolBarBreak(QToolBar *before);
192 void removeToolBarBreak(QToolBar *before);
193 void addToolBarBreak(QInternal::DockPosition pos);
194 void moveToolBar(QToolBar *toolbar, int pos);
195
196 void insertItem(QInternal::DockPosition pos, QLayoutItem *item);
197 void insertItem(QToolBar *before, QLayoutItem *item);
198
199 QInternal::DockPosition findToolBar(const QToolBar *toolBar) const;
200 bool toolBarBreak(QToolBar *toolBar) const;
201
202 void getStyleOptionInfo(QStyleOptionToolBar *option, QToolBar *toolBar) const;
203
204 QList<int> indexOf(QWidget *toolBar) const;
205 QList<int> gapIndex(const QPoint &pos) const;
206 QList<int> currentGapIndex() const;
207 bool insertGap(const QList<int> &path, QLayoutItem *item);
208 void remove(const QList<int> &path);
209 void remove(QLayoutItem *item);
210 void clear();
211 QToolBarAreaLayoutItem *item(const QList<int> &path);
212 QRect itemRect(const QList<int> &path) const;
213 QLayoutItem *plug(const QList<int> &path);
214 QLayoutItem *unplug(const QList<int> &path, QToolBarAreaLayout *other);
215
216 void saveState(QDataStream &stream) const;
217 bool restoreState(QDataStream &stream, const QList<QToolBar*> &toolBars, uchar tmarker, bool testing = false);
218 bool isEmpty() const;
219};
220
221QT_END_NAMESPACE
222
223#endif // QTOOLBARAREALAYOUT_P_H
224

source code of qtbase/src/widgets/widgets/qtoolbararealayout_p.h