Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qlayout.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
5 | ** | - | ||||||||||||||||||||||||
6 | ** This file is part of the QtWidgets module of the Qt Toolkit. | - | ||||||||||||||||||||||||
7 | ** | - | ||||||||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
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 http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
15 | ** information use the contact form at http://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 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
29 | ** | - | ||||||||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
31 | ** | - | ||||||||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
33 | - | |||||||||||||||||||||||||
34 | #include "qlayout.h" | - | ||||||||||||||||||||||||
35 | - | |||||||||||||||||||||||||
36 | #include "qapplication.h" | - | ||||||||||||||||||||||||
37 | #include "qlayoutengine_p.h" | - | ||||||||||||||||||||||||
38 | #include "qmenubar.h" | - | ||||||||||||||||||||||||
39 | #include "qtoolbar.h" | - | ||||||||||||||||||||||||
40 | #include "qsizegrip.h" | - | ||||||||||||||||||||||||
41 | #include "qevent.h" | - | ||||||||||||||||||||||||
42 | #include "qstyle.h" | - | ||||||||||||||||||||||||
43 | #include "qvariant.h" | - | ||||||||||||||||||||||||
44 | #include "qwidget_p.h" | - | ||||||||||||||||||||||||
45 | #include "qlayout_p.h" | - | ||||||||||||||||||||||||
46 | #include "qformlayout.h" | - | ||||||||||||||||||||||||
47 | - | |||||||||||||||||||||||||
48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
49 | - | |||||||||||||||||||||||||
50 | static int menuBarHeightForWidth(QWidget *menubar, int w) | - | ||||||||||||||||||||||||
51 | { | - | ||||||||||||||||||||||||
52 | if (menubar && !menubar->isHidden() && !menubar->isWindow()) {
| 0 | ||||||||||||||||||||||||
53 | int result = menubar->heightForWidth(qMax(w, menubar->minimumWidth())); | - | ||||||||||||||||||||||||
54 | if (result == -1)
| 0 | ||||||||||||||||||||||||
55 | result = menubar->sizeHint().height(); never executed: result = menubar->sizeHint().height(); | 0 | ||||||||||||||||||||||||
56 | const int min = qSmartMinSize(menubar).height(); | - | ||||||||||||||||||||||||
57 | result = qBound(min, result, menubar->maximumSize().height()); | - | ||||||||||||||||||||||||
58 | if (result != -1)
| 0 | ||||||||||||||||||||||||
59 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
60 | } never executed: end of block | 0 | ||||||||||||||||||||||||
61 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
62 | } | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | /*! | - | ||||||||||||||||||||||||
65 | \class QLayout | - | ||||||||||||||||||||||||
66 | \brief The QLayout class is the base class of geometry managers. | - | ||||||||||||||||||||||||
67 | - | |||||||||||||||||||||||||
68 | \ingroup geomanagement | - | ||||||||||||||||||||||||
69 | \inmodule QtWidgets | - | ||||||||||||||||||||||||
70 | - | |||||||||||||||||||||||||
71 | This is an abstract base class inherited by the concrete classes | - | ||||||||||||||||||||||||
72 | QBoxLayout, QGridLayout, QFormLayout, and QStackedLayout. | - | ||||||||||||||||||||||||
73 | - | |||||||||||||||||||||||||
74 | For users of QLayout subclasses or of QMainWindow there is seldom | - | ||||||||||||||||||||||||
75 | any need to use the basic functions provided by QLayout, such as | - | ||||||||||||||||||||||||
76 | setSizeConstraint() or setMenuBar(). See \l{Layout Management} | - | ||||||||||||||||||||||||
77 | for more information. | - | ||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | To make your own layout manager, implement the functions | - | ||||||||||||||||||||||||
80 | addItem(), sizeHint(), setGeometry(), itemAt() and takeAt(). You | - | ||||||||||||||||||||||||
81 | should also implement minimumSize() to ensure your layout isn't | - | ||||||||||||||||||||||||
82 | resized to zero size if there is too little space. To support | - | ||||||||||||||||||||||||
83 | children whose heights depend on their widths, implement | - | ||||||||||||||||||||||||
84 | hasHeightForWidth() and heightForWidth(). See the | - | ||||||||||||||||||||||||
85 | \l{layouts/borderlayout}{Border Layout} and | - | ||||||||||||||||||||||||
86 | \l{layouts/flowlayout}{Flow Layout} examples for | - | ||||||||||||||||||||||||
87 | more information about implementing custom layout managers. | - | ||||||||||||||||||||||||
88 | - | |||||||||||||||||||||||||
89 | Geometry management stops when the layout manager is deleted. | - | ||||||||||||||||||||||||
90 | - | |||||||||||||||||||||||||
91 | \sa QLayoutItem, {Layout Management}, {Basic Layouts Example}, | - | ||||||||||||||||||||||||
92 | {Border Layout Example}, {Flow Layout Example} | - | ||||||||||||||||||||||||
93 | */ | - | ||||||||||||||||||||||||
94 | - | |||||||||||||||||||||||||
95 | - | |||||||||||||||||||||||||
96 | /*! | - | ||||||||||||||||||||||||
97 | Constructs a new top-level QLayout, with parent \a parent. | - | ||||||||||||||||||||||||
98 | \a parent may not be 0. | - | ||||||||||||||||||||||||
99 | - | |||||||||||||||||||||||||
100 | There can be only one top-level layout for a widget. It is | - | ||||||||||||||||||||||||
101 | returned by QWidget::layout(). | - | ||||||||||||||||||||||||
102 | */ | - | ||||||||||||||||||||||||
103 | QLayout::QLayout(QWidget *parent) | - | ||||||||||||||||||||||||
104 | : QObject(*new QLayoutPrivate, parent) | - | ||||||||||||||||||||||||
105 | { | - | ||||||||||||||||||||||||
106 | if (!parent)
| 0 | ||||||||||||||||||||||||
107 | return; never executed: return; | 0 | ||||||||||||||||||||||||
108 | parent->setLayout(this); | - | ||||||||||||||||||||||||
109 | } never executed: end of block | 0 | ||||||||||||||||||||||||
110 | - | |||||||||||||||||||||||||
111 | /*! | - | ||||||||||||||||||||||||
112 | Constructs a new child QLayout. | - | ||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | This layout has to be inserted into another layout before geometry | - | ||||||||||||||||||||||||
115 | management will work. | - | ||||||||||||||||||||||||
116 | */ | - | ||||||||||||||||||||||||
117 | QLayout::QLayout() | - | ||||||||||||||||||||||||
118 | : QObject(*new QLayoutPrivate, 0) | - | ||||||||||||||||||||||||
119 | { | - | ||||||||||||||||||||||||
120 | } never executed: end of block | 0 | ||||||||||||||||||||||||
121 | - | |||||||||||||||||||||||||
122 | - | |||||||||||||||||||||||||
123 | /*! \internal | - | ||||||||||||||||||||||||
124 | */ | - | ||||||||||||||||||||||||
125 | QLayout::QLayout(QLayoutPrivate &dd, QLayout *lay, QWidget *w) | - | ||||||||||||||||||||||||
126 | : QObject(dd, lay ? static_cast<QObject*>(lay) : static_cast<QObject*>(w)) | - | ||||||||||||||||||||||||
127 | { | - | ||||||||||||||||||||||||
128 | Q_D(QLayout); | - | ||||||||||||||||||||||||
129 | if (lay) {
| 0 | ||||||||||||||||||||||||
130 | lay->addItem(this); | - | ||||||||||||||||||||||||
131 | } else if (w) { never executed: end of block
| 0 | ||||||||||||||||||||||||
132 | if (w->layout()) {
| 0 | ||||||||||||||||||||||||
133 | qWarning("QLayout: Attempting to add QLayout \"%s\" to %s \"%s\", which" | - | ||||||||||||||||||||||||
134 | " already has a layout", | - | ||||||||||||||||||||||||
135 | qPrintable(QObject::objectName()), w->metaObject()->className(), | - | ||||||||||||||||||||||||
136 | w->objectName().toLocal8Bit().data()); | - | ||||||||||||||||||||||||
137 | setParent(0); | - | ||||||||||||||||||||||||
138 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
139 | d->topLevel = true; | - | ||||||||||||||||||||||||
140 | w->d_func()->layout = this; | - | ||||||||||||||||||||||||
141 | QT_TRY { | - | ||||||||||||||||||||||||
142 | invalidate(); | - | ||||||||||||||||||||||||
143 | } QT_CATCH(...) { never executed: end of block dead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
144 | w->d_func()->layout = 0; dead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
145 | QT_RETHROW; dead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
146 | } dead code: { w->d_func()->layout = 0; qt_noop(); } | - | ||||||||||||||||||||||||
147 | } | - | ||||||||||||||||||||||||
148 | } | - | ||||||||||||||||||||||||
149 | } never executed: end of block | 0 | ||||||||||||||||||||||||
150 | - | |||||||||||||||||||||||||
151 | QLayoutPrivate::QLayoutPrivate() | - | ||||||||||||||||||||||||
152 | : QObjectPrivate(), insideSpacing(-1), userLeftMargin(-1), userTopMargin(-1), userRightMargin(-1), | - | ||||||||||||||||||||||||
153 | userBottomMargin(-1), topLevel(false), enabled(true), activated(true), autoNewChild(false), | - | ||||||||||||||||||||||||
154 | constraint(QLayout::SetDefaultConstraint), menubar(0) | - | ||||||||||||||||||||||||
155 | { | - | ||||||||||||||||||||||||
156 | } never executed: end of block | 0 | ||||||||||||||||||||||||
157 | - | |||||||||||||||||||||||||
158 | void QLayoutPrivate::getMargin(int *result, int userMargin, QStyle::PixelMetric pm) const | - | ||||||||||||||||||||||||
159 | { | - | ||||||||||||||||||||||||
160 | if (!result)
| 0 | ||||||||||||||||||||||||
161 | return; never executed: return; | 0 | ||||||||||||||||||||||||
162 | - | |||||||||||||||||||||||||
163 | Q_Q(const QLayout); | - | ||||||||||||||||||||||||
164 | if (userMargin >= 0) {
| 0 | ||||||||||||||||||||||||
165 | *result = userMargin; | - | ||||||||||||||||||||||||
166 | } else if (!topLevel) { never executed: end of block
| 0 | ||||||||||||||||||||||||
167 | *result = 0; | - | ||||||||||||||||||||||||
168 | } else if (QWidget *pw = q->parentWidget()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
169 | *result = pw->style()->pixelMetric(pm, 0, pw); | - | ||||||||||||||||||||||||
170 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
171 | *result = 0; | - | ||||||||||||||||||||||||
172 | } never executed: end of block | 0 | ||||||||||||||||||||||||
173 | } | - | ||||||||||||||||||||||||
174 | - | |||||||||||||||||||||||||
175 | // Static item factory functions that allow for hooking things in Designer | - | ||||||||||||||||||||||||
176 | - | |||||||||||||||||||||||||
177 | QLayoutPrivate::QWidgetItemFactoryMethod QLayoutPrivate::widgetItemFactoryMethod = 0; | - | ||||||||||||||||||||||||
178 | QLayoutPrivate::QSpacerItemFactoryMethod QLayoutPrivate::spacerItemFactoryMethod = 0; | - | ||||||||||||||||||||||||
179 | - | |||||||||||||||||||||||||
180 | QWidgetItem *QLayoutPrivate::createWidgetItem(const QLayout *layout, QWidget *widget) | - | ||||||||||||||||||||||||
181 | { | - | ||||||||||||||||||||||||
182 | if (widgetItemFactoryMethod)
| 0 | ||||||||||||||||||||||||
183 | if (QWidgetItem *wi = (*widgetItemFactoryMethod)(layout, widget))
| 0 | ||||||||||||||||||||||||
184 | return wi; never executed: return wi; | 0 | ||||||||||||||||||||||||
185 | return new QWidgetItemV2(widget); never executed: return new QWidgetItemV2(widget); | 0 | ||||||||||||||||||||||||
186 | } | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | QSpacerItem *QLayoutPrivate::createSpacerItem(const QLayout *layout, int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy) | - | ||||||||||||||||||||||||
189 | { | - | ||||||||||||||||||||||||
190 | if (spacerItemFactoryMethod)
| 0 | ||||||||||||||||||||||||
191 | if (QSpacerItem *si = (*spacerItemFactoryMethod)(layout, w, h, hPolicy, vPolicy))
| 0 | ||||||||||||||||||||||||
192 | return si; never executed: return si; | 0 | ||||||||||||||||||||||||
193 | return new QSpacerItem(w, h, hPolicy, vPolicy); never executed: return new QSpacerItem(w, h, hPolicy, vPolicy); | 0 | ||||||||||||||||||||||||
194 | } | - | ||||||||||||||||||||||||
195 | - | |||||||||||||||||||||||||
196 | - | |||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | /*! | - | ||||||||||||||||||||||||
199 | \fn void QLayout::addItem(QLayoutItem *item) | - | ||||||||||||||||||||||||
200 | - | |||||||||||||||||||||||||
201 | Implemented in subclasses to add an \a item. How it is added is | - | ||||||||||||||||||||||||
202 | specific to each subclass. | - | ||||||||||||||||||||||||
203 | - | |||||||||||||||||||||||||
204 | This function is not usually called in application code. To add a widget | - | ||||||||||||||||||||||||
205 | to a layout, use the addWidget() function; to add a child layout, use the | - | ||||||||||||||||||||||||
206 | addLayout() function provided by the relevant QLayout subclass. | - | ||||||||||||||||||||||||
207 | - | |||||||||||||||||||||||||
208 | \b{Note:} The ownership of \a item is transferred to the layout, and it's | - | ||||||||||||||||||||||||
209 | the layout's responsibility to delete it. | - | ||||||||||||||||||||||||
210 | - | |||||||||||||||||||||||||
211 | \sa addWidget(), QBoxLayout::addLayout(), QGridLayout::addLayout() | - | ||||||||||||||||||||||||
212 | */ | - | ||||||||||||||||||||||||
213 | - | |||||||||||||||||||||||||
214 | /*! | - | ||||||||||||||||||||||||
215 | Adds widget \a w to this layout in a manner specific to the | - | ||||||||||||||||||||||||
216 | layout. This function uses addItem(). | - | ||||||||||||||||||||||||
217 | */ | - | ||||||||||||||||||||||||
218 | void QLayout::addWidget(QWidget *w) | - | ||||||||||||||||||||||||
219 | { | - | ||||||||||||||||||||||||
220 | addChildWidget(w); | - | ||||||||||||||||||||||||
221 | addItem(QLayoutPrivate::createWidgetItem(this, w)); | - | ||||||||||||||||||||||||
222 | } never executed: end of block | 0 | ||||||||||||||||||||||||
223 | - | |||||||||||||||||||||||||
224 | - | |||||||||||||||||||||||||
225 | - | |||||||||||||||||||||||||
226 | /*! | - | ||||||||||||||||||||||||
227 | Sets the alignment for widget \a w to \a alignment and returns | - | ||||||||||||||||||||||||
228 | true if \a w is found in this layout (not including child | - | ||||||||||||||||||||||||
229 | layouts); otherwise returns \c false. | - | ||||||||||||||||||||||||
230 | */ | - | ||||||||||||||||||||||||
231 | bool QLayout::setAlignment(QWidget *w, Qt::Alignment alignment) | - | ||||||||||||||||||||||||
232 | { | - | ||||||||||||||||||||||||
233 | int i = 0; | - | ||||||||||||||||||||||||
234 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
235 | while (item) {
| 0 | ||||||||||||||||||||||||
236 | if (item->widget() == w) {
| 0 | ||||||||||||||||||||||||
237 | item->setAlignment(alignment); | - | ||||||||||||||||||||||||
238 | invalidate(); | - | ||||||||||||||||||||||||
239 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
240 | } | - | ||||||||||||||||||||||||
241 | ++i; | - | ||||||||||||||||||||||||
242 | item = itemAt(i); | - | ||||||||||||||||||||||||
243 | } never executed: end of block | 0 | ||||||||||||||||||||||||
244 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
245 | } | - | ||||||||||||||||||||||||
246 | - | |||||||||||||||||||||||||
247 | /*! | - | ||||||||||||||||||||||||
248 | \overload | - | ||||||||||||||||||||||||
249 | - | |||||||||||||||||||||||||
250 | Sets the alignment for the layout \a l to \a alignment and | - | ||||||||||||||||||||||||
251 | returns \c true if \a l is found in this layout (not including child | - | ||||||||||||||||||||||||
252 | layouts); otherwise returns \c false. | - | ||||||||||||||||||||||||
253 | */ | - | ||||||||||||||||||||||||
254 | bool QLayout::setAlignment(QLayout *l, Qt::Alignment alignment) | - | ||||||||||||||||||||||||
255 | { | - | ||||||||||||||||||||||||
256 | int i = 0; | - | ||||||||||||||||||||||||
257 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
258 | while (item) {
| 0 | ||||||||||||||||||||||||
259 | if (item->layout() == l) {
| 0 | ||||||||||||||||||||||||
260 | item->setAlignment(alignment); | - | ||||||||||||||||||||||||
261 | invalidate(); | - | ||||||||||||||||||||||||
262 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
263 | } | - | ||||||||||||||||||||||||
264 | ++i; | - | ||||||||||||||||||||||||
265 | item = itemAt(i); | - | ||||||||||||||||||||||||
266 | } never executed: end of block | 0 | ||||||||||||||||||||||||
267 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
268 | } | - | ||||||||||||||||||||||||
269 | - | |||||||||||||||||||||||||
270 | /*! | - | ||||||||||||||||||||||||
271 | \property QLayout::margin | - | ||||||||||||||||||||||||
272 | \brief the width of the outside border of the layout | - | ||||||||||||||||||||||||
273 | \obsolete | - | ||||||||||||||||||||||||
274 | - | |||||||||||||||||||||||||
275 | Use setContentsMargins() and getContentsMargins() instead. | - | ||||||||||||||||||||||||
276 | - | |||||||||||||||||||||||||
277 | \sa contentsRect(), spacing | - | ||||||||||||||||||||||||
278 | */ | - | ||||||||||||||||||||||||
279 | - | |||||||||||||||||||||||||
280 | /*! | - | ||||||||||||||||||||||||
281 | \obsolete | - | ||||||||||||||||||||||||
282 | */ | - | ||||||||||||||||||||||||
283 | int QLayout::margin() const | - | ||||||||||||||||||||||||
284 | { | - | ||||||||||||||||||||||||
285 | int left, top, right, bottom; | - | ||||||||||||||||||||||||
286 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||||||||
287 | if (left == top && top == right && right == bottom) {
| 0 | ||||||||||||||||||||||||
288 | return left; never executed: return left; | 0 | ||||||||||||||||||||||||
289 | } else { | - | ||||||||||||||||||||||||
290 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
291 | } | - | ||||||||||||||||||||||||
292 | } | - | ||||||||||||||||||||||||
293 | - | |||||||||||||||||||||||||
294 | /*! | - | ||||||||||||||||||||||||
295 | \property QLayout::spacing | - | ||||||||||||||||||||||||
296 | \brief the spacing between widgets inside the layout | - | ||||||||||||||||||||||||
297 | - | |||||||||||||||||||||||||
298 | If no value is explicitly set, the layout's spacing is inherited | - | ||||||||||||||||||||||||
299 | from the parent layout, or from the style settings for the parent | - | ||||||||||||||||||||||||
300 | widget. | - | ||||||||||||||||||||||||
301 | - | |||||||||||||||||||||||||
302 | For QGridLayout and QFormLayout, it is possible to set different horizontal and | - | ||||||||||||||||||||||||
303 | vertical spacings using \l{QGridLayout::}{setHorizontalSpacing()} | - | ||||||||||||||||||||||||
304 | and \l{QGridLayout::}{setVerticalSpacing()}. In that case, | - | ||||||||||||||||||||||||
305 | spacing() returns -1. | - | ||||||||||||||||||||||||
306 | - | |||||||||||||||||||||||||
307 | \sa contentsRect(), getContentsMargins(), QStyle::layoutSpacing(), | - | ||||||||||||||||||||||||
308 | QStyle::pixelMetric() | - | ||||||||||||||||||||||||
309 | */ | - | ||||||||||||||||||||||||
310 | - | |||||||||||||||||||||||||
311 | int QLayout::spacing() const | - | ||||||||||||||||||||||||
312 | { | - | ||||||||||||||||||||||||
313 | if (const QBoxLayout* boxlayout = qobject_cast<const QBoxLayout*>(this)) {
| 0 | ||||||||||||||||||||||||
314 | return boxlayout->spacing(); never executed: return boxlayout->spacing(); | 0 | ||||||||||||||||||||||||
315 | } else if (const QGridLayout* gridlayout = qobject_cast<const QGridLayout*>(this)) {
| 0 | ||||||||||||||||||||||||
316 | return gridlayout->spacing(); never executed: return gridlayout->spacing(); | 0 | ||||||||||||||||||||||||
317 | } else if (const QFormLayout* formlayout = qobject_cast<const QFormLayout*>(this)) {
| 0 | ||||||||||||||||||||||||
318 | return formlayout->spacing(); never executed: return formlayout->spacing(); | 0 | ||||||||||||||||||||||||
319 | } else { | - | ||||||||||||||||||||||||
320 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
321 | if (d->insideSpacing >=0) {
| 0 | ||||||||||||||||||||||||
322 | return d->insideSpacing; never executed: return d->insideSpacing; | 0 | ||||||||||||||||||||||||
323 | } else { | - | ||||||||||||||||||||||||
324 | // arbitrarily prefer horizontal spacing to vertical spacing | - | ||||||||||||||||||||||||
325 | return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing); never executed: return qSmartSpacing(this, QStyle::PM_LayoutHorizontalSpacing); | 0 | ||||||||||||||||||||||||
326 | } | - | ||||||||||||||||||||||||
327 | } | - | ||||||||||||||||||||||||
328 | } | - | ||||||||||||||||||||||||
329 | - | |||||||||||||||||||||||||
330 | /*! | - | ||||||||||||||||||||||||
331 | \obsolete | - | ||||||||||||||||||||||||
332 | */ | - | ||||||||||||||||||||||||
333 | void QLayout::setMargin(int margin) | - | ||||||||||||||||||||||||
334 | { | - | ||||||||||||||||||||||||
335 | setContentsMargins(margin, margin, margin, margin); | - | ||||||||||||||||||||||||
336 | } never executed: end of block | 0 | ||||||||||||||||||||||||
337 | - | |||||||||||||||||||||||||
338 | void QLayout::setSpacing(int spacing) | - | ||||||||||||||||||||||||
339 | { | - | ||||||||||||||||||||||||
340 | if (QBoxLayout* boxlayout = qobject_cast<QBoxLayout*>(this)) {
| 0 | ||||||||||||||||||||||||
341 | boxlayout->setSpacing(spacing); | - | ||||||||||||||||||||||||
342 | } else if (QGridLayout* gridlayout = qobject_cast<QGridLayout*>(this)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
343 | gridlayout->setSpacing(spacing); | - | ||||||||||||||||||||||||
344 | } else if (QFormLayout* formlayout = qobject_cast<QFormLayout*>(this)) { never executed: end of block
| 0 | ||||||||||||||||||||||||
345 | formlayout->setSpacing(spacing); | - | ||||||||||||||||||||||||
346 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
347 | Q_D(QLayout); | - | ||||||||||||||||||||||||
348 | d->insideSpacing = spacing; | - | ||||||||||||||||||||||||
349 | invalidate(); | - | ||||||||||||||||||||||||
350 | } never executed: end of block | 0 | ||||||||||||||||||||||||
351 | } | - | ||||||||||||||||||||||||
352 | - | |||||||||||||||||||||||||
353 | /*! | - | ||||||||||||||||||||||||
354 | \since 4.3 | - | ||||||||||||||||||||||||
355 | - | |||||||||||||||||||||||||
356 | Sets the \a left, \a top, \a right, and \a bottom margins to use | - | ||||||||||||||||||||||||
357 | around the layout. | - | ||||||||||||||||||||||||
358 | - | |||||||||||||||||||||||||
359 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
360 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
361 | - | |||||||||||||||||||||||||
362 | \sa getContentsMargins(), QStyle::pixelMetric(), | - | ||||||||||||||||||||||||
363 | {QStyle::}{PM_LayoutLeftMargin}, | - | ||||||||||||||||||||||||
364 | {QStyle::}{PM_LayoutTopMargin}, | - | ||||||||||||||||||||||||
365 | {QStyle::}{PM_LayoutRightMargin}, | - | ||||||||||||||||||||||||
366 | {QStyle::}{PM_LayoutBottomMargin} | - | ||||||||||||||||||||||||
367 | */ | - | ||||||||||||||||||||||||
368 | void QLayout::setContentsMargins(int left, int top, int right, int bottom) | - | ||||||||||||||||||||||||
369 | { | - | ||||||||||||||||||||||||
370 | Q_D(QLayout); | - | ||||||||||||||||||||||||
371 | - | |||||||||||||||||||||||||
372 | if (d->userLeftMargin == left && d->userTopMargin == top &&
| 0 | ||||||||||||||||||||||||
373 | d->userRightMargin == right && d->userBottomMargin == bottom)
| 0 | ||||||||||||||||||||||||
374 | return; never executed: return; | 0 | ||||||||||||||||||||||||
375 | - | |||||||||||||||||||||||||
376 | d->userLeftMargin = left; | - | ||||||||||||||||||||||||
377 | d->userTopMargin = top; | - | ||||||||||||||||||||||||
378 | d->userRightMargin = right; | - | ||||||||||||||||||||||||
379 | d->userBottomMargin = bottom; | - | ||||||||||||||||||||||||
380 | invalidate(); | - | ||||||||||||||||||||||||
381 | } never executed: end of block | 0 | ||||||||||||||||||||||||
382 | - | |||||||||||||||||||||||||
383 | /*! | - | ||||||||||||||||||||||||
384 | \since 4.6 | - | ||||||||||||||||||||||||
385 | - | |||||||||||||||||||||||||
386 | Sets the \a margins to use around the layout. | - | ||||||||||||||||||||||||
387 | - | |||||||||||||||||||||||||
388 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
389 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
390 | - | |||||||||||||||||||||||||
391 | \sa contentsMargins() | - | ||||||||||||||||||||||||
392 | */ | - | ||||||||||||||||||||||||
393 | void QLayout::setContentsMargins(const QMargins &margins) | - | ||||||||||||||||||||||||
394 | { | - | ||||||||||||||||||||||||
395 | setContentsMargins(margins.left(), margins.top(), margins.right(), margins.bottom()); | - | ||||||||||||||||||||||||
396 | } never executed: end of block | 0 | ||||||||||||||||||||||||
397 | - | |||||||||||||||||||||||||
398 | /*! | - | ||||||||||||||||||||||||
399 | \since 4.3 | - | ||||||||||||||||||||||||
400 | - | |||||||||||||||||||||||||
401 | Extracts the left, top, right, and bottom margins used around the | - | ||||||||||||||||||||||||
402 | layout, and assigns them to *\a left, *\a top, *\a right, and *\a | - | ||||||||||||||||||||||||
403 | bottom (unless they are null pointers). | - | ||||||||||||||||||||||||
404 | - | |||||||||||||||||||||||||
405 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
406 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||
408 | \sa setContentsMargins(), QStyle::pixelMetric(), | - | ||||||||||||||||||||||||
409 | {QStyle::}{PM_LayoutLeftMargin}, | - | ||||||||||||||||||||||||
410 | {QStyle::}{PM_LayoutTopMargin}, | - | ||||||||||||||||||||||||
411 | {QStyle::}{PM_LayoutRightMargin}, | - | ||||||||||||||||||||||||
412 | {QStyle::}{PM_LayoutBottomMargin} | - | ||||||||||||||||||||||||
413 | */ | - | ||||||||||||||||||||||||
414 | void QLayout::getContentsMargins(int *left, int *top, int *right, int *bottom) const | - | ||||||||||||||||||||||||
415 | { | - | ||||||||||||||||||||||||
416 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
417 | d->getMargin(left, d->userLeftMargin, QStyle::PM_LayoutLeftMargin); | - | ||||||||||||||||||||||||
418 | d->getMargin(top, d->userTopMargin, QStyle::PM_LayoutTopMargin); | - | ||||||||||||||||||||||||
419 | d->getMargin(right, d->userRightMargin, QStyle::PM_LayoutRightMargin); | - | ||||||||||||||||||||||||
420 | d->getMargin(bottom, d->userBottomMargin, QStyle::PM_LayoutBottomMargin); | - | ||||||||||||||||||||||||
421 | } never executed: end of block | 0 | ||||||||||||||||||||||||
422 | - | |||||||||||||||||||||||||
423 | /*! | - | ||||||||||||||||||||||||
424 | \since 4.6 | - | ||||||||||||||||||||||||
425 | - | |||||||||||||||||||||||||
426 | Returns the margins used around the layout. | - | ||||||||||||||||||||||||
427 | - | |||||||||||||||||||||||||
428 | By default, QLayout uses the values provided by the style. On | - | ||||||||||||||||||||||||
429 | most platforms, the margin is 11 pixels in all directions. | - | ||||||||||||||||||||||||
430 | - | |||||||||||||||||||||||||
431 | \sa setContentsMargins() | - | ||||||||||||||||||||||||
432 | */ | - | ||||||||||||||||||||||||
433 | QMargins QLayout::contentsMargins() const | - | ||||||||||||||||||||||||
434 | { | - | ||||||||||||||||||||||||
435 | int left, top, right, bottom; | - | ||||||||||||||||||||||||
436 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||||||||
437 | return QMargins(left, top, right, bottom); never executed: return QMargins(left, top, right, bottom); | 0 | ||||||||||||||||||||||||
438 | } | - | ||||||||||||||||||||||||
439 | - | |||||||||||||||||||||||||
440 | /*! | - | ||||||||||||||||||||||||
441 | \since 4.3 | - | ||||||||||||||||||||||||
442 | - | |||||||||||||||||||||||||
443 | Returns the layout's geometry() rectangle, but taking into account the | - | ||||||||||||||||||||||||
444 | contents margins. | - | ||||||||||||||||||||||||
445 | - | |||||||||||||||||||||||||
446 | \sa setContentsMargins(), getContentsMargins() | - | ||||||||||||||||||||||||
447 | */ | - | ||||||||||||||||||||||||
448 | QRect QLayout::contentsRect() const | - | ||||||||||||||||||||||||
449 | { | - | ||||||||||||||||||||||||
450 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
451 | int left, top, right, bottom; | - | ||||||||||||||||||||||||
452 | getContentsMargins(&left, &top, &right, &bottom); | - | ||||||||||||||||||||||||
453 | return d->rect.adjusted(+left, +top, -right, -bottom); never executed: return d->rect.adjusted(+left, +top, -right, -bottom); | 0 | ||||||||||||||||||||||||
454 | } | - | ||||||||||||||||||||||||
455 | - | |||||||||||||||||||||||||
456 | - | |||||||||||||||||||||||||
457 | /*! | - | ||||||||||||||||||||||||
458 | Returns the parent widget of this layout, or 0 if this layout is | - | ||||||||||||||||||||||||
459 | not installed on any widget. | - | ||||||||||||||||||||||||
460 | - | |||||||||||||||||||||||||
461 | If the layout is a sub-layout, this function returns the parent | - | ||||||||||||||||||||||||
462 | widget of the parent layout. | - | ||||||||||||||||||||||||
463 | - | |||||||||||||||||||||||||
464 | \sa parent() | - | ||||||||||||||||||||||||
465 | */ | - | ||||||||||||||||||||||||
466 | QWidget *QLayout::parentWidget() const | - | ||||||||||||||||||||||||
467 | { | - | ||||||||||||||||||||||||
468 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
469 | if (!d->topLevel) {
| 0 | ||||||||||||||||||||||||
470 | if (parent()) {
| 0 | ||||||||||||||||||||||||
471 | QLayout *parentLayout = qobject_cast<QLayout*>(parent()); | - | ||||||||||||||||||||||||
472 | if (!parentLayout) {
| 0 | ||||||||||||||||||||||||
473 | qWarning("QLayout::parentWidget: A layout can only have another layout as a parent."); | - | ||||||||||||||||||||||||
474 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
475 | } | - | ||||||||||||||||||||||||
476 | return parentLayout->parentWidget(); never executed: return parentLayout->parentWidget(); | 0 | ||||||||||||||||||||||||
477 | } else { | - | ||||||||||||||||||||||||
478 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
479 | } | - | ||||||||||||||||||||||||
480 | } else { | - | ||||||||||||||||||||||||
481 | Q_ASSERT(parent() && parent()->isWidgetType()); | - | ||||||||||||||||||||||||
482 | return static_cast<QWidget *>(parent()); never executed: return static_cast<QWidget *>(parent()); | 0 | ||||||||||||||||||||||||
483 | } | - | ||||||||||||||||||||||||
484 | } | - | ||||||||||||||||||||||||
485 | - | |||||||||||||||||||||||||
486 | /*! | - | ||||||||||||||||||||||||
487 | \reimp | - | ||||||||||||||||||||||||
488 | */ | - | ||||||||||||||||||||||||
489 | bool QLayout::isEmpty() const | - | ||||||||||||||||||||||||
490 | { | - | ||||||||||||||||||||||||
491 | int i = 0; | - | ||||||||||||||||||||||||
492 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
493 | while (item) {
| 0 | ||||||||||||||||||||||||
494 | if (!item->isEmpty())
| 0 | ||||||||||||||||||||||||
495 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
496 | ++i; | - | ||||||||||||||||||||||||
497 | item = itemAt(i); | - | ||||||||||||||||||||||||
498 | } never executed: end of block | 0 | ||||||||||||||||||||||||
499 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
500 | } | - | ||||||||||||||||||||||||
501 | - | |||||||||||||||||||||||||
502 | /*! | - | ||||||||||||||||||||||||
503 | \reimp | - | ||||||||||||||||||||||||
504 | */ | - | ||||||||||||||||||||||||
505 | QSizePolicy::ControlTypes QLayout::controlTypes() const | - | ||||||||||||||||||||||||
506 | { | - | ||||||||||||||||||||||||
507 | if (count() == 0)
| 0 | ||||||||||||||||||||||||
508 | return QSizePolicy::DefaultType; never executed: return QSizePolicy::DefaultType; | 0 | ||||||||||||||||||||||||
509 | QSizePolicy::ControlTypes types; | - | ||||||||||||||||||||||||
510 | for (int i = count() - 1; i >= 0; --i)
| 0 | ||||||||||||||||||||||||
511 | types |= itemAt(i)->controlTypes(); never executed: types |= itemAt(i)->controlTypes(); | 0 | ||||||||||||||||||||||||
512 | return types; never executed: return types; | 0 | ||||||||||||||||||||||||
513 | } | - | ||||||||||||||||||||||||
514 | - | |||||||||||||||||||||||||
515 | /*! | - | ||||||||||||||||||||||||
516 | \reimp | - | ||||||||||||||||||||||||
517 | */ | - | ||||||||||||||||||||||||
518 | void QLayout::setGeometry(const QRect &r) | - | ||||||||||||||||||||||||
519 | { | - | ||||||||||||||||||||||||
520 | Q_D(QLayout); | - | ||||||||||||||||||||||||
521 | d->rect = r; | - | ||||||||||||||||||||||||
522 | } never executed: end of block | 0 | ||||||||||||||||||||||||
523 | - | |||||||||||||||||||||||||
524 | /*! | - | ||||||||||||||||||||||||
525 | \reimp | - | ||||||||||||||||||||||||
526 | */ | - | ||||||||||||||||||||||||
527 | QRect QLayout::geometry() const | - | ||||||||||||||||||||||||
528 | { | - | ||||||||||||||||||||||||
529 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
530 | return d->rect; never executed: return d->rect; | 0 | ||||||||||||||||||||||||
531 | } | - | ||||||||||||||||||||||||
532 | - | |||||||||||||||||||||||||
533 | /*! | - | ||||||||||||||||||||||||
534 | \reimp | - | ||||||||||||||||||||||||
535 | */ | - | ||||||||||||||||||||||||
536 | void QLayout::invalidate() | - | ||||||||||||||||||||||||
537 | { | - | ||||||||||||||||||||||||
538 | Q_D(QLayout); | - | ||||||||||||||||||||||||
539 | d->rect = QRect(); | - | ||||||||||||||||||||||||
540 | update(); | - | ||||||||||||||||||||||||
541 | } never executed: end of block | 0 | ||||||||||||||||||||||||
542 | - | |||||||||||||||||||||||||
543 | static bool removeWidgetRecursively(QLayoutItem *li, QObject *w) | - | ||||||||||||||||||||||||
544 | { | - | ||||||||||||||||||||||||
545 | QLayout *lay = li->layout(); | - | ||||||||||||||||||||||||
546 | if (!lay)
| 0 | ||||||||||||||||||||||||
547 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
548 | int i = 0; | - | ||||||||||||||||||||||||
549 | QLayoutItem *child; | - | ||||||||||||||||||||||||
550 | while ((child = lay->itemAt(i))) {
| 0 | ||||||||||||||||||||||||
551 | if (child->widget() == w) {
| 0 | ||||||||||||||||||||||||
552 | delete lay->takeAt(i); | - | ||||||||||||||||||||||||
553 | lay->invalidate(); | - | ||||||||||||||||||||||||
554 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
555 | } else if (removeWidgetRecursively(child, w)) {
| 0 | ||||||||||||||||||||||||
556 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
557 | } else { | - | ||||||||||||||||||||||||
558 | ++i; | - | ||||||||||||||||||||||||
559 | } never executed: end of block | 0 | ||||||||||||||||||||||||
560 | } | - | ||||||||||||||||||||||||
561 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
562 | } | - | ||||||||||||||||||||||||
563 | - | |||||||||||||||||||||||||
564 | - | |||||||||||||||||||||||||
565 | void QLayoutPrivate::doResize(const QSize &r) | - | ||||||||||||||||||||||||
566 | { | - | ||||||||||||||||||||||||
567 | Q_Q(QLayout); | - | ||||||||||||||||||||||||
568 | int mbh = menuBarHeightForWidth(menubar, r.width()); | - | ||||||||||||||||||||||||
569 | QWidget *mw = q->parentWidget(); | - | ||||||||||||||||||||||||
570 | QRect rect = mw->testAttribute(Qt::WA_LayoutOnEntireRect) ? mw->rect() : mw->contentsRect();
| 0 | ||||||||||||||||||||||||
571 | const int mbTop = rect.top(); | - | ||||||||||||||||||||||||
572 | rect.setTop(rect.top() + mbh); | - | ||||||||||||||||||||||||
573 | q->setGeometry(rect); | - | ||||||||||||||||||||||||
574 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
575 | if (menubar)
| 0 | ||||||||||||||||||||||||
576 | menubar->setGeometry(rect.left(), mbTop, r.width(), mbh); never executed: menubar->setGeometry(rect.left(), mbTop, r.width(), mbh); | 0 | ||||||||||||||||||||||||
577 | #endif | - | ||||||||||||||||||||||||
578 | } never executed: end of block | 0 | ||||||||||||||||||||||||
579 | - | |||||||||||||||||||||||||
580 | - | |||||||||||||||||||||||||
581 | /*! | - | ||||||||||||||||||||||||
582 | \internal | - | ||||||||||||||||||||||||
583 | Performs child widget layout when the parent widget is | - | ||||||||||||||||||||||||
584 | resized. Also handles removal of widgets. \a e is the | - | ||||||||||||||||||||||||
585 | event | - | ||||||||||||||||||||||||
586 | */ | - | ||||||||||||||||||||||||
587 | void QLayout::widgetEvent(QEvent *e) | - | ||||||||||||||||||||||||
588 | { | - | ||||||||||||||||||||||||
589 | Q_D(QLayout); | - | ||||||||||||||||||||||||
590 | if (!d->enabled)
| 0 | ||||||||||||||||||||||||
591 | return; never executed: return; | 0 | ||||||||||||||||||||||||
592 | - | |||||||||||||||||||||||||
593 | switch (e->type()) { | - | ||||||||||||||||||||||||
594 | case QEvent::Resize: never executed: case QEvent::Resize: | 0 | ||||||||||||||||||||||||
595 | if (d->activated) {
| 0 | ||||||||||||||||||||||||
596 | QResizeEvent *r = (QResizeEvent *)e; | - | ||||||||||||||||||||||||
597 | d->doResize(r->size()); | - | ||||||||||||||||||||||||
598 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
599 | activate(); | - | ||||||||||||||||||||||||
600 | } never executed: end of block | 0 | ||||||||||||||||||||||||
601 | break; never executed: break; | 0 | ||||||||||||||||||||||||
602 | case QEvent::ChildRemoved: never executed: case QEvent::ChildRemoved: | 0 | ||||||||||||||||||||||||
603 | { | - | ||||||||||||||||||||||||
604 | QChildEvent *c = (QChildEvent *)e; | - | ||||||||||||||||||||||||
605 | if (c->child()->isWidgetType()) {
| 0 | ||||||||||||||||||||||||
606 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
607 | if (c->child() == d->menubar)
| 0 | ||||||||||||||||||||||||
608 | d->menubar = 0; never executed: d->menubar = 0; | 0 | ||||||||||||||||||||||||
609 | #endif | - | ||||||||||||||||||||||||
610 | removeWidgetRecursively(this, c->child()); | - | ||||||||||||||||||||||||
611 | } never executed: end of block | 0 | ||||||||||||||||||||||||
612 | } | - | ||||||||||||||||||||||||
613 | break; never executed: break; | 0 | ||||||||||||||||||||||||
614 | case QEvent::LayoutRequest: never executed: case QEvent::LayoutRequest: | 0 | ||||||||||||||||||||||||
615 | if (static_cast<QWidget *>(parent())->isVisible())
| 0 | ||||||||||||||||||||||||
616 | activate(); never executed: activate(); | 0 | ||||||||||||||||||||||||
617 | break; never executed: break; | 0 | ||||||||||||||||||||||||
618 | default: never executed: default: | 0 | ||||||||||||||||||||||||
619 | break; never executed: break; | 0 | ||||||||||||||||||||||||
620 | } | - | ||||||||||||||||||||||||
621 | } | - | ||||||||||||||||||||||||
622 | - | |||||||||||||||||||||||||
623 | /*! | - | ||||||||||||||||||||||||
624 | \reimp | - | ||||||||||||||||||||||||
625 | */ | - | ||||||||||||||||||||||||
626 | void QLayout::childEvent(QChildEvent *e) | - | ||||||||||||||||||||||||
627 | { | - | ||||||||||||||||||||||||
628 | Q_D(QLayout); | - | ||||||||||||||||||||||||
629 | if (!d->enabled)
| 0 | ||||||||||||||||||||||||
630 | return; never executed: return; | 0 | ||||||||||||||||||||||||
631 | - | |||||||||||||||||||||||||
632 | if (e->type() == QEvent::ChildRemoved) {
| 0 | ||||||||||||||||||||||||
633 | QChildEvent *c = (QChildEvent*)e; | - | ||||||||||||||||||||||||
634 | int i = 0; | - | ||||||||||||||||||||||||
635 | - | |||||||||||||||||||||||||
636 | QLayoutItem *item; | - | ||||||||||||||||||||||||
637 | while ((item = itemAt(i))) {
| 0 | ||||||||||||||||||||||||
638 | if (item == static_cast<QLayout*>(c->child())) {
| 0 | ||||||||||||||||||||||||
639 | takeAt(i); | - | ||||||||||||||||||||||||
640 | invalidate(); | - | ||||||||||||||||||||||||
641 | break; never executed: break; | 0 | ||||||||||||||||||||||||
642 | } else { | - | ||||||||||||||||||||||||
643 | ++i; | - | ||||||||||||||||||||||||
644 | } never executed: end of block | 0 | ||||||||||||||||||||||||
645 | } | - | ||||||||||||||||||||||||
646 | } never executed: end of block | 0 | ||||||||||||||||||||||||
647 | } never executed: end of block | 0 | ||||||||||||||||||||||||
648 | - | |||||||||||||||||||||||||
649 | /*! | - | ||||||||||||||||||||||||
650 | \internal | - | ||||||||||||||||||||||||
651 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
652 | */ | - | ||||||||||||||||||||||||
653 | int QLayout::totalHeightForWidth(int w) const | - | ||||||||||||||||||||||||
654 | { | - | ||||||||||||||||||||||||
655 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
656 | int side=0, top=0; | - | ||||||||||||||||||||||||
657 | if (d->topLevel) {
| 0 | ||||||||||||||||||||||||
658 | QWidget *parent = parentWidget(); | - | ||||||||||||||||||||||||
659 | parent->ensurePolished(); | - | ||||||||||||||||||||||||
660 | QWidgetPrivate *wd = parent->d_func(); | - | ||||||||||||||||||||||||
661 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
662 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
663 | } never executed: end of block | 0 | ||||||||||||||||||||||||
664 | int h = heightForWidth(w - side) + top; | - | ||||||||||||||||||||||||
665 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
666 | h += menuBarHeightForWidth(d->menubar, w); | - | ||||||||||||||||||||||||
667 | #endif | - | ||||||||||||||||||||||||
668 | return h; never executed: return h; | 0 | ||||||||||||||||||||||||
669 | } | - | ||||||||||||||||||||||||
670 | - | |||||||||||||||||||||||||
671 | /*! | - | ||||||||||||||||||||||||
672 | \internal | - | ||||||||||||||||||||||||
673 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
674 | */ | - | ||||||||||||||||||||||||
675 | QSize QLayout::totalMinimumSize() const | - | ||||||||||||||||||||||||
676 | { | - | ||||||||||||||||||||||||
677 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
678 | int side=0, top=0; | - | ||||||||||||||||||||||||
679 | if (d->topLevel) {
| 0 | ||||||||||||||||||||||||
680 | QWidget *pw = parentWidget(); | - | ||||||||||||||||||||||||
681 | pw->ensurePolished(); | - | ||||||||||||||||||||||||
682 | QWidgetPrivate *wd = pw->d_func(); | - | ||||||||||||||||||||||||
683 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
684 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
685 | } never executed: end of block | 0 | ||||||||||||||||||||||||
686 | - | |||||||||||||||||||||||||
687 | QSize s = minimumSize(); | - | ||||||||||||||||||||||||
688 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
689 | top += menuBarHeightForWidth(d->menubar, s.width() + side); | - | ||||||||||||||||||||||||
690 | #endif | - | ||||||||||||||||||||||||
691 | return s + QSize(side, top); never executed: return s + QSize(side, top); | 0 | ||||||||||||||||||||||||
692 | } | - | ||||||||||||||||||||||||
693 | - | |||||||||||||||||||||||||
694 | /*! | - | ||||||||||||||||||||||||
695 | \internal | - | ||||||||||||||||||||||||
696 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
697 | */ | - | ||||||||||||||||||||||||
698 | QSize QLayout::totalSizeHint() const | - | ||||||||||||||||||||||||
699 | { | - | ||||||||||||||||||||||||
700 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
701 | int side=0, top=0; | - | ||||||||||||||||||||||||
702 | if (d->topLevel) {
| 0 | ||||||||||||||||||||||||
703 | QWidget *pw = parentWidget(); | - | ||||||||||||||||||||||||
704 | pw->ensurePolished(); | - | ||||||||||||||||||||||||
705 | QWidgetPrivate *wd = pw->d_func(); | - | ||||||||||||||||||||||||
706 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
707 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
708 | } never executed: end of block | 0 | ||||||||||||||||||||||||
709 | - | |||||||||||||||||||||||||
710 | QSize s = sizeHint(); | - | ||||||||||||||||||||||||
711 | if (hasHeightForWidth())
| 0 | ||||||||||||||||||||||||
712 | s.setHeight(heightForWidth(s.width() + side)); never executed: s.setHeight(heightForWidth(s.width() + side)); | 0 | ||||||||||||||||||||||||
713 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
714 | top += menuBarHeightForWidth(d->menubar, s.width()); | - | ||||||||||||||||||||||||
715 | #endif | - | ||||||||||||||||||||||||
716 | return s + QSize(side, top); never executed: return s + QSize(side, top); | 0 | ||||||||||||||||||||||||
717 | } | - | ||||||||||||||||||||||||
718 | - | |||||||||||||||||||||||||
719 | /*! | - | ||||||||||||||||||||||||
720 | \internal | - | ||||||||||||||||||||||||
721 | Also takes contentsMargins and menu bar into account. | - | ||||||||||||||||||||||||
722 | */ | - | ||||||||||||||||||||||||
723 | QSize QLayout::totalMaximumSize() const | - | ||||||||||||||||||||||||
724 | { | - | ||||||||||||||||||||||||
725 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
726 | int side=0, top=0; | - | ||||||||||||||||||||||||
727 | if (d->topLevel) {
| 0 | ||||||||||||||||||||||||
728 | QWidget *pw = parentWidget(); | - | ||||||||||||||||||||||||
729 | pw->ensurePolished(); | - | ||||||||||||||||||||||||
730 | QWidgetPrivate *wd = pw->d_func(); | - | ||||||||||||||||||||||||
731 | side += wd->leftmargin + wd->rightmargin; | - | ||||||||||||||||||||||||
732 | top += wd->topmargin + wd->bottommargin; | - | ||||||||||||||||||||||||
733 | } never executed: end of block | 0 | ||||||||||||||||||||||||
734 | - | |||||||||||||||||||||||||
735 | QSize s = maximumSize(); | - | ||||||||||||||||||||||||
736 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
737 | top += menuBarHeightForWidth(d->menubar, s.width()); | - | ||||||||||||||||||||||||
738 | #endif | - | ||||||||||||||||||||||||
739 | - | |||||||||||||||||||||||||
740 | if (d->topLevel)
| 0 | ||||||||||||||||||||||||
741 | s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX), never executed: s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX), qMin(s.height() + top, QLAYOUTSIZE_MAX)); | 0 | ||||||||||||||||||||||||
742 | qMin(s.height() + top, QLAYOUTSIZE_MAX)); never executed: s = QSize(qMin(s.width() + side, QLAYOUTSIZE_MAX), qMin(s.height() + top, QLAYOUTSIZE_MAX)); | 0 | ||||||||||||||||||||||||
743 | return s; never executed: return s; | 0 | ||||||||||||||||||||||||
744 | } | - | ||||||||||||||||||||||||
745 | - | |||||||||||||||||||||||||
746 | /*! | - | ||||||||||||||||||||||||
747 | \internal | - | ||||||||||||||||||||||||
748 | Destroys the layout, deleting all child layouts. | - | ||||||||||||||||||||||||
749 | Geometry management stops when a top-level layout is deleted. | - | ||||||||||||||||||||||||
750 | - | |||||||||||||||||||||||||
751 | The layout classes will probably be fatally confused if you delete | - | ||||||||||||||||||||||||
752 | a sublayout. | - | ||||||||||||||||||||||||
753 | */ | - | ||||||||||||||||||||||||
754 | QLayout::~QLayout() | - | ||||||||||||||||||||||||
755 | { | - | ||||||||||||||||||||||||
756 | Q_D(QLayout); | - | ||||||||||||||||||||||||
757 | /* | - | ||||||||||||||||||||||||
758 | This function may be called during the QObject destructor, | - | ||||||||||||||||||||||||
759 | when the parent no longer is a QWidget. | - | ||||||||||||||||||||||||
760 | */ | - | ||||||||||||||||||||||||
761 | if (d->topLevel && parent() && parent()->isWidgetType() &&
| 0 | ||||||||||||||||||||||||
762 | ((QWidget*)parent())->layout() == this)
| 0 | ||||||||||||||||||||||||
763 | ((QWidget*)parent())->d_func()->layout = 0; never executed: ((QWidget*)parent())->d_func()->layout = 0; | 0 | ||||||||||||||||||||||||
764 | } never executed: end of block | 0 | ||||||||||||||||||||||||
765 | - | |||||||||||||||||||||||||
766 | - | |||||||||||||||||||||||||
767 | /*! | - | ||||||||||||||||||||||||
768 | This function is called from \c addLayout() or \c insertLayout() functions in | - | ||||||||||||||||||||||||
769 | subclasses to add layout \a l as a sub-layout. | - | ||||||||||||||||||||||||
770 | - | |||||||||||||||||||||||||
771 | The only scenario in which you need to call it directly is if you | - | ||||||||||||||||||||||||
772 | implement a custom layout that supports nested layouts. | - | ||||||||||||||||||||||||
773 | - | |||||||||||||||||||||||||
774 | \sa QBoxLayout::addLayout(), QBoxLayout::insertLayout(), QGridLayout::addLayout() | - | ||||||||||||||||||||||||
775 | */ | - | ||||||||||||||||||||||||
776 | void QLayout::addChildLayout(QLayout *l) | - | ||||||||||||||||||||||||
777 | { | - | ||||||||||||||||||||||||
778 | if (l->parent()) {
| 0 | ||||||||||||||||||||||||
779 | qWarning("QLayout::addChildLayout: layout \"%s\" already has a parent", | - | ||||||||||||||||||||||||
780 | l->objectName().toLocal8Bit().data()); | - | ||||||||||||||||||||||||
781 | return; never executed: return; | 0 | ||||||||||||||||||||||||
782 | } | - | ||||||||||||||||||||||||
783 | l->setParent(this); | - | ||||||||||||||||||||||||
784 | - | |||||||||||||||||||||||||
785 | if (QWidget *mw = parentWidget()) {
| 0 | ||||||||||||||||||||||||
786 | l->d_func()->reparentChildWidgets(mw); | - | ||||||||||||||||||||||||
787 | } never executed: end of block | 0 | ||||||||||||||||||||||||
788 | - | |||||||||||||||||||||||||
789 | } never executed: end of block | 0 | ||||||||||||||||||||||||
790 | - | |||||||||||||||||||||||||
791 | /*! | - | ||||||||||||||||||||||||
792 | \internal | - | ||||||||||||||||||||||||
793 | */ | - | ||||||||||||||||||||||||
794 | bool QLayout::adoptLayout(QLayout *layout) | - | ||||||||||||||||||||||||
795 | { | - | ||||||||||||||||||||||||
796 | const bool ok = !layout->parent(); | - | ||||||||||||||||||||||||
797 | addChildLayout(layout); | - | ||||||||||||||||||||||||
798 | return ok; never executed: return ok; | 0 | ||||||||||||||||||||||||
799 | } | - | ||||||||||||||||||||||||
800 | - | |||||||||||||||||||||||||
801 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
802 | static bool layoutDebug() | - | ||||||||||||||||||||||||
803 | { | - | ||||||||||||||||||||||||
804 | static int checked_env = -1; | - | ||||||||||||||||||||||||
805 | if(checked_env == -1)
| 0 | ||||||||||||||||||||||||
806 | checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt(); never executed: checked_env = !!qgetenv("QT_LAYOUT_DEBUG").toInt(); | 0 | ||||||||||||||||||||||||
807 | - | |||||||||||||||||||||||||
808 | return checked_env; never executed: return checked_env; | 0 | ||||||||||||||||||||||||
809 | } | - | ||||||||||||||||||||||||
810 | #endif | - | ||||||||||||||||||||||||
811 | - | |||||||||||||||||||||||||
812 | void QLayoutPrivate::reparentChildWidgets(QWidget *mw) | - | ||||||||||||||||||||||||
813 | { | - | ||||||||||||||||||||||||
814 | Q_Q(QLayout); | - | ||||||||||||||||||||||||
815 | int n = q->count(); | - | ||||||||||||||||||||||||
816 | - | |||||||||||||||||||||||||
817 | #ifndef QT_NO_MENUBAR | - | ||||||||||||||||||||||||
818 | if (menubar && menubar->parentWidget() != mw) {
| 0 | ||||||||||||||||||||||||
819 | menubar->setParent(mw); | - | ||||||||||||||||||||||||
820 | } never executed: end of block | 0 | ||||||||||||||||||||||||
821 | #endif | - | ||||||||||||||||||||||||
822 | bool mwVisible = mw && mw->isVisible();
| 0 | ||||||||||||||||||||||||
823 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||||||||||||||
824 | QLayoutItem *item = q->itemAt(i); | - | ||||||||||||||||||||||||
825 | if (QWidget *w = item->widget()) {
| 0 | ||||||||||||||||||||||||
826 | QWidget *pw = w->parentWidget(); | - | ||||||||||||||||||||||||
827 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
828 | if (pw && pw != mw && layoutDebug()) {
| 0 | ||||||||||||||||||||||||
829 | qWarning("QLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent", | - | ||||||||||||||||||||||||
830 | w->metaObject()->className(), w->objectName().toLocal8Bit().data()); | - | ||||||||||||||||||||||||
831 | } never executed: end of block | 0 | ||||||||||||||||||||||||
832 | #endif | - | ||||||||||||||||||||||||
833 | bool needShow = mwVisible && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
| 0 | ||||||||||||||||||||||||
834 | if (pw != mw)
| 0 | ||||||||||||||||||||||||
835 | w->setParent(mw); never executed: w->setParent(mw); | 0 | ||||||||||||||||||||||||
836 | if (needShow)
| 0 | ||||||||||||||||||||||||
837 | QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); | 0 | ||||||||||||||||||||||||
838 | } else if (QLayout *l = item->layout()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
839 | l->d_func()->reparentChildWidgets(mw); | - | ||||||||||||||||||||||||
840 | } never executed: end of block | 0 | ||||||||||||||||||||||||
841 | } never executed: end of block | 0 | ||||||||||||||||||||||||
842 | } never executed: end of block | 0 | ||||||||||||||||||||||||
843 | - | |||||||||||||||||||||||||
844 | /*! | - | ||||||||||||||||||||||||
845 | Returns \c true if the \a widget can be added to the \a layout; | - | ||||||||||||||||||||||||
846 | otherwise returns \c false. | - | ||||||||||||||||||||||||
847 | */ | - | ||||||||||||||||||||||||
848 | bool QLayoutPrivate::checkWidget(QWidget *widget) const | - | ||||||||||||||||||||||||
849 | { | - | ||||||||||||||||||||||||
850 | Q_Q(const QLayout); | - | ||||||||||||||||||||||||
851 | if (!widget) {
| 0 | ||||||||||||||||||||||||
852 | qWarning("QLayout: Cannot add a null widget to %s/%s", q->metaObject()->className(), | - | ||||||||||||||||||||||||
853 | qPrintable(q->objectName())); | - | ||||||||||||||||||||||||
854 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
855 | } | - | ||||||||||||||||||||||||
856 | if (widget == q->parentWidget()) {
| 0 | ||||||||||||||||||||||||
857 | qWarning("QLayout: Cannot add parent widget %s/%s to its child layout %s/%s", | - | ||||||||||||||||||||||||
858 | widget->metaObject()->className(), qPrintable(widget->objectName()), | - | ||||||||||||||||||||||||
859 | q->metaObject()->className(), qPrintable(q->objectName())); | - | ||||||||||||||||||||||||
860 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
861 | } | - | ||||||||||||||||||||||||
862 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
863 | } | - | ||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||
865 | /*! | - | ||||||||||||||||||||||||
866 | Returns \c true if the \a otherLayout can be added to the \a layout; | - | ||||||||||||||||||||||||
867 | otherwise returns \c false. | - | ||||||||||||||||||||||||
868 | */ | - | ||||||||||||||||||||||||
869 | bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const | - | ||||||||||||||||||||||||
870 | { | - | ||||||||||||||||||||||||
871 | Q_Q(const QLayout); | - | ||||||||||||||||||||||||
872 | if (!otherLayout) {
| 0 | ||||||||||||||||||||||||
873 | qWarning("QLayout: Cannot add a null layout to %s/%s", q->metaObject()->className(), | - | ||||||||||||||||||||||||
874 | qPrintable(q->objectName())); | - | ||||||||||||||||||||||||
875 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
876 | } | - | ||||||||||||||||||||||||
877 | if (otherLayout == q) {
| 0 | ||||||||||||||||||||||||
878 | qWarning("QLayout: Cannot add layout %s/%s to itself", q->metaObject()->className(), | - | ||||||||||||||||||||||||
879 | qPrintable(q->objectName())); | - | ||||||||||||||||||||||||
880 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
881 | } | - | ||||||||||||||||||||||||
882 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
883 | } | - | ||||||||||||||||||||||||
884 | - | |||||||||||||||||||||||||
885 | /*! | - | ||||||||||||||||||||||||
886 | This function is called from \c addWidget() functions in | - | ||||||||||||||||||||||||
887 | subclasses to add \a w as a managed widget of a layout. | - | ||||||||||||||||||||||||
888 | - | |||||||||||||||||||||||||
889 | If \a w is already managed by a layout, this function will give a warning | - | ||||||||||||||||||||||||
890 | and remove \a w from that layout. This function must therefore be | - | ||||||||||||||||||||||||
891 | called before adding \a w to the layout's data structure. | - | ||||||||||||||||||||||||
892 | */ | - | ||||||||||||||||||||||||
893 | void QLayout::addChildWidget(QWidget *w) | - | ||||||||||||||||||||||||
894 | { | - | ||||||||||||||||||||||||
895 | QWidget *mw = parentWidget(); | - | ||||||||||||||||||||||||
896 | QWidget *pw = w->parentWidget(); | - | ||||||||||||||||||||||||
897 | - | |||||||||||||||||||||||||
898 | //Qt::WA_LaidOut is never reset. It only means that the widget at some point has | - | ||||||||||||||||||||||||
899 | //been in a layout. | - | ||||||||||||||||||||||||
900 | if (pw && w->testAttribute(Qt::WA_LaidOut)) {
| 0 | ||||||||||||||||||||||||
901 | QLayout *l = pw->layout(); | - | ||||||||||||||||||||||||
902 | if (l && removeWidgetRecursively(l, w)) {
| 0 | ||||||||||||||||||||||||
903 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
904 | if (layoutDebug())
| 0 | ||||||||||||||||||||||||
905 | qWarning("QLayout::addChildWidget: %s \"%s\" is already in a layout; moved to new layout", never executed: QMessageLogger(__FILE__, 905, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%s\" is already in a layout; moved to new layout", w->metaObject()->className(), w->objectName().toLocal8Bit().data()); | 0 | ||||||||||||||||||||||||
906 | w->metaObject()->className(), w->objectName().toLocal8Bit().data()); never executed: QMessageLogger(__FILE__, 905, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%s\" is already in a layout; moved to new layout", w->metaObject()->className(), w->objectName().toLocal8Bit().data()); | 0 | ||||||||||||||||||||||||
907 | #endif | - | ||||||||||||||||||||||||
908 | } never executed: end of block | 0 | ||||||||||||||||||||||||
909 | } never executed: end of block | 0 | ||||||||||||||||||||||||
910 | if (pw && mw && pw != mw) {
| 0 | ||||||||||||||||||||||||
911 | #ifdef QT_DEBUG | - | ||||||||||||||||||||||||
912 | if (layoutDebug())
| 0 | ||||||||||||||||||||||||
913 | qWarning("QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent", never executed: QMessageLogger(__FILE__, 913, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent", w->metaObject()->className(), w->objectName().toLocal8Bit().data()); | 0 | ||||||||||||||||||||||||
914 | w->metaObject()->className(), w->objectName().toLocal8Bit().data()); never executed: QMessageLogger(__FILE__, 913, __PRETTY_FUNCTION__).warning("QLayout::addChildWidget: %s \"%s\" in wrong parent; moved to correct parent", w->metaObject()->className(), w->objectName().toLocal8Bit().data()); | 0 | ||||||||||||||||||||||||
915 | #endif | - | ||||||||||||||||||||||||
916 | pw = 0; | - | ||||||||||||||||||||||||
917 | } never executed: end of block | 0 | ||||||||||||||||||||||||
918 | bool needShow = mw && mw->isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide));
| 0 | ||||||||||||||||||||||||
919 | if (!pw && mw)
| 0 | ||||||||||||||||||||||||
920 | w->setParent(mw); never executed: w->setParent(mw); | 0 | ||||||||||||||||||||||||
921 | w->setAttribute(Qt::WA_LaidOut); | - | ||||||||||||||||||||||||
922 | if (needShow)
| 0 | ||||||||||||||||||||||||
923 | QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); //show later never executed: QMetaObject::invokeMethod(w, "_q_showIfNotHidden", Qt::QueuedConnection); | 0 | ||||||||||||||||||||||||
924 | } never executed: end of block | 0 | ||||||||||||||||||||||||
925 | - | |||||||||||||||||||||||||
926 | - | |||||||||||||||||||||||||
927 | - | |||||||||||||||||||||||||
928 | - | |||||||||||||||||||||||||
929 | - | |||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | - | |||||||||||||||||||||||||
932 | - | |||||||||||||||||||||||||
933 | /*! | - | ||||||||||||||||||||||||
934 | Tells the geometry manager to place the menu bar \a widget at the | - | ||||||||||||||||||||||||
935 | top of parentWidget(), outside QWidget::contentsMargins(). All | - | ||||||||||||||||||||||||
936 | child widgets are placed below the bottom edge of the menu bar. | - | ||||||||||||||||||||||||
937 | */ | - | ||||||||||||||||||||||||
938 | void QLayout::setMenuBar(QWidget *widget) | - | ||||||||||||||||||||||||
939 | { | - | ||||||||||||||||||||||||
940 | Q_D(QLayout); | - | ||||||||||||||||||||||||
941 | - | |||||||||||||||||||||||||
942 | #ifdef Q_OS_WINCE_WM | - | ||||||||||||||||||||||||
943 | if (widget && widget->size().height() > 0) | - | ||||||||||||||||||||||||
944 | #else | - | ||||||||||||||||||||||||
945 | if (widget)
| 0 | ||||||||||||||||||||||||
946 | #endif | - | ||||||||||||||||||||||||
947 | addChildWidget(widget); never executed: addChildWidget(widget); | 0 | ||||||||||||||||||||||||
948 | d->menubar = widget; | - | ||||||||||||||||||||||||
949 | } never executed: end of block | 0 | ||||||||||||||||||||||||
950 | - | |||||||||||||||||||||||||
951 | /*! | - | ||||||||||||||||||||||||
952 | Returns the menu bar set for this layout, or 0 if no menu bar is | - | ||||||||||||||||||||||||
953 | set. | - | ||||||||||||||||||||||||
954 | */ | - | ||||||||||||||||||||||||
955 | - | |||||||||||||||||||||||||
956 | QWidget *QLayout::menuBar() const | - | ||||||||||||||||||||||||
957 | { | - | ||||||||||||||||||||||||
958 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
959 | return d->menubar; never executed: return d->menubar; | 0 | ||||||||||||||||||||||||
960 | } | - | ||||||||||||||||||||||||
961 | - | |||||||||||||||||||||||||
962 | - | |||||||||||||||||||||||||
963 | /*! | - | ||||||||||||||||||||||||
964 | Returns the minimum size of this layout. This is the smallest | - | ||||||||||||||||||||||||
965 | size that the layout can have while still respecting the | - | ||||||||||||||||||||||||
966 | specifications. | - | ||||||||||||||||||||||||
967 | - | |||||||||||||||||||||||||
968 | The returned value doesn't include the space required by | - | ||||||||||||||||||||||||
969 | QWidget::setContentsMargins() or menuBar(). | - | ||||||||||||||||||||||||
970 | - | |||||||||||||||||||||||||
971 | The default implementation allows unlimited resizing. | - | ||||||||||||||||||||||||
972 | */ | - | ||||||||||||||||||||||||
973 | QSize QLayout::minimumSize() const | - | ||||||||||||||||||||||||
974 | { | - | ||||||||||||||||||||||||
975 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||||||||
976 | } | - | ||||||||||||||||||||||||
977 | - | |||||||||||||||||||||||||
978 | /*! | - | ||||||||||||||||||||||||
979 | Returns the maximum size of this layout. This is the largest size | - | ||||||||||||||||||||||||
980 | that the layout can have while still respecting the | - | ||||||||||||||||||||||||
981 | specifications. | - | ||||||||||||||||||||||||
982 | - | |||||||||||||||||||||||||
983 | The returned value doesn't include the space required by | - | ||||||||||||||||||||||||
984 | QWidget::setContentsMargins() or menuBar(). | - | ||||||||||||||||||||||||
985 | - | |||||||||||||||||||||||||
986 | The default implementation allows unlimited resizing. | - | ||||||||||||||||||||||||
987 | */ | - | ||||||||||||||||||||||||
988 | QSize QLayout::maximumSize() const | - | ||||||||||||||||||||||||
989 | { | - | ||||||||||||||||||||||||
990 | return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX); never executed: return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX); | 0 | ||||||||||||||||||||||||
991 | } | - | ||||||||||||||||||||||||
992 | - | |||||||||||||||||||||||||
993 | /*! | - | ||||||||||||||||||||||||
994 | Returns whether this layout can make use of more space than | - | ||||||||||||||||||||||||
995 | sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that | - | ||||||||||||||||||||||||
996 | it wants to grow in only one dimension, whereas Qt::Vertical | | - | ||||||||||||||||||||||||
997 | Qt::Horizontal means that it wants to grow in both dimensions. | - | ||||||||||||||||||||||||
998 | - | |||||||||||||||||||||||||
999 | The default implementation returns Qt::Horizontal | Qt::Vertical. | - | ||||||||||||||||||||||||
1000 | Subclasses reimplement it to return a meaningful value based on | - | ||||||||||||||||||||||||
1001 | their child widgets's \l{QSizePolicy}{size policies}. | - | ||||||||||||||||||||||||
1002 | - | |||||||||||||||||||||||||
1003 | \sa sizeHint() | - | ||||||||||||||||||||||||
1004 | */ | - | ||||||||||||||||||||||||
1005 | Qt::Orientations QLayout::expandingDirections() const | - | ||||||||||||||||||||||||
1006 | { | - | ||||||||||||||||||||||||
1007 | return Qt::Horizontal | Qt::Vertical; never executed: return Qt::Horizontal | Qt::Vertical; | 0 | ||||||||||||||||||||||||
1008 | } | - | ||||||||||||||||||||||||
1009 | - | |||||||||||||||||||||||||
1010 | void QLayout::activateRecursiveHelper(QLayoutItem *item) | - | ||||||||||||||||||||||||
1011 | { | - | ||||||||||||||||||||||||
1012 | item->invalidate(); | - | ||||||||||||||||||||||||
1013 | QLayout *layout = item->layout(); | - | ||||||||||||||||||||||||
1014 | if (layout) {
| 0 | ||||||||||||||||||||||||
1015 | QLayoutItem *child; | - | ||||||||||||||||||||||||
1016 | int i=0; | - | ||||||||||||||||||||||||
1017 | while ((child = layout->itemAt(i++)))
| 0 | ||||||||||||||||||||||||
1018 | activateRecursiveHelper(child); never executed: activateRecursiveHelper(child); | 0 | ||||||||||||||||||||||||
1019 | layout->d_func()->activated = true; | - | ||||||||||||||||||||||||
1020 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1021 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1022 | - | |||||||||||||||||||||||||
1023 | /*! | - | ||||||||||||||||||||||||
1024 | Updates the layout for parentWidget(). | - | ||||||||||||||||||||||||
1025 | - | |||||||||||||||||||||||||
1026 | You should generally not need to call this because it is | - | ||||||||||||||||||||||||
1027 | automatically called at the most appropriate times. | - | ||||||||||||||||||||||||
1028 | - | |||||||||||||||||||||||||
1029 | \sa activate(), invalidate() | - | ||||||||||||||||||||||||
1030 | */ | - | ||||||||||||||||||||||||
1031 | - | |||||||||||||||||||||||||
1032 | void QLayout::update() | - | ||||||||||||||||||||||||
1033 | { | - | ||||||||||||||||||||||||
1034 | QLayout *layout = this; | - | ||||||||||||||||||||||||
1035 | while (layout && layout->d_func()->activated) {
| 0 | ||||||||||||||||||||||||
1036 | layout->d_func()->activated = false; | - | ||||||||||||||||||||||||
1037 | if (layout->d_func()->topLevel) {
| 0 | ||||||||||||||||||||||||
1038 | Q_ASSERT(layout->parent()->isWidgetType()); | - | ||||||||||||||||||||||||
1039 | QWidget *mw = static_cast<QWidget*>(layout->parent()); | - | ||||||||||||||||||||||||
1040 | QApplication::postEvent(mw, new QEvent(QEvent::LayoutRequest)); | - | ||||||||||||||||||||||||
1041 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1042 | } | - | ||||||||||||||||||||||||
1043 | layout = static_cast<QLayout*>(layout->parent()); | - | ||||||||||||||||||||||||
1044 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1045 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1046 | - | |||||||||||||||||||||||||
1047 | /*! | - | ||||||||||||||||||||||||
1048 | Redoes the layout for parentWidget() if necessary. | - | ||||||||||||||||||||||||
1049 | - | |||||||||||||||||||||||||
1050 | You should generally not need to call this because it is | - | ||||||||||||||||||||||||
1051 | automatically called at the most appropriate times. It returns | - | ||||||||||||||||||||||||
1052 | true if the layout was redone. | - | ||||||||||||||||||||||||
1053 | - | |||||||||||||||||||||||||
1054 | \sa update(), QWidget::updateGeometry() | - | ||||||||||||||||||||||||
1055 | */ | - | ||||||||||||||||||||||||
1056 | bool QLayout::activate() | - | ||||||||||||||||||||||||
1057 | { | - | ||||||||||||||||||||||||
1058 | Q_D(QLayout); | - | ||||||||||||||||||||||||
1059 | if (!d->enabled || !parent())
| 0 | ||||||||||||||||||||||||
1060 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1061 | if (!d->topLevel)
| 0 | ||||||||||||||||||||||||
1062 | return static_cast<QLayout*>(parent())->activate(); never executed: return static_cast<QLayout*>(parent())->activate(); | 0 | ||||||||||||||||||||||||
1063 | if (d->activated)
| 0 | ||||||||||||||||||||||||
1064 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1065 | QWidget *mw = static_cast<QWidget*>(parent()); | - | ||||||||||||||||||||||||
1066 | if (mw == 0) {
| 0 | ||||||||||||||||||||||||
1067 | qWarning("QLayout::activate: %s \"%s\" does not have a main widget", | - | ||||||||||||||||||||||||
1068 | QObject::metaObject()->className(), QObject::objectName().toLocal8Bit().data()); | - | ||||||||||||||||||||||||
1069 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1070 | } | - | ||||||||||||||||||||||||
1071 | activateRecursiveHelper(this); | - | ||||||||||||||||||||||||
1072 | - | |||||||||||||||||||||||||
1073 | QWidgetPrivate *md = mw->d_func(); | - | ||||||||||||||||||||||||
1074 | uint explMin = md->extra ? md->extra->explicitMinSize : 0;
| 0 | ||||||||||||||||||||||||
1075 | uint explMax = md->extra ? md->extra->explicitMaxSize : 0;
| 0 | ||||||||||||||||||||||||
1076 | - | |||||||||||||||||||||||||
1077 | switch (d->constraint) { | - | ||||||||||||||||||||||||
1078 | case SetFixedSize: never executed: case SetFixedSize: | 0 | ||||||||||||||||||||||||
1079 | // will trigger resize | - | ||||||||||||||||||||||||
1080 | mw->setFixedSize(totalSizeHint()); | - | ||||||||||||||||||||||||
1081 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1082 | case SetMinimumSize: never executed: case SetMinimumSize: | 0 | ||||||||||||||||||||||||
1083 | mw->setMinimumSize(totalMinimumSize()); | - | ||||||||||||||||||||||||
1084 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1085 | case SetMaximumSize: never executed: case SetMaximumSize: | 0 | ||||||||||||||||||||||||
1086 | mw->setMaximumSize(totalMaximumSize()); | - | ||||||||||||||||||||||||
1087 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1088 | case SetMinAndMaxSize: never executed: case SetMinAndMaxSize: | 0 | ||||||||||||||||||||||||
1089 | mw->setMinimumSize(totalMinimumSize()); | - | ||||||||||||||||||||||||
1090 | mw->setMaximumSize(totalMaximumSize()); | - | ||||||||||||||||||||||||
1091 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1092 | case SetDefaultConstraint: { never executed: case SetDefaultConstraint: | 0 | ||||||||||||||||||||||||
1093 | bool widthSet = explMin & Qt::Horizontal; | - | ||||||||||||||||||||||||
1094 | bool heightSet = explMin & Qt::Vertical; | - | ||||||||||||||||||||||||
1095 | if (mw->isWindow()) {
| 0 | ||||||||||||||||||||||||
1096 | QSize ms = totalMinimumSize(); | - | ||||||||||||||||||||||||
1097 | if (widthSet)
| 0 | ||||||||||||||||||||||||
1098 | ms.setWidth(mw->minimumSize().width()); never executed: ms.setWidth(mw->minimumSize().width()); | 0 | ||||||||||||||||||||||||
1099 | if (heightSet)
| 0 | ||||||||||||||||||||||||
1100 | ms.setHeight(mw->minimumSize().height()); never executed: ms.setHeight(mw->minimumSize().height()); | 0 | ||||||||||||||||||||||||
1101 | mw->setMinimumSize(ms); | - | ||||||||||||||||||||||||
1102 | } else if (!widthSet || !heightSet) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1103 | QSize ms = mw->minimumSize(); | - | ||||||||||||||||||||||||
1104 | if (!widthSet)
| 0 | ||||||||||||||||||||||||
1105 | ms.setWidth(0); never executed: ms.setWidth(0); | 0 | ||||||||||||||||||||||||
1106 | if (!heightSet)
| 0 | ||||||||||||||||||||||||
1107 | ms.setHeight(0); never executed: ms.setHeight(0); | 0 | ||||||||||||||||||||||||
1108 | mw->setMinimumSize(ms); | - | ||||||||||||||||||||||||
1109 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1110 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1111 | } | - | ||||||||||||||||||||||||
1112 | case SetNoConstraint: never executed: case SetNoConstraint: | 0 | ||||||||||||||||||||||||
1113 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1114 | } | - | ||||||||||||||||||||||||
1115 | - | |||||||||||||||||||||||||
1116 | d->doResize(mw->size()); | - | ||||||||||||||||||||||||
1117 | - | |||||||||||||||||||||||||
1118 | if (md->extra) {
| 0 | ||||||||||||||||||||||||
1119 | md->extra->explicitMinSize = explMin; | - | ||||||||||||||||||||||||
1120 | md->extra->explicitMaxSize = explMax; | - | ||||||||||||||||||||||||
1121 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1122 | // ideally only if sizeHint() or sizePolicy() has changed | - | ||||||||||||||||||||||||
1123 | mw->updateGeometry(); | - | ||||||||||||||||||||||||
1124 | return true; never executed: return true; | 0 | ||||||||||||||||||||||||
1125 | } | - | ||||||||||||||||||||||||
1126 | - | |||||||||||||||||||||||||
1127 | /*! | - | ||||||||||||||||||||||||
1128 | \since 5.2 | - | ||||||||||||||||||||||||
1129 | - | |||||||||||||||||||||||||
1130 | Searches for widget \a from and replaces it with widget \a to if found. | - | ||||||||||||||||||||||||
1131 | Returns the layout item that contains the widget \a from on success. | - | ||||||||||||||||||||||||
1132 | Otherwise \c 0 is returned. If \a options contains \c Qt::FindChildrenRecursively | - | ||||||||||||||||||||||||
1133 | (the default), sub-layouts are searched for doing the replacement. | - | ||||||||||||||||||||||||
1134 | Any other flag in \a options is ignored. | - | ||||||||||||||||||||||||
1135 | - | |||||||||||||||||||||||||
1136 | Notice that the returned item therefore might not belong to this layout, | - | ||||||||||||||||||||||||
1137 | but to a sub-layout. | - | ||||||||||||||||||||||||
1138 | - | |||||||||||||||||||||||||
1139 | The returned layout item is no longer owned by the layout and should be | - | ||||||||||||||||||||||||
1140 | either deleted or inserted to another layout. The widget \a from is no | - | ||||||||||||||||||||||||
1141 | longer managed by the layout and may need to be deleted or hidden. The | - | ||||||||||||||||||||||||
1142 | parent of widget \a from is left unchanged. | - | ||||||||||||||||||||||||
1143 | - | |||||||||||||||||||||||||
1144 | This function works for the built-in Qt layouts, but might not work for | - | ||||||||||||||||||||||||
1145 | custom layouts. | - | ||||||||||||||||||||||||
1146 | - | |||||||||||||||||||||||||
1147 | \sa indexOf() | - | ||||||||||||||||||||||||
1148 | */ | - | ||||||||||||||||||||||||
1149 | - | |||||||||||||||||||||||||
1150 | QLayoutItem *QLayout::replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options) | - | ||||||||||||||||||||||||
1151 | { | - | ||||||||||||||||||||||||
1152 | Q_D(QLayout); | - | ||||||||||||||||||||||||
1153 | if (!from || !to)
| 0 | ||||||||||||||||||||||||
1154 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1155 | - | |||||||||||||||||||||||||
1156 | int index = -1; | - | ||||||||||||||||||||||||
1157 | QLayoutItem *item = 0; | - | ||||||||||||||||||||||||
1158 | for (int u = 0; u < count(); ++u) {
| 0 | ||||||||||||||||||||||||
1159 | item = itemAt(u); | - | ||||||||||||||||||||||||
1160 | if (!item)
| 0 | ||||||||||||||||||||||||
1161 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||
1162 | - | |||||||||||||||||||||||||
1163 | if (item->widget() == from) {
| 0 | ||||||||||||||||||||||||
1164 | index = u; | - | ||||||||||||||||||||||||
1165 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1166 | } | - | ||||||||||||||||||||||||
1167 | - | |||||||||||||||||||||||||
1168 | if (item->layout() && (options & Qt::FindChildrenRecursively)) {
| 0 | ||||||||||||||||||||||||
1169 | QLayoutItem *r = item->layout()->replaceWidget(from, to, options); | - | ||||||||||||||||||||||||
1170 | if (r)
| 0 | ||||||||||||||||||||||||
1171 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
1172 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1173 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1174 | if (index == -1)
| 0 | ||||||||||||||||||||||||
1175 | return 0; never executed: return 0; | 0 | ||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||
1177 | addChildWidget(to); | - | ||||||||||||||||||||||||
1178 | QLayoutItem *newitem = new QWidgetItem(to); | - | ||||||||||||||||||||||||
1179 | newitem->setAlignment(item->alignment()); | - | ||||||||||||||||||||||||
1180 | QLayoutItem *r = d->replaceAt(index, newitem); | - | ||||||||||||||||||||||||
1181 | if (!r)
| 0 | ||||||||||||||||||||||||
1182 | delete newitem; never executed: delete newitem; | 0 | ||||||||||||||||||||||||
1183 | return r; never executed: return r; | 0 | ||||||||||||||||||||||||
1184 | } | - | ||||||||||||||||||||||||
1185 | - | |||||||||||||||||||||||||
1186 | /*! | - | ||||||||||||||||||||||||
1187 | \fn QLayoutItem *QLayout::itemAt(int index) const | - | ||||||||||||||||||||||||
1188 | - | |||||||||||||||||||||||||
1189 | Must be implemented in subclasses to return the layout item at \a | - | ||||||||||||||||||||||||
1190 | index. If there is no such item, the function must return 0. | - | ||||||||||||||||||||||||
1191 | Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered. | - | ||||||||||||||||||||||||
1192 | - | |||||||||||||||||||||||||
1193 | This function can be used to iterate over a layout. The following | - | ||||||||||||||||||||||||
1194 | code will draw a rectangle for each layout item in the layout structure of the widget. | - | ||||||||||||||||||||||||
1195 | - | |||||||||||||||||||||||||
1196 | \snippet code/src_gui_kernel_qlayout.cpp 0 | - | ||||||||||||||||||||||||
1197 | - | |||||||||||||||||||||||||
1198 | \sa count(), takeAt() | - | ||||||||||||||||||||||||
1199 | */ | - | ||||||||||||||||||||||||
1200 | - | |||||||||||||||||||||||||
1201 | /*! | - | ||||||||||||||||||||||||
1202 | \fn QLayoutItem *QLayout::takeAt(int index) | - | ||||||||||||||||||||||||
1203 | - | |||||||||||||||||||||||||
1204 | Must be implemented in subclasses to remove the layout item at \a | - | ||||||||||||||||||||||||
1205 | index from the layout, and return the item. If there is no such | - | ||||||||||||||||||||||||
1206 | item, the function must do nothing and return 0. Items are numbered | - | ||||||||||||||||||||||||
1207 | consecutively from 0. If an item is removed, other items will be | - | ||||||||||||||||||||||||
1208 | renumbered. | - | ||||||||||||||||||||||||
1209 | - | |||||||||||||||||||||||||
1210 | The following code fragment shows a safe way to remove all items | - | ||||||||||||||||||||||||
1211 | from a layout: | - | ||||||||||||||||||||||||
1212 | - | |||||||||||||||||||||||||
1213 | \snippet code/src_gui_kernel_qlayout.cpp 1 | - | ||||||||||||||||||||||||
1214 | - | |||||||||||||||||||||||||
1215 | \sa itemAt(), count() | - | ||||||||||||||||||||||||
1216 | */ | - | ||||||||||||||||||||||||
1217 | - | |||||||||||||||||||||||||
1218 | /*! | - | ||||||||||||||||||||||||
1219 | \fn int *QLayout::count() const | - | ||||||||||||||||||||||||
1220 | - | |||||||||||||||||||||||||
1221 | Must be implemented in subclasses to return the number of items | - | ||||||||||||||||||||||||
1222 | in the layout. | - | ||||||||||||||||||||||||
1223 | - | |||||||||||||||||||||||||
1224 | \sa itemAt() | - | ||||||||||||||||||||||||
1225 | */ | - | ||||||||||||||||||||||||
1226 | - | |||||||||||||||||||||||||
1227 | /*! | - | ||||||||||||||||||||||||
1228 | Searches for widget \a widget in this layout (not including child | - | ||||||||||||||||||||||||
1229 | layouts). | - | ||||||||||||||||||||||||
1230 | - | |||||||||||||||||||||||||
1231 | Returns the index of \a widget, or -1 if \a widget is not found. | - | ||||||||||||||||||||||||
1232 | - | |||||||||||||||||||||||||
1233 | The default implementation iterates over all items using itemAt() | - | ||||||||||||||||||||||||
1234 | */ | - | ||||||||||||||||||||||||
1235 | int QLayout::indexOf(QWidget *widget) const | - | ||||||||||||||||||||||||
1236 | { | - | ||||||||||||||||||||||||
1237 | int i = 0; | - | ||||||||||||||||||||||||
1238 | QLayoutItem *item = itemAt(i); | - | ||||||||||||||||||||||||
1239 | while (item) {
| 0 | ||||||||||||||||||||||||
1240 | if (item->widget() == widget)
| 0 | ||||||||||||||||||||||||
1241 | return i; never executed: return i; | 0 | ||||||||||||||||||||||||
1242 | ++i; | - | ||||||||||||||||||||||||
1243 | item = itemAt(i); | - | ||||||||||||||||||||||||
1244 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1245 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
1246 | } | - | ||||||||||||||||||||||||
1247 | - | |||||||||||||||||||||||||
1248 | /*! | - | ||||||||||||||||||||||||
1249 | \enum QLayout::SizeConstraint | - | ||||||||||||||||||||||||
1250 | - | |||||||||||||||||||||||||
1251 | The possible values are: | - | ||||||||||||||||||||||||
1252 | - | |||||||||||||||||||||||||
1253 | \value SetDefaultConstraint The main widget's minimum size is set | - | ||||||||||||||||||||||||
1254 | to minimumSize(), unless the widget already has | - | ||||||||||||||||||||||||
1255 | a minimum size. | - | ||||||||||||||||||||||||
1256 | - | |||||||||||||||||||||||||
1257 | \value SetFixedSize The main widget's size is set to sizeHint(); it | - | ||||||||||||||||||||||||
1258 | cannot be resized at all. | - | ||||||||||||||||||||||||
1259 | \value SetMinimumSize The main widget's minimum size is set to | - | ||||||||||||||||||||||||
1260 | minimumSize(); it cannot be smaller. | - | ||||||||||||||||||||||||
1261 | - | |||||||||||||||||||||||||
1262 | \value SetMaximumSize The main widget's maximum size is set to | - | ||||||||||||||||||||||||
1263 | maximumSize(); it cannot be larger. | - | ||||||||||||||||||||||||
1264 | - | |||||||||||||||||||||||||
1265 | \value SetMinAndMaxSize The main widget's minimum size is set to | - | ||||||||||||||||||||||||
1266 | minimumSize() and its maximum size is set to | - | ||||||||||||||||||||||||
1267 | maximumSize(). | - | ||||||||||||||||||||||||
1268 | - | |||||||||||||||||||||||||
1269 | \value SetNoConstraint The widget is not constrained. | - | ||||||||||||||||||||||||
1270 | - | |||||||||||||||||||||||||
1271 | \sa setSizeConstraint() | - | ||||||||||||||||||||||||
1272 | */ | - | ||||||||||||||||||||||||
1273 | - | |||||||||||||||||||||||||
1274 | /*! | - | ||||||||||||||||||||||||
1275 | \property QLayout::sizeConstraint | - | ||||||||||||||||||||||||
1276 | \brief the resize mode of the layout | - | ||||||||||||||||||||||||
1277 | - | |||||||||||||||||||||||||
1278 | The default mode is \l {QLayout::SetDefaultConstraint} | - | ||||||||||||||||||||||||
1279 | {SetDefaultConstraint}. | - | ||||||||||||||||||||||||
1280 | */ | - | ||||||||||||||||||||||||
1281 | void QLayout::setSizeConstraint(SizeConstraint constraint) | - | ||||||||||||||||||||||||
1282 | { | - | ||||||||||||||||||||||||
1283 | Q_D(QLayout); | - | ||||||||||||||||||||||||
1284 | if (constraint == d->constraint)
| 0 | ||||||||||||||||||||||||
1285 | return; never executed: return; | 0 | ||||||||||||||||||||||||
1286 | - | |||||||||||||||||||||||||
1287 | d->constraint = constraint; | - | ||||||||||||||||||||||||
1288 | invalidate(); | - | ||||||||||||||||||||||||
1289 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1290 | - | |||||||||||||||||||||||||
1291 | QLayout::SizeConstraint QLayout::sizeConstraint() const | - | ||||||||||||||||||||||||
1292 | { | - | ||||||||||||||||||||||||
1293 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
1294 | return d->constraint; never executed: return d->constraint; | 0 | ||||||||||||||||||||||||
1295 | } | - | ||||||||||||||||||||||||
1296 | - | |||||||||||||||||||||||||
1297 | /*! | - | ||||||||||||||||||||||||
1298 | Returns the rectangle that should be covered when the geometry of | - | ||||||||||||||||||||||||
1299 | this layout is set to \a r, provided that this layout supports | - | ||||||||||||||||||||||||
1300 | setAlignment(). | - | ||||||||||||||||||||||||
1301 | - | |||||||||||||||||||||||||
1302 | The result is derived from sizeHint() and expanding(). It is never | - | ||||||||||||||||||||||||
1303 | larger than \a r. | - | ||||||||||||||||||||||||
1304 | */ | - | ||||||||||||||||||||||||
1305 | QRect QLayout::alignmentRect(const QRect &r) const | - | ||||||||||||||||||||||||
1306 | { | - | ||||||||||||||||||||||||
1307 | QSize s = sizeHint(); | - | ||||||||||||||||||||||||
1308 | Qt::Alignment a = alignment(); | - | ||||||||||||||||||||||||
1309 | - | |||||||||||||||||||||||||
1310 | /* | - | ||||||||||||||||||||||||
1311 | This is a hack to obtain the real maximum size, not | - | ||||||||||||||||||||||||
1312 | QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX), the value consistently | - | ||||||||||||||||||||||||
1313 | returned by QLayoutItems that have an alignment. | - | ||||||||||||||||||||||||
1314 | */ | - | ||||||||||||||||||||||||
1315 | QLayout *that = const_cast<QLayout *>(this); | - | ||||||||||||||||||||||||
1316 | that->setAlignment(0); | - | ||||||||||||||||||||||||
1317 | QSize ms = that->maximumSize(); | - | ||||||||||||||||||||||||
1318 | that->setAlignment(a); | - | ||||||||||||||||||||||||
1319 | - | |||||||||||||||||||||||||
1320 | if ((expandingDirections() & Qt::Horizontal) ||
| 0 | ||||||||||||||||||||||||
1321 | !(a & Qt::AlignHorizontal_Mask)) {
| 0 | ||||||||||||||||||||||||
1322 | s.setWidth(qMin(r.width(), ms.width())); | - | ||||||||||||||||||||||||
1323 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1324 | if ((expandingDirections() & Qt::Vertical) ||
| 0 | ||||||||||||||||||||||||
1325 | !(a & Qt::AlignVertical_Mask)) {
| 0 | ||||||||||||||||||||||||
1326 | s.setHeight(qMin(r.height(), ms.height())); | - | ||||||||||||||||||||||||
1327 | } else if (hasHeightForWidth()) { never executed: end of block
| 0 | ||||||||||||||||||||||||
1328 | int hfw = heightForWidth(s.width()); | - | ||||||||||||||||||||||||
1329 | if (hfw < s.height())
| 0 | ||||||||||||||||||||||||
1330 | s.setHeight(qMin(hfw, ms.height())); never executed: s.setHeight(qMin(hfw, ms.height())); | 0 | ||||||||||||||||||||||||
1331 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1332 | - | |||||||||||||||||||||||||
1333 | s = s.boundedTo(r.size()); | - | ||||||||||||||||||||||||
1334 | int x = r.x(); | - | ||||||||||||||||||||||||
1335 | int y = r.y(); | - | ||||||||||||||||||||||||
1336 | - | |||||||||||||||||||||||||
1337 | if (a & Qt::AlignBottom)
| 0 | ||||||||||||||||||||||||
1338 | y += (r.height() - s.height()); never executed: y += (r.height() - s.height()); | 0 | ||||||||||||||||||||||||
1339 | else if (!(a & Qt::AlignTop))
| 0 | ||||||||||||||||||||||||
1340 | y += (r.height() - s.height()) / 2; never executed: y += (r.height() - s.height()) / 2; | 0 | ||||||||||||||||||||||||
1341 | - | |||||||||||||||||||||||||
1342 | QWidget *parent = parentWidget(); | - | ||||||||||||||||||||||||
1343 | a = QStyle::visualAlignment(parent ? parent->layoutDirection() : QApplication::layoutDirection(), a); | - | ||||||||||||||||||||||||
1344 | if (a & Qt::AlignRight)
| 0 | ||||||||||||||||||||||||
1345 | x += (r.width() - s.width()); never executed: x += (r.width() - s.width()); | 0 | ||||||||||||||||||||||||
1346 | else if (!(a & Qt::AlignLeft))
| 0 | ||||||||||||||||||||||||
1347 | x += (r.width() - s.width()) / 2; never executed: x += (r.width() - s.width()) / 2; | 0 | ||||||||||||||||||||||||
1348 | - | |||||||||||||||||||||||||
1349 | return QRect(x, y, s.width(), s.height()); never executed: return QRect(x, y, s.width(), s.height()); | 0 | ||||||||||||||||||||||||
1350 | } | - | ||||||||||||||||||||||||
1351 | - | |||||||||||||||||||||||||
1352 | /*! | - | ||||||||||||||||||||||||
1353 | Removes the widget \a widget from the layout. After this call, it | - | ||||||||||||||||||||||||
1354 | is the caller's responsibility to give the widget a reasonable | - | ||||||||||||||||||||||||
1355 | geometry or to put the widget back into a layout. | - | ||||||||||||||||||||||||
1356 | - | |||||||||||||||||||||||||
1357 | \b{Note:} The ownership of \a widget remains the same as | - | ||||||||||||||||||||||||
1358 | when it was added. | - | ||||||||||||||||||||||||
1359 | - | |||||||||||||||||||||||||
1360 | \sa removeItem(), QWidget::setGeometry(), addWidget() | - | ||||||||||||||||||||||||
1361 | */ | - | ||||||||||||||||||||||||
1362 | void QLayout::removeWidget(QWidget *widget) | - | ||||||||||||||||||||||||
1363 | { | - | ||||||||||||||||||||||||
1364 | int i = 0; | - | ||||||||||||||||||||||||
1365 | QLayoutItem *child; | - | ||||||||||||||||||||||||
1366 | while ((child = itemAt(i))) {
| 0 | ||||||||||||||||||||||||
1367 | if (child->widget() == widget) {
| 0 | ||||||||||||||||||||||||
1368 | delete takeAt(i); | - | ||||||||||||||||||||||||
1369 | invalidate(); | - | ||||||||||||||||||||||||
1370 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1371 | ++i; | - | ||||||||||||||||||||||||
1372 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1373 | } | - | ||||||||||||||||||||||||
1374 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1375 | - | |||||||||||||||||||||||||
1376 | /*! | - | ||||||||||||||||||||||||
1377 | Removes the layout item \a item from the layout. It is the | - | ||||||||||||||||||||||||
1378 | caller's responsibility to delete the item. | - | ||||||||||||||||||||||||
1379 | - | |||||||||||||||||||||||||
1380 | Notice that \a item can be a layout (since QLayout inherits | - | ||||||||||||||||||||||||
1381 | QLayoutItem). | - | ||||||||||||||||||||||||
1382 | - | |||||||||||||||||||||||||
1383 | \sa removeWidget(), addItem() | - | ||||||||||||||||||||||||
1384 | */ | - | ||||||||||||||||||||||||
1385 | void QLayout::removeItem(QLayoutItem *item) | - | ||||||||||||||||||||||||
1386 | { | - | ||||||||||||||||||||||||
1387 | int i = 0; | - | ||||||||||||||||||||||||
1388 | QLayoutItem *child; | - | ||||||||||||||||||||||||
1389 | while ((child = itemAt(i))) {
| 0 | ||||||||||||||||||||||||
1390 | if (child == item) {
| 0 | ||||||||||||||||||||||||
1391 | takeAt(i); | - | ||||||||||||||||||||||||
1392 | invalidate(); | - | ||||||||||||||||||||||||
1393 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1394 | ++i; | - | ||||||||||||||||||||||||
1395 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1396 | } | - | ||||||||||||||||||||||||
1397 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1398 | - | |||||||||||||||||||||||||
1399 | /*! | - | ||||||||||||||||||||||||
1400 | Enables this layout if \a enable is true, otherwise disables it. | - | ||||||||||||||||||||||||
1401 | - | |||||||||||||||||||||||||
1402 | An enabled layout adjusts dynamically to changes; a disabled | - | ||||||||||||||||||||||||
1403 | layout acts as if it did not exist. | - | ||||||||||||||||||||||||
1404 | - | |||||||||||||||||||||||||
1405 | By default all layouts are enabled. | - | ||||||||||||||||||||||||
1406 | - | |||||||||||||||||||||||||
1407 | \sa isEnabled() | - | ||||||||||||||||||||||||
1408 | */ | - | ||||||||||||||||||||||||
1409 | void QLayout::setEnabled(bool enable) | - | ||||||||||||||||||||||||
1410 | { | - | ||||||||||||||||||||||||
1411 | Q_D(QLayout); | - | ||||||||||||||||||||||||
1412 | d->enabled = enable; | - | ||||||||||||||||||||||||
1413 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1414 | - | |||||||||||||||||||||||||
1415 | /*! | - | ||||||||||||||||||||||||
1416 | Returns \c true if the layout is enabled; otherwise returns \c false. | - | ||||||||||||||||||||||||
1417 | - | |||||||||||||||||||||||||
1418 | \sa setEnabled() | - | ||||||||||||||||||||||||
1419 | */ | - | ||||||||||||||||||||||||
1420 | bool QLayout::isEnabled() const | - | ||||||||||||||||||||||||
1421 | { | - | ||||||||||||||||||||||||
1422 | Q_D(const QLayout); | - | ||||||||||||||||||||||||
1423 | return d->enabled; never executed: return d->enabled; | 0 | ||||||||||||||||||||||||
1424 | } | - | ||||||||||||||||||||||||
1425 | - | |||||||||||||||||||||||||
1426 | /*! | - | ||||||||||||||||||||||||
1427 | Returns a size that satisfies all size constraints on \a widget, | - | ||||||||||||||||||||||||
1428 | including heightForWidth() and that is as close as possible to \a | - | ||||||||||||||||||||||||
1429 | size. | - | ||||||||||||||||||||||||
1430 | */ | - | ||||||||||||||||||||||||
1431 | - | |||||||||||||||||||||||||
1432 | QSize QLayout::closestAcceptableSize(const QWidget *widget, const QSize &size) | - | ||||||||||||||||||||||||
1433 | { | - | ||||||||||||||||||||||||
1434 | QSize result = size.boundedTo(qSmartMaxSize(widget)); | - | ||||||||||||||||||||||||
1435 | result = result.expandedTo(qSmartMinSize(widget)); | - | ||||||||||||||||||||||||
1436 | QLayout *l = widget->layout(); | - | ||||||||||||||||||||||||
1437 | if (l && l->hasHeightForWidth() && result.height() < l->minimumHeightForWidth(result.width()) ) {
| 0 | ||||||||||||||||||||||||
1438 | QSize current = widget->size(); | - | ||||||||||||||||||||||||
1439 | int currentHfw = l->minimumHeightForWidth(current.width()); | - | ||||||||||||||||||||||||
1440 | int newHfw = l->minimumHeightForWidth(result.width()); | - | ||||||||||||||||||||||||
1441 | if (current.height() < currentHfw || currentHfw == newHfw) {
| 0 | ||||||||||||||||||||||||
1442 | //handle the constant hfw case and the vertical-only case, as well as the | - | ||||||||||||||||||||||||
1443 | // current-size-is-not-correct case | - | ||||||||||||||||||||||||
1444 | result.setHeight(newHfw); | - | ||||||||||||||||||||||||
1445 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1446 | // binary search; assume hfw is decreasing ### | - | ||||||||||||||||||||||||
1447 | - | |||||||||||||||||||||||||
1448 | int maxw = qMax(widget->width(),result.width()); | - | ||||||||||||||||||||||||
1449 | int maxh = qMax(widget->height(), result.height()); | - | ||||||||||||||||||||||||
1450 | int minw = qMin(widget->width(),result.width()); | - | ||||||||||||||||||||||||
1451 | int minh = qMin(widget->height(), result.height()); | - | ||||||||||||||||||||||||
1452 | - | |||||||||||||||||||||||||
1453 | int minhfw = l->minimumHeightForWidth(minw); | - | ||||||||||||||||||||||||
1454 | int maxhfw = l->minimumHeightForWidth(maxw); | - | ||||||||||||||||||||||||
1455 | while (minw < maxw) {
| 0 | ||||||||||||||||||||||||
1456 | if (minhfw > maxh) { //assume decreasing
| 0 | ||||||||||||||||||||||||
1457 | minw = maxw - (maxw-minw)/2; | - | ||||||||||||||||||||||||
1458 | minhfw = l->minimumHeightForWidth(minw); | - | ||||||||||||||||||||||||
1459 | } else if (maxhfw < minh ) { //assume decreasing never executed: end of block
| 0 | ||||||||||||||||||||||||
1460 | maxw = minw + (maxw-minw)/2; | - | ||||||||||||||||||||||||
1461 | maxhfw = l->minimumHeightForWidth(maxw); | - | ||||||||||||||||||||||||
1462 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
1463 | break; never executed: break; | 0 | ||||||||||||||||||||||||
1464 | } | - | ||||||||||||||||||||||||
1465 | } | - | ||||||||||||||||||||||||
1466 | result = result.expandedTo(QSize(minw, minhfw)); | - | ||||||||||||||||||||||||
1467 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1468 | } | - | ||||||||||||||||||||||||
1469 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
1470 | } | - | ||||||||||||||||||||||||
1471 | - | |||||||||||||||||||||||||
1472 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
1473 | - | |||||||||||||||||||||||||
1474 | #include "moc_qlayout.cpp" | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |