Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qlayoutitem.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 "qevent.h" | - | ||||||||||||||||||
41 | #include "qstyle.h" | - | ||||||||||||||||||
42 | #include "qvariant.h" | - | ||||||||||||||||||
43 | #include "qwidget_p.h" | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | inline static QRect fromLayoutItemRect(QWidgetPrivate *priv, const QRect &rect) | - | ||||||||||||||||||
48 | { | - | ||||||||||||||||||
49 | return rect.adjusted(priv->leftLayoutItemMargin, priv->topLayoutItemMargin, never executed: return rect.adjusted(priv->leftLayoutItemMargin, priv->topLayoutItemMargin, -priv->rightLayoutItemMargin, -priv->bottomLayoutItemMargin); | 0 | ||||||||||||||||||
50 | -priv->rightLayoutItemMargin, -priv->bottomLayoutItemMargin); never executed: return rect.adjusted(priv->leftLayoutItemMargin, priv->topLayoutItemMargin, -priv->rightLayoutItemMargin, -priv->bottomLayoutItemMargin); | 0 | ||||||||||||||||||
51 | } | - | ||||||||||||||||||
52 | - | |||||||||||||||||||
53 | inline static QSize fromLayoutItemSize(QWidgetPrivate *priv, const QSize &size) | - | ||||||||||||||||||
54 | { | - | ||||||||||||||||||
55 | return fromLayoutItemRect(priv, QRect(QPoint(0, 0), size)).size(); never executed: return fromLayoutItemRect(priv, QRect(QPoint(0, 0), size)).size(); | 0 | ||||||||||||||||||
56 | } | - | ||||||||||||||||||
57 | - | |||||||||||||||||||
58 | inline static QRect toLayoutItemRect(QWidgetPrivate *priv, const QRect &rect) | - | ||||||||||||||||||
59 | { | - | ||||||||||||||||||
60 | return rect.adjusted(-priv->leftLayoutItemMargin, -priv->topLayoutItemMargin, never executed: return rect.adjusted(-priv->leftLayoutItemMargin, -priv->topLayoutItemMargin, priv->rightLayoutItemMargin, priv->bottomLayoutItemMargin); | 0 | ||||||||||||||||||
61 | priv->rightLayoutItemMargin, priv->bottomLayoutItemMargin); never executed: return rect.adjusted(-priv->leftLayoutItemMargin, -priv->topLayoutItemMargin, priv->rightLayoutItemMargin, priv->bottomLayoutItemMargin); | 0 | ||||||||||||||||||
62 | } | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | inline static QSize toLayoutItemSize(QWidgetPrivate *priv, const QSize &size) | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | return toLayoutItemRect(priv, QRect(QPoint(0, 0), size)).size(); never executed: return toLayoutItemRect(priv, QRect(QPoint(0, 0), size)).size(); | 0 | ||||||||||||||||||
67 | } | - | ||||||||||||||||||
68 | - | |||||||||||||||||||
69 | /*! | - | ||||||||||||||||||
70 | \class QLayoutItem | - | ||||||||||||||||||
71 | \brief The QLayoutItem class provides an abstract item that a | - | ||||||||||||||||||
72 | QLayout manipulates. | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | \ingroup geomanagement | - | ||||||||||||||||||
75 | \inmodule QtWidgets | - | ||||||||||||||||||
76 | - | |||||||||||||||||||
77 | This is used by custom layouts. | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | Pure virtual functions are provided to return information about | - | ||||||||||||||||||
80 | the layout, including, sizeHint(), minimumSize(), maximumSize() | - | ||||||||||||||||||
81 | and expanding(). | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | The layout's geometry can be set and retrieved with setGeometry() | - | ||||||||||||||||||
84 | and geometry(), and its alignment with setAlignment() and | - | ||||||||||||||||||
85 | alignment(). | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | isEmpty() returns whether the layout item is empty. If the | - | ||||||||||||||||||
88 | concrete item is a QWidget, it can be retrieved using widget(). | - | ||||||||||||||||||
89 | Similarly for layout() and spacerItem(). | - | ||||||||||||||||||
90 | - | |||||||||||||||||||
91 | Some layouts have width and height interdependencies. These can | - | ||||||||||||||||||
92 | be expressed using hasHeightForWidth(), heightForWidth(), and | - | ||||||||||||||||||
93 | minimumHeightForWidth(). For more explanation see the \e{Qt | - | ||||||||||||||||||
94 | Quarterly} article | - | ||||||||||||||||||
95 | \l{http://doc.qt.io/archives/qq/qq04-height-for-width.html}{Trading | - | ||||||||||||||||||
96 | Height for Width}. | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | \sa QLayout | - | ||||||||||||||||||
99 | */ | - | ||||||||||||||||||
100 | - | |||||||||||||||||||
101 | /*! | - | ||||||||||||||||||
102 | \class QSpacerItem | - | ||||||||||||||||||
103 | \ingroup geomanagement | - | ||||||||||||||||||
104 | \brief The QSpacerItem class provides blank space in a layout. | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | \inmodule QtWidgets | - | ||||||||||||||||||
107 | - | |||||||||||||||||||
108 | Normally, you don't need to use this class directly. Qt's | - | ||||||||||||||||||
109 | built-in layout managers provide the following functions for | - | ||||||||||||||||||
110 | manipulating empty space in layouts: | - | ||||||||||||||||||
111 | - | |||||||||||||||||||
112 | \table | - | ||||||||||||||||||
113 | \header \li Class | - | ||||||||||||||||||
114 | \li Functions | - | ||||||||||||||||||
115 | \row \li QHBoxLayout | - | ||||||||||||||||||
116 | \li \l{QBoxLayout::addSpacing()}{addSpacing()}, | - | ||||||||||||||||||
117 | \l{QBoxLayout::addStretch()}{addStretch()}, | - | ||||||||||||||||||
118 | \l{QBoxLayout::insertSpacing()}{insertSpacing()}, | - | ||||||||||||||||||
119 | \l{QBoxLayout::insertStretch()}{insertStretch()} | - | ||||||||||||||||||
120 | \row \li QGridLayout | - | ||||||||||||||||||
121 | \li \l{QGridLayout::setRowMinimumHeight()}{setRowMinimumHeight()}, | - | ||||||||||||||||||
122 | \l{QGridLayout::setRowStretch()}{setRowStretch()}, | - | ||||||||||||||||||
123 | \l{QGridLayout::setColumnMinimumWidth()}{setColumnMinimumWidth()}, | - | ||||||||||||||||||
124 | \l{QGridLayout::setColumnStretch()}{setColumnStretch()} | - | ||||||||||||||||||
125 | \endtable | - | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | \sa QLayout, QWidgetItem, QLayoutItem::spacerItem() | - | ||||||||||||||||||
128 | */ | - | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | /*! | - | ||||||||||||||||||
131 | \class QWidgetItem | - | ||||||||||||||||||
132 | \ingroup geomanagement | - | ||||||||||||||||||
133 | \brief The QWidgetItem class is a layout item that represents a widget. | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | \inmodule QtWidgets | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | Normally, you don't need to use this class directly. Qt's | - | ||||||||||||||||||
138 | built-in layout managers provide the following functions for | - | ||||||||||||||||||
139 | manipulating widgets in layouts: | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | \table | - | ||||||||||||||||||
142 | \header \li Class | - | ||||||||||||||||||
143 | \li Functions | - | ||||||||||||||||||
144 | \row \li QBoxLayout | - | ||||||||||||||||||
145 | \li \l{QBoxLayout::addWidget()}{addWidget()}, | - | ||||||||||||||||||
146 | \l{QBoxLayout::insertWidget()}{insertWidget()}, | - | ||||||||||||||||||
147 | \l{QBoxLayout::setStretchFactor()}{setStretchFactor()} | - | ||||||||||||||||||
148 | \row \li QGridLayout | - | ||||||||||||||||||
149 | \li \l{QGridLayout::addWidget()}{addWidget()} | - | ||||||||||||||||||
150 | \row \li QStackedLayout | - | ||||||||||||||||||
151 | \li \l{QStackedLayout::addWidget()}{addWidget()}, | - | ||||||||||||||||||
152 | \l{QStackedLayout::insertWidget()}{insertWidget()}, | - | ||||||||||||||||||
153 | \l{QStackedLayout::currentWidget()}{currentWidget()}, | - | ||||||||||||||||||
154 | \l{QStackedLayout::setCurrentWidget()}{setCurrentWidget()}, | - | ||||||||||||||||||
155 | \l{QStackedLayout::widget()}{widget()} | - | ||||||||||||||||||
156 | \endtable | - | ||||||||||||||||||
157 | - | |||||||||||||||||||
158 | \sa QLayout, QSpacerItem, QLayoutItem::widget() | - | ||||||||||||||||||
159 | */ | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | /*! | - | ||||||||||||||||||
162 | \fn QLayoutItem::QLayoutItem(Qt::Alignment alignment) | - | ||||||||||||||||||
163 | - | |||||||||||||||||||
164 | Constructs a layout item with an \a alignment. | - | ||||||||||||||||||
165 | Not all subclasses support alignment. | - | ||||||||||||||||||
166 | */ | - | ||||||||||||||||||
167 | - | |||||||||||||||||||
168 | /*! | - | ||||||||||||||||||
169 | \fn Qt::Alignment QLayoutItem::alignment() const | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | Returns the alignment of this item. | - | ||||||||||||||||||
172 | */ | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | /*! | - | ||||||||||||||||||
175 | Sets the alignment of this item to \a alignment. | - | ||||||||||||||||||
176 | - | |||||||||||||||||||
177 | \b{Note:} Item alignment is only supported by QLayoutItem subclasses | - | ||||||||||||||||||
178 | where it would have a visual effect. Except for QSpacerItem, which provides | - | ||||||||||||||||||
179 | blank space for layouts, all public Qt classes that inherit QLayoutItem | - | ||||||||||||||||||
180 | support item alignment. | - | ||||||||||||||||||
181 | */ | - | ||||||||||||||||||
182 | void QLayoutItem::setAlignment(Qt::Alignment alignment) | - | ||||||||||||||||||
183 | { | - | ||||||||||||||||||
184 | align = alignment; | - | ||||||||||||||||||
185 | } never executed: end of block | 0 | ||||||||||||||||||
186 | - | |||||||||||||||||||
187 | /*! | - | ||||||||||||||||||
188 | \fn QSize QLayoutItem::maximumSize() const | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | Implemented in subclasses to return the maximum size of this item. | - | ||||||||||||||||||
191 | */ | - | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | /*! | - | ||||||||||||||||||
194 | \fn QSize QLayoutItem::minimumSize() const | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | Implemented in subclasses to return the minimum size of this item. | - | ||||||||||||||||||
197 | */ | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | /*! | - | ||||||||||||||||||
200 | \fn QSize QLayoutItem::sizeHint() const | - | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | Implemented in subclasses to return the preferred size of this item. | - | ||||||||||||||||||
203 | */ | - | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | /*! | - | ||||||||||||||||||
206 | \fn Qt::Orientations QLayoutItem::expandingDirections() const | - | ||||||||||||||||||
207 | - | |||||||||||||||||||
208 | Returns whether this layout item can make use of more space than | - | ||||||||||||||||||
209 | sizeHint(). A value of Qt::Vertical or Qt::Horizontal means that | - | ||||||||||||||||||
210 | it wants to grow in only one dimension, whereas Qt::Vertical | | - | ||||||||||||||||||
211 | Qt::Horizontal means that it wants to grow in both dimensions. | - | ||||||||||||||||||
212 | */ | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | /*! | - | ||||||||||||||||||
215 | \fn void QLayoutItem::setGeometry(const QRect &r) | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | Implemented in subclasses to set this item's geometry to \a r. | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | \sa geometry() | - | ||||||||||||||||||
220 | */ | - | ||||||||||||||||||
221 | - | |||||||||||||||||||
222 | /*! | - | ||||||||||||||||||
223 | \fn QRect QLayoutItem::geometry() const | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | Returns the rectangle covered by this layout item. | - | ||||||||||||||||||
226 | - | |||||||||||||||||||
227 | \sa setGeometry() | - | ||||||||||||||||||
228 | */ | - | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | /*! | - | ||||||||||||||||||
231 | \fn virtual bool QLayoutItem::isEmpty() const | - | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | Implemented in subclasses to return whether this item is empty, | - | ||||||||||||||||||
234 | i.e. whether it contains any widgets. | - | ||||||||||||||||||
235 | */ | - | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | /*! | - | ||||||||||||||||||
238 | \fn QSpacerItem::QSpacerItem(int w, int h, QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy) | - | ||||||||||||||||||
239 | - | |||||||||||||||||||
240 | Constructs a spacer item with preferred width \a w, preferred | - | ||||||||||||||||||
241 | height \a h, horizontal size policy \a hPolicy and vertical size | - | ||||||||||||||||||
242 | policy \a vPolicy. | - | ||||||||||||||||||
243 | - | |||||||||||||||||||
244 | The default values provide a gap that is able to stretch if | - | ||||||||||||||||||
245 | nothing else wants the space. | - | ||||||||||||||||||
246 | */ | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | /*! | - | ||||||||||||||||||
249 | Destructor. | - | ||||||||||||||||||
250 | */ | - | ||||||||||||||||||
251 | QSpacerItem::~QSpacerItem() {} | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | /*! | - | ||||||||||||||||||
254 | Changes this spacer item to have preferred width \a w, preferred | - | ||||||||||||||||||
255 | height \a h, horizontal size policy \a hPolicy and vertical size | - | ||||||||||||||||||
256 | policy \a vPolicy. | - | ||||||||||||||||||
257 | - | |||||||||||||||||||
258 | The default values provide a gap that is able to stretch if | - | ||||||||||||||||||
259 | nothing else wants the space. | - | ||||||||||||||||||
260 | - | |||||||||||||||||||
261 | Note that if changeSize() is called after the spacer item has been added | - | ||||||||||||||||||
262 | to a layout, it is necessary to invalidate the layout in order for the | - | ||||||||||||||||||
263 | spacer item's new size to take effect. | - | ||||||||||||||||||
264 | - | |||||||||||||||||||
265 | \sa QSpacerItem::invalidate() | - | ||||||||||||||||||
266 | */ | - | ||||||||||||||||||
267 | void QSpacerItem::changeSize(int w, int h, QSizePolicy::Policy hPolicy, | - | ||||||||||||||||||
268 | QSizePolicy::Policy vPolicy) | - | ||||||||||||||||||
269 | { | - | ||||||||||||||||||
270 | width = w; | - | ||||||||||||||||||
271 | height = h; | - | ||||||||||||||||||
272 | sizeP = QSizePolicy(hPolicy, vPolicy); | - | ||||||||||||||||||
273 | } never executed: end of block | 0 | ||||||||||||||||||
274 | - | |||||||||||||||||||
275 | /*! | - | ||||||||||||||||||
276 | \fn QWidgetItem::QWidgetItem(QWidget *widget) | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | Creates an item containing the given \a widget. | - | ||||||||||||||||||
279 | */ | - | ||||||||||||||||||
280 | - | |||||||||||||||||||
281 | /*! | - | ||||||||||||||||||
282 | Destructor. | - | ||||||||||||||||||
283 | */ | - | ||||||||||||||||||
284 | QWidgetItem::~QWidgetItem() {} | - | ||||||||||||||||||
285 | - | |||||||||||||||||||
286 | /*! | - | ||||||||||||||||||
287 | Destroys the QLayoutItem. | - | ||||||||||||||||||
288 | */ | - | ||||||||||||||||||
289 | QLayoutItem::~QLayoutItem() | - | ||||||||||||||||||
290 | { | - | ||||||||||||||||||
291 | } | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | /*! | - | ||||||||||||||||||
294 | Invalidates any cached information in this layout item. | - | ||||||||||||||||||
295 | */ | - | ||||||||||||||||||
296 | void QLayoutItem::invalidate() | - | ||||||||||||||||||
297 | { | - | ||||||||||||||||||
298 | } | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | /*! | - | ||||||||||||||||||
301 | If this item is a QLayout, it is returned as a QLayout; otherwise | - | ||||||||||||||||||
302 | 0 is returned. This function provides type-safe casting. | - | ||||||||||||||||||
303 | - | |||||||||||||||||||
304 | \sa spacerItem(), widget() | - | ||||||||||||||||||
305 | */ | - | ||||||||||||||||||
306 | QLayout * QLayoutItem::layout() | - | ||||||||||||||||||
307 | { | - | ||||||||||||||||||
308 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
309 | } | - | ||||||||||||||||||
310 | - | |||||||||||||||||||
311 | /*! | - | ||||||||||||||||||
312 | If this item is a QSpacerItem, it is returned as a QSpacerItem; | - | ||||||||||||||||||
313 | otherwise 0 is returned. This function provides type-safe casting. | - | ||||||||||||||||||
314 | - | |||||||||||||||||||
315 | \sa layout(), widget() | - | ||||||||||||||||||
316 | */ | - | ||||||||||||||||||
317 | QSpacerItem * QLayoutItem::spacerItem() | - | ||||||||||||||||||
318 | { | - | ||||||||||||||||||
319 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
320 | } | - | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | /*! | - | ||||||||||||||||||
323 | \reimp | - | ||||||||||||||||||
324 | */ | - | ||||||||||||||||||
325 | QLayout * QLayout::layout() | - | ||||||||||||||||||
326 | { | - | ||||||||||||||||||
327 | return this; never executed: return this; | 0 | ||||||||||||||||||
328 | } | - | ||||||||||||||||||
329 | - | |||||||||||||||||||
330 | /*! | - | ||||||||||||||||||
331 | Returns a pointer to this object. | - | ||||||||||||||||||
332 | */ | - | ||||||||||||||||||
333 | QSpacerItem * QSpacerItem::spacerItem() | - | ||||||||||||||||||
334 | { | - | ||||||||||||||||||
335 | return this; never executed: return this; | 0 | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | /*! | - | ||||||||||||||||||
339 | \fn QSizePolicy QSpacerItem::sizePolicy() const | - | ||||||||||||||||||
340 | \since 5.5 | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | Returns the size policy of this item. | - | ||||||||||||||||||
343 | */ | - | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | /*! | - | ||||||||||||||||||
346 | If this item manages a QWidget, returns that widget. Otherwise, | - | ||||||||||||||||||
347 | \c nullptr is returned. | - | ||||||||||||||||||
348 | - | |||||||||||||||||||
349 | \note While the functions layout() and spacerItem() perform casts, this | - | ||||||||||||||||||
350 | function returns another object: QLayout and QSpacerItem inherit QLayoutItem, | - | ||||||||||||||||||
351 | while QWidget does not. | - | ||||||||||||||||||
352 | - | |||||||||||||||||||
353 | \sa layout(), spacerItem() | - | ||||||||||||||||||
354 | */ | - | ||||||||||||||||||
355 | QWidget * QLayoutItem::widget() | - | ||||||||||||||||||
356 | { | - | ||||||||||||||||||
357 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
358 | } | - | ||||||||||||||||||
359 | - | |||||||||||||||||||
360 | /*! | - | ||||||||||||||||||
361 | Returns the widget managed by this item. | - | ||||||||||||||||||
362 | */ | - | ||||||||||||||||||
363 | QWidget *QWidgetItem::widget() | - | ||||||||||||||||||
364 | { | - | ||||||||||||||||||
365 | return wid; never executed: return wid; | 0 | ||||||||||||||||||
366 | } | - | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | /*! | - | ||||||||||||||||||
369 | Returns \c true if this layout's preferred height depends on its | - | ||||||||||||||||||
370 | width; otherwise returns \c false. The default implementation returns | - | ||||||||||||||||||
371 | false. | - | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | Reimplement this function in layout managers that support height | - | ||||||||||||||||||
374 | for width. | - | ||||||||||||||||||
375 | - | |||||||||||||||||||
376 | \sa heightForWidth(), QWidget::heightForWidth() | - | ||||||||||||||||||
377 | */ | - | ||||||||||||||||||
378 | bool QLayoutItem::hasHeightForWidth() const | - | ||||||||||||||||||
379 | { | - | ||||||||||||||||||
380 | return false; never executed: return false; | 0 | ||||||||||||||||||
381 | } | - | ||||||||||||||||||
382 | - | |||||||||||||||||||
383 | /*! | - | ||||||||||||||||||
384 | Returns the minimum height this widget needs for the given width, | - | ||||||||||||||||||
385 | \a w. The default implementation simply returns heightForWidth(\a | - | ||||||||||||||||||
386 | w). | - | ||||||||||||||||||
387 | */ | - | ||||||||||||||||||
388 | int QLayoutItem::minimumHeightForWidth(int w) const | - | ||||||||||||||||||
389 | { | - | ||||||||||||||||||
390 | return heightForWidth(w); never executed: return heightForWidth(w); | 0 | ||||||||||||||||||
391 | } | - | ||||||||||||||||||
392 | - | |||||||||||||||||||
393 | - | |||||||||||||||||||
394 | /*! | - | ||||||||||||||||||
395 | Returns the preferred height for this layout item, given the width | - | ||||||||||||||||||
396 | \a w. | - | ||||||||||||||||||
397 | - | |||||||||||||||||||
398 | The default implementation returns -1, indicating that the | - | ||||||||||||||||||
399 | preferred height is independent of the width of the item. Using | - | ||||||||||||||||||
400 | the function hasHeightForWidth() will typically be much faster | - | ||||||||||||||||||
401 | than calling this function and testing for -1. | - | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | Reimplement this function in layout managers that support height | - | ||||||||||||||||||
404 | for width. A typical implementation will look like this: | - | ||||||||||||||||||
405 | \snippet code/src_gui_kernel_qlayoutitem.cpp 0 | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | Caching is strongly recommended; without it layout will take | - | ||||||||||||||||||
408 | exponential time. | - | ||||||||||||||||||
409 | - | |||||||||||||||||||
410 | \sa hasHeightForWidth() | - | ||||||||||||||||||
411 | */ | - | ||||||||||||||||||
412 | int QLayoutItem::heightForWidth(int /* w */) const | - | ||||||||||||||||||
413 | { | - | ||||||||||||||||||
414 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
415 | } | - | ||||||||||||||||||
416 | - | |||||||||||||||||||
417 | /*! | - | ||||||||||||||||||
418 | Returns the control type(s) for the layout item. For a | - | ||||||||||||||||||
419 | QWidgetItem, the control type comes from the widget's size | - | ||||||||||||||||||
420 | policy; for a QLayoutItem, the control types is derived from the | - | ||||||||||||||||||
421 | layout's contents. | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | \sa QSizePolicy::controlType() | - | ||||||||||||||||||
424 | */ | - | ||||||||||||||||||
425 | QSizePolicy::ControlTypes QLayoutItem::controlTypes() const | - | ||||||||||||||||||
426 | { | - | ||||||||||||||||||
427 | return QSizePolicy::DefaultType; never executed: return QSizePolicy::DefaultType; | 0 | ||||||||||||||||||
428 | } | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | /*! | - | ||||||||||||||||||
431 | \reimp | - | ||||||||||||||||||
432 | */ | - | ||||||||||||||||||
433 | void QSpacerItem::setGeometry(const QRect &r) | - | ||||||||||||||||||
434 | { | - | ||||||||||||||||||
435 | rect = r; | - | ||||||||||||||||||
436 | } never executed: end of block | 0 | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | /*! | - | ||||||||||||||||||
439 | \reimp | - | ||||||||||||||||||
440 | */ | - | ||||||||||||||||||
441 | void QWidgetItem::setGeometry(const QRect &rect) | - | ||||||||||||||||||
442 | { | - | ||||||||||||||||||
443 | if (isEmpty())
| 0 | ||||||||||||||||||
444 | return; never executed: return; | 0 | ||||||||||||||||||
445 | - | |||||||||||||||||||
446 | QRect r = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
| 0 | ||||||||||||||||||
447 | ? fromLayoutItemRect(wid->d_func(), rect) | - | ||||||||||||||||||
448 | : rect; | - | ||||||||||||||||||
449 | const QSize widgetRectSurplus = r.size() - rect.size(); | - | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | /* | - | ||||||||||||||||||
452 | For historical reasons, this code is done using widget rect | - | ||||||||||||||||||
453 | coordinates, not layout item rect coordinates. However, | - | ||||||||||||||||||
454 | QWidgetItem's sizeHint(), maximumSize(), and heightForWidth() | - | ||||||||||||||||||
455 | all work in terms of layout item rect coordinates, so we have to | - | ||||||||||||||||||
456 | add or subtract widgetRectSurplus here and there. The code could | - | ||||||||||||||||||
457 | be much simpler if we did everything using layout item rect | - | ||||||||||||||||||
458 | coordinates and did the conversion right before the call to | - | ||||||||||||||||||
459 | QWidget::setGeometry(). | - | ||||||||||||||||||
460 | */ | - | ||||||||||||||||||
461 | - | |||||||||||||||||||
462 | QSize s = r.size().boundedTo(maximumSize() + widgetRectSurplus); | - | ||||||||||||||||||
463 | int x = r.x(); | - | ||||||||||||||||||
464 | int y = r.y(); | - | ||||||||||||||||||
465 | if (align & (Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask)) {
| 0 | ||||||||||||||||||
466 | QSize pref(sizeHint()); | - | ||||||||||||||||||
467 | QSizePolicy sp = wid->sizePolicy(); | - | ||||||||||||||||||
468 | if (sp.horizontalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||
469 | pref.setWidth(wid->sizeHint().expandedTo(wid->minimumSize()).width()); never executed: pref.setWidth(wid->sizeHint().expandedTo(wid->minimumSize()).width()); | 0 | ||||||||||||||||||
470 | if (sp.verticalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||
471 | pref.setHeight(wid->sizeHint().expandedTo(wid->minimumSize()).height()); never executed: pref.setHeight(wid->sizeHint().expandedTo(wid->minimumSize()).height()); | 0 | ||||||||||||||||||
472 | pref += widgetRectSurplus; | - | ||||||||||||||||||
473 | if (align & Qt::AlignHorizontal_Mask)
| 0 | ||||||||||||||||||
474 | s.setWidth(qMin(s.width(), pref.width())); never executed: s.setWidth(qMin(s.width(), pref.width())); | 0 | ||||||||||||||||||
475 | if (align & Qt::AlignVertical_Mask) {
| 0 | ||||||||||||||||||
476 | if (hasHeightForWidth())
| 0 | ||||||||||||||||||
477 | s.setHeight(qMin(s.height(), never executed: s.setHeight(qMin(s.height(), heightForWidth(s.width() - widgetRectSurplus.width()) + widgetRectSurplus.height())); | 0 | ||||||||||||||||||
478 | heightForWidth(s.width() - widgetRectSurplus.width()) never executed: s.setHeight(qMin(s.height(), heightForWidth(s.width() - widgetRectSurplus.width()) + widgetRectSurplus.height())); | 0 | ||||||||||||||||||
479 | + widgetRectSurplus.height())); never executed: s.setHeight(qMin(s.height(), heightForWidth(s.width() - widgetRectSurplus.width()) + widgetRectSurplus.height())); | 0 | ||||||||||||||||||
480 | else | - | ||||||||||||||||||
481 | s.setHeight(qMin(s.height(), pref.height())); never executed: s.setHeight(qMin(s.height(), pref.height())); | 0 | ||||||||||||||||||
482 | } | - | ||||||||||||||||||
483 | } never executed: end of block | 0 | ||||||||||||||||||
484 | Qt::Alignment alignHoriz = QStyle::visualAlignment(wid->layoutDirection(), align); | - | ||||||||||||||||||
485 | if (alignHoriz & Qt::AlignRight)
| 0 | ||||||||||||||||||
486 | x = x + (r.width() - s.width()); never executed: x = x + (r.width() - s.width()); | 0 | ||||||||||||||||||
487 | else if (!(alignHoriz & Qt::AlignLeft))
| 0 | ||||||||||||||||||
488 | x = x + (r.width() - s.width()) / 2; never executed: x = x + (r.width() - s.width()) / 2; | 0 | ||||||||||||||||||
489 | - | |||||||||||||||||||
490 | if (align & Qt::AlignBottom)
| 0 | ||||||||||||||||||
491 | y = y + (r.height() - s.height()); never executed: y = y + (r.height() - s.height()); | 0 | ||||||||||||||||||
492 | else if (!(align & Qt::AlignTop))
| 0 | ||||||||||||||||||
493 | y = y + (r.height() - s.height()) / 2; never executed: y = y + (r.height() - s.height()) / 2; | 0 | ||||||||||||||||||
494 | - | |||||||||||||||||||
495 | wid->setGeometry(x, y, s.width(), s.height()); | - | ||||||||||||||||||
496 | } never executed: end of block | 0 | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | /*! | - | ||||||||||||||||||
499 | \reimp | - | ||||||||||||||||||
500 | */ | - | ||||||||||||||||||
501 | QRect QSpacerItem::geometry() const | - | ||||||||||||||||||
502 | { | - | ||||||||||||||||||
503 | return rect; never executed: return rect; | 0 | ||||||||||||||||||
504 | } | - | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | /*! | - | ||||||||||||||||||
507 | \reimp | - | ||||||||||||||||||
508 | */ | - | ||||||||||||||||||
509 | QRect QWidgetItem::geometry() const | - | ||||||||||||||||||
510 | { | - | ||||||||||||||||||
511 | return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemRect(wid->d_func(), wid->geometry()) : wid->geometry();
| 0 | ||||||||||||||||||
512 | ? toLayoutItemRect(wid->d_func(), wid->geometry()) never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemRect(wid->d_func(), wid->geometry()) : wid->geometry(); | 0 | ||||||||||||||||||
513 | : wid->geometry(); never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemRect(wid->d_func(), wid->geometry()) : wid->geometry(); | 0 | ||||||||||||||||||
514 | } | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | - | |||||||||||||||||||
517 | /*! | - | ||||||||||||||||||
518 | \reimp | - | ||||||||||||||||||
519 | */ | - | ||||||||||||||||||
520 | bool QWidgetItem::hasHeightForWidth() const | - | ||||||||||||||||||
521 | { | - | ||||||||||||||||||
522 | if (isEmpty())
| 0 | ||||||||||||||||||
523 | return false; never executed: return false; | 0 | ||||||||||||||||||
524 | return wid->hasHeightForWidth(); never executed: return wid->hasHeightForWidth(); | 0 | ||||||||||||||||||
525 | } | - | ||||||||||||||||||
526 | - | |||||||||||||||||||
527 | /*! | - | ||||||||||||||||||
528 | \reimp | - | ||||||||||||||||||
529 | */ | - | ||||||||||||||||||
530 | int QWidgetItem::heightForWidth(int w) const | - | ||||||||||||||||||
531 | { | - | ||||||||||||||||||
532 | if (isEmpty())
| 0 | ||||||||||||||||||
533 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
534 | - | |||||||||||||||||||
535 | w = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
| 0 | ||||||||||||||||||
536 | ? fromLayoutItemSize(wid->d_func(), QSize(w, 0)).width() | - | ||||||||||||||||||
537 | : w; | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | int hfw; | - | ||||||||||||||||||
540 | if (wid->layout())
| 0 | ||||||||||||||||||
541 | hfw = wid->layout()->totalHeightForWidth(w); never executed: hfw = wid->layout()->totalHeightForWidth(w); | 0 | ||||||||||||||||||
542 | else | - | ||||||||||||||||||
543 | hfw = wid->heightForWidth(w); never executed: hfw = wid->heightForWidth(w); | 0 | ||||||||||||||||||
544 | - | |||||||||||||||||||
545 | if (hfw > wid->maximumHeight())
| 0 | ||||||||||||||||||
546 | hfw = wid->maximumHeight(); never executed: hfw = wid->maximumHeight(); | 0 | ||||||||||||||||||
547 | if (hfw < wid->minimumHeight())
| 0 | ||||||||||||||||||
548 | hfw = wid->minimumHeight(); never executed: hfw = wid->minimumHeight(); | 0 | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | hfw = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
| 0 | ||||||||||||||||||
551 | ? toLayoutItemSize(wid->d_func(), QSize(0, hfw)).height() | - | ||||||||||||||||||
552 | : hfw; | - | ||||||||||||||||||
553 | - | |||||||||||||||||||
554 | if (hfw < 0)
| 0 | ||||||||||||||||||
555 | hfw = 0; never executed: hfw = 0; | 0 | ||||||||||||||||||
556 | return hfw; never executed: return hfw; | 0 | ||||||||||||||||||
557 | } | - | ||||||||||||||||||
558 | - | |||||||||||||||||||
559 | /*! | - | ||||||||||||||||||
560 | \reimp | - | ||||||||||||||||||
561 | */ | - | ||||||||||||||||||
562 | Qt::Orientations QSpacerItem::expandingDirections() const | - | ||||||||||||||||||
563 | { | - | ||||||||||||||||||
564 | return sizeP.expandingDirections(); never executed: return sizeP.expandingDirections(); | 0 | ||||||||||||||||||
565 | } | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | /*! | - | ||||||||||||||||||
568 | \reimp | - | ||||||||||||||||||
569 | */ | - | ||||||||||||||||||
570 | Qt::Orientations QWidgetItem::expandingDirections() const | - | ||||||||||||||||||
571 | { | - | ||||||||||||||||||
572 | if (isEmpty())
| 0 | ||||||||||||||||||
573 | return Qt::Orientations(0); never executed: return Qt::Orientations(0); | 0 | ||||||||||||||||||
574 | - | |||||||||||||||||||
575 | Qt::Orientations e = wid->sizePolicy().expandingDirections(); | - | ||||||||||||||||||
576 | /* | - | ||||||||||||||||||
577 | If the layout is expanding, we make the widget expanding, even if | - | ||||||||||||||||||
578 | its own size policy isn't expanding. | - | ||||||||||||||||||
579 | */ | - | ||||||||||||||||||
580 | if (wid->layout()) {
| 0 | ||||||||||||||||||
581 | if (wid->sizePolicy().horizontalPolicy() & QSizePolicy::GrowFlag
| 0 | ||||||||||||||||||
582 | && (wid->layout()->expandingDirections() & Qt::Horizontal))
| 0 | ||||||||||||||||||
583 | e |= Qt::Horizontal; never executed: e |= Qt::Horizontal; | 0 | ||||||||||||||||||
584 | if (wid->sizePolicy().verticalPolicy() & QSizePolicy::GrowFlag
| 0 | ||||||||||||||||||
585 | && (wid->layout()->expandingDirections() & Qt::Vertical))
| 0 | ||||||||||||||||||
586 | e |= Qt::Vertical; never executed: e |= Qt::Vertical; | 0 | ||||||||||||||||||
587 | } never executed: end of block | 0 | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | if (align & Qt::AlignHorizontal_Mask)
| 0 | ||||||||||||||||||
590 | e &= ~Qt::Horizontal; never executed: e &= ~Qt::Horizontal; | 0 | ||||||||||||||||||
591 | if (align & Qt::AlignVertical_Mask)
| 0 | ||||||||||||||||||
592 | e &= ~Qt::Vertical; never executed: e &= ~Qt::Vertical; | 0 | ||||||||||||||||||
593 | return e; never executed: return e; | 0 | ||||||||||||||||||
594 | } | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | /*! | - | ||||||||||||||||||
597 | \reimp | - | ||||||||||||||||||
598 | */ | - | ||||||||||||||||||
599 | QSize QSpacerItem::minimumSize() const | - | ||||||||||||||||||
600 | { | - | ||||||||||||||||||
601 | return QSize(sizeP.horizontalPolicy() & QSizePolicy::ShrinkFlag ? 0 : width, never executed: return QSize(sizeP.horizontalPolicy() & QSizePolicy::ShrinkFlag ? 0 : width, sizeP.verticalPolicy() & QSizePolicy::ShrinkFlag ? 0 : height); | 0 | ||||||||||||||||||
602 | sizeP.verticalPolicy() & QSizePolicy::ShrinkFlag ? 0 : height); never executed: return QSize(sizeP.horizontalPolicy() & QSizePolicy::ShrinkFlag ? 0 : width, sizeP.verticalPolicy() & QSizePolicy::ShrinkFlag ? 0 : height); | 0 | ||||||||||||||||||
603 | } | - | ||||||||||||||||||
604 | - | |||||||||||||||||||
605 | /*! | - | ||||||||||||||||||
606 | \reimp | - | ||||||||||||||||||
607 | */ | - | ||||||||||||||||||
608 | QSize QWidgetItem::minimumSize() const | - | ||||||||||||||||||
609 | { | - | ||||||||||||||||||
610 | if (isEmpty())
| 0 | ||||||||||||||||||
611 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||
612 | return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemSize(wid->d_func(), qSmartMinSize(this)) : qSmartMinSize(this);
| 0 | ||||||||||||||||||
613 | ? toLayoutItemSize(wid->d_func(), qSmartMinSize(this)) never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemSize(wid->d_func(), qSmartMinSize(this)) : qSmartMinSize(this); | 0 | ||||||||||||||||||
614 | : qSmartMinSize(this); never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemSize(wid->d_func(), qSmartMinSize(this)) : qSmartMinSize(this); | 0 | ||||||||||||||||||
615 | } | - | ||||||||||||||||||
616 | - | |||||||||||||||||||
617 | /*! | - | ||||||||||||||||||
618 | \reimp | - | ||||||||||||||||||
619 | */ | - | ||||||||||||||||||
620 | QSize QSpacerItem::maximumSize() const | - | ||||||||||||||||||
621 | { | - | ||||||||||||||||||
622 | return QSize(sizeP.horizontalPolicy() & QSizePolicy::GrowFlag ? QLAYOUTSIZE_MAX : width, never executed: return QSize(sizeP.horizontalPolicy() & QSizePolicy::GrowFlag ? QLAYOUTSIZE_MAX : width, sizeP.verticalPolicy() & QSizePolicy::GrowFlag ? QLAYOUTSIZE_MAX : height); | 0 | ||||||||||||||||||
623 | sizeP.verticalPolicy() & QSizePolicy::GrowFlag ? QLAYOUTSIZE_MAX : height); never executed: return QSize(sizeP.horizontalPolicy() & QSizePolicy::GrowFlag ? QLAYOUTSIZE_MAX : width, sizeP.verticalPolicy() & QSizePolicy::GrowFlag ? QLAYOUTSIZE_MAX : height); | 0 | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | /*! | - | ||||||||||||||||||
627 | \reimp | - | ||||||||||||||||||
628 | */ | - | ||||||||||||||||||
629 | QSize QWidgetItem::maximumSize() const | - | ||||||||||||||||||
630 | { | - | ||||||||||||||||||
631 | if (isEmpty()) {
| 0 | ||||||||||||||||||
632 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||
633 | } else { | - | ||||||||||||||||||
634 | return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemSize(wid->d_func(), qSmartMaxSize(this, align)) : qSmartMaxSize(this, align);
| 0 | ||||||||||||||||||
635 | ? toLayoutItemSize(wid->d_func(), qSmartMaxSize(this, align)) never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemSize(wid->d_func(), qSmartMaxSize(this, align)) : qSmartMaxSize(this, align); | 0 | ||||||||||||||||||
636 | : qSmartMaxSize(this, align); never executed: return !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect) ? toLayoutItemSize(wid->d_func(), qSmartMaxSize(this, align)) : qSmartMaxSize(this, align); | 0 | ||||||||||||||||||
637 | } | - | ||||||||||||||||||
638 | } | - | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | /*! | - | ||||||||||||||||||
641 | \reimp | - | ||||||||||||||||||
642 | */ | - | ||||||||||||||||||
643 | QSize QSpacerItem::sizeHint() const | - | ||||||||||||||||||
644 | { | - | ||||||||||||||||||
645 | return QSize(width, height); never executed: return QSize(width, height); | 0 | ||||||||||||||||||
646 | } | - | ||||||||||||||||||
647 | - | |||||||||||||||||||
648 | /*! | - | ||||||||||||||||||
649 | \reimp | - | ||||||||||||||||||
650 | */ | - | ||||||||||||||||||
651 | QSize QWidgetItem::sizeHint() const | - | ||||||||||||||||||
652 | { | - | ||||||||||||||||||
653 | QSize s(0, 0); | - | ||||||||||||||||||
654 | if (!isEmpty()) {
| 0 | ||||||||||||||||||
655 | s = wid->sizeHint().expandedTo(wid->minimumSizeHint()); | - | ||||||||||||||||||
656 | s = s.boundedTo(wid->maximumSize()) | - | ||||||||||||||||||
657 | .expandedTo(wid->minimumSize()); | - | ||||||||||||||||||
658 | s = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect)
| 0 | ||||||||||||||||||
659 | ? toLayoutItemSize(wid->d_func(), s) | - | ||||||||||||||||||
660 | : s; | - | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | if (wid->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||
663 | s.setWidth(0); never executed: s.setWidth(0); | 0 | ||||||||||||||||||
664 | if (wid->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||
665 | s.setHeight(0); never executed: s.setHeight(0); | 0 | ||||||||||||||||||
666 | } never executed: end of block | 0 | ||||||||||||||||||
667 | return s; never executed: return s; | 0 | ||||||||||||||||||
668 | } | - | ||||||||||||||||||
669 | - | |||||||||||||||||||
670 | /*! | - | ||||||||||||||||||
671 | Returns \c true. | - | ||||||||||||||||||
672 | */ | - | ||||||||||||||||||
673 | bool QSpacerItem::isEmpty() const | - | ||||||||||||||||||
674 | { | - | ||||||||||||||||||
675 | return true; never executed: return true; | 0 | ||||||||||||||||||
676 | } | - | ||||||||||||||||||
677 | - | |||||||||||||||||||
678 | /*! | - | ||||||||||||||||||
679 | Returns \c true if the widget is hidden; otherwise returns \c false. | - | ||||||||||||||||||
680 | - | |||||||||||||||||||
681 | \sa QWidget::isHidden() | - | ||||||||||||||||||
682 | */ | - | ||||||||||||||||||
683 | bool QWidgetItem::isEmpty() const | - | ||||||||||||||||||
684 | { | - | ||||||||||||||||||
685 | return (wid->isHidden() && !wid->sizePolicy().retainSizeWhenHidden()) || wid->isWindow(); never executed: return (wid->isHidden() && !wid->sizePolicy().retainSizeWhenHidden()) || wid->isWindow();
| 0 | ||||||||||||||||||
686 | } | - | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | /*! | - | ||||||||||||||||||
689 | Returns the control type associated with the widget for which | - | ||||||||||||||||||
690 | this size policy applies. | - | ||||||||||||||||||
691 | - | |||||||||||||||||||
692 | \sa QSizePolicy::controlType() | - | ||||||||||||||||||
693 | */ | - | ||||||||||||||||||
694 | QSizePolicy::ControlTypes QWidgetItem::controlTypes() const | - | ||||||||||||||||||
695 | { | - | ||||||||||||||||||
696 | return wid->sizePolicy().controlType(); never executed: return wid->sizePolicy().controlType(); | 0 | ||||||||||||||||||
697 | } | - | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | /*! | - | ||||||||||||||||||
700 | \class QWidgetItemV2 | - | ||||||||||||||||||
701 | \internal | - | ||||||||||||||||||
702 | */ | - | ||||||||||||||||||
703 | - | |||||||||||||||||||
704 | inline bool QWidgetItemV2::useSizeCache() const | - | ||||||||||||||||||
705 | { | - | ||||||||||||||||||
706 | return wid->d_func()->widgetItem == this; never executed: return wid->d_func()->widgetItem == this; | 0 | ||||||||||||||||||
707 | } | - | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | void QWidgetItemV2::updateCacheIfNecessary() const | - | ||||||||||||||||||
710 | { | - | ||||||||||||||||||
711 | if (q_cachedMinimumSize.width() != Dirty)
| 0 | ||||||||||||||||||
712 | return; never executed: return; | 0 | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | const QSize sizeHint(wid->sizeHint()); | - | ||||||||||||||||||
715 | const QSize minimumSizeHint(wid->minimumSizeHint()); | - | ||||||||||||||||||
716 | const QSize minimumSize(wid->minimumSize()); | - | ||||||||||||||||||
717 | const QSize maximumSize(wid->maximumSize()); | - | ||||||||||||||||||
718 | const QSizePolicy sizePolicy(wid->sizePolicy()); | - | ||||||||||||||||||
719 | const QSize expandedSizeHint(sizeHint.expandedTo(minimumSizeHint)); | - | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | const QSize smartMinSize(qSmartMinSize(sizeHint, minimumSizeHint, minimumSize, maximumSize, sizePolicy)); | - | ||||||||||||||||||
722 | const QSize smartMaxSize(qSmartMaxSize(expandedSizeHint, minimumSize, maximumSize, sizePolicy, align)); | - | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | const bool useLayoutItemRect = !wid->testAttribute(Qt::WA_LayoutUsesWidgetRect); | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | q_cachedMinimumSize = useLayoutItemRect
| 0 | ||||||||||||||||||
727 | ? toLayoutItemSize(wid->d_func(), smartMinSize) | - | ||||||||||||||||||
728 | : smartMinSize; | - | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | q_cachedSizeHint = expandedSizeHint; | - | ||||||||||||||||||
731 | q_cachedSizeHint = q_cachedSizeHint.boundedTo(maximumSize) | - | ||||||||||||||||||
732 | .expandedTo(minimumSize); | - | ||||||||||||||||||
733 | q_cachedSizeHint = useLayoutItemRect
| 0 | ||||||||||||||||||
734 | ? toLayoutItemSize(wid->d_func(), q_cachedSizeHint) | - | ||||||||||||||||||
735 | : q_cachedSizeHint; | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | if (wid->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||
738 | q_cachedSizeHint.setWidth(0); never executed: q_cachedSizeHint.setWidth(0); | 0 | ||||||||||||||||||
739 | if (wid->sizePolicy().verticalPolicy() == QSizePolicy::Ignored)
| 0 | ||||||||||||||||||
740 | q_cachedSizeHint.setHeight(0); never executed: q_cachedSizeHint.setHeight(0); | 0 | ||||||||||||||||||
741 | - | |||||||||||||||||||
742 | q_cachedMaximumSize = useLayoutItemRect
| 0 | ||||||||||||||||||
743 | ? toLayoutItemSize(wid->d_func(), smartMaxSize) | - | ||||||||||||||||||
744 | : smartMaxSize; | - | ||||||||||||||||||
745 | } never executed: end of block | 0 | ||||||||||||||||||
746 | - | |||||||||||||||||||
747 | QWidgetItemV2::QWidgetItemV2(QWidget *widget) | - | ||||||||||||||||||
748 | : QWidgetItem(widget), | - | ||||||||||||||||||
749 | q_cachedMinimumSize(Dirty, Dirty), | - | ||||||||||||||||||
750 | q_cachedSizeHint(Dirty, Dirty), | - | ||||||||||||||||||
751 | q_cachedMaximumSize(Dirty, Dirty), | - | ||||||||||||||||||
752 | q_firstCachedHfw(0), | - | ||||||||||||||||||
753 | q_hfwCacheSize(0), | - | ||||||||||||||||||
754 | d(0) | - | ||||||||||||||||||
755 | { | - | ||||||||||||||||||
756 | QWidgetPrivate *wd = wid->d_func(); | - | ||||||||||||||||||
757 | if (!wd->widgetItem)
| 0 | ||||||||||||||||||
758 | wd->widgetItem = this; never executed: wd->widgetItem = this; | 0 | ||||||||||||||||||
759 | } never executed: end of block | 0 | ||||||||||||||||||
760 | - | |||||||||||||||||||
761 | QWidgetItemV2::~QWidgetItemV2() | - | ||||||||||||||||||
762 | { | - | ||||||||||||||||||
763 | if (wid) {
| 0 | ||||||||||||||||||
764 | QWidgetPrivate *wd = wid->d_func(); | - | ||||||||||||||||||
765 | if (wd->widgetItem == this)
| 0 | ||||||||||||||||||
766 | wd->widgetItem = 0; never executed: wd->widgetItem = 0; | 0 | ||||||||||||||||||
767 | } never executed: end of block | 0 | ||||||||||||||||||
768 | } never executed: end of block | 0 | ||||||||||||||||||
769 | - | |||||||||||||||||||
770 | QSize QWidgetItemV2::sizeHint() const | - | ||||||||||||||||||
771 | { | - | ||||||||||||||||||
772 | if (isEmpty())
| 0 | ||||||||||||||||||
773 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||
774 | - | |||||||||||||||||||
775 | if (useSizeCache()) {
| 0 | ||||||||||||||||||
776 | updateCacheIfNecessary(); | - | ||||||||||||||||||
777 | return q_cachedSizeHint; never executed: return q_cachedSizeHint; | 0 | ||||||||||||||||||
778 | } else { | - | ||||||||||||||||||
779 | return QWidgetItem::sizeHint(); never executed: return QWidgetItem::sizeHint(); | 0 | ||||||||||||||||||
780 | } | - | ||||||||||||||||||
781 | } | - | ||||||||||||||||||
782 | - | |||||||||||||||||||
783 | QSize QWidgetItemV2::minimumSize() const | - | ||||||||||||||||||
784 | { | - | ||||||||||||||||||
785 | if (isEmpty())
| 0 | ||||||||||||||||||
786 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||
787 | - | |||||||||||||||||||
788 | if (useSizeCache()) {
| 0 | ||||||||||||||||||
789 | updateCacheIfNecessary(); | - | ||||||||||||||||||
790 | return q_cachedMinimumSize; never executed: return q_cachedMinimumSize; | 0 | ||||||||||||||||||
791 | } else { | - | ||||||||||||||||||
792 | return QWidgetItem::minimumSize(); never executed: return QWidgetItem::minimumSize(); | 0 | ||||||||||||||||||
793 | } | - | ||||||||||||||||||
794 | } | - | ||||||||||||||||||
795 | - | |||||||||||||||||||
796 | QSize QWidgetItemV2::maximumSize() const | - | ||||||||||||||||||
797 | { | - | ||||||||||||||||||
798 | if (isEmpty())
| 0 | ||||||||||||||||||
799 | return QSize(0, 0); never executed: return QSize(0, 0); | 0 | ||||||||||||||||||
800 | - | |||||||||||||||||||
801 | if (useSizeCache()) {
| 0 | ||||||||||||||||||
802 | updateCacheIfNecessary(); | - | ||||||||||||||||||
803 | return q_cachedMaximumSize; never executed: return q_cachedMaximumSize; | 0 | ||||||||||||||||||
804 | } else { | - | ||||||||||||||||||
805 | return QWidgetItem::maximumSize(); never executed: return QWidgetItem::maximumSize(); | 0 | ||||||||||||||||||
806 | } | - | ||||||||||||||||||
807 | } | - | ||||||||||||||||||
808 | - | |||||||||||||||||||
809 | /* | - | ||||||||||||||||||
810 | The height-for-width cache is organized as a circular buffer. The entries | - | ||||||||||||||||||
811 | - | |||||||||||||||||||
812 | q_hfwCachedHfws[q_firstCachedHfw], | - | ||||||||||||||||||
813 | ..., | - | ||||||||||||||||||
814 | q_hfwCachedHfws[(q_firstCachedHfw + q_hfwCacheSize - 1) % HfwCacheMaxSize] | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | contain the last cached values. When the cache is full, the first entry to | - | ||||||||||||||||||
817 | be erased is the entry before q_hfwCachedHfws[q_firstCachedHfw]. When | - | ||||||||||||||||||
818 | values are looked up, we try to move q_firstCachedHfw to point to that new | - | ||||||||||||||||||
819 | entry (unless the cache is not full, in which case it would leave the cache | - | ||||||||||||||||||
820 | in a broken state), so that the most recently used entry is also the last | - | ||||||||||||||||||
821 | to be erased. | - | ||||||||||||||||||
822 | */ | - | ||||||||||||||||||
823 | - | |||||||||||||||||||
824 | int QWidgetItemV2::heightForWidth(int width) const | - | ||||||||||||||||||
825 | { | - | ||||||||||||||||||
826 | if (isEmpty())
| 0 | ||||||||||||||||||
827 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
828 | - | |||||||||||||||||||
829 | for (int i = 0; i < q_hfwCacheSize; ++i) {
| 0 | ||||||||||||||||||
830 | int offset = q_firstCachedHfw + i; | - | ||||||||||||||||||
831 | const QSize &size = q_cachedHfws[offset % HfwCacheMaxSize]; | - | ||||||||||||||||||
832 | if (size.width() == width) {
| 0 | ||||||||||||||||||
833 | if (q_hfwCacheSize == HfwCacheMaxSize)
| 0 | ||||||||||||||||||
834 | q_firstCachedHfw = offset; never executed: q_firstCachedHfw = offset; | 0 | ||||||||||||||||||
835 | return size.height(); never executed: return size.height(); | 0 | ||||||||||||||||||
836 | } | - | ||||||||||||||||||
837 | } never executed: end of block | 0 | ||||||||||||||||||
838 | - | |||||||||||||||||||
839 | if (q_hfwCacheSize < HfwCacheMaxSize)
| 0 | ||||||||||||||||||
840 | ++q_hfwCacheSize; never executed: ++q_hfwCacheSize; | 0 | ||||||||||||||||||
841 | q_firstCachedHfw = (q_firstCachedHfw + HfwCacheMaxSize - 1) % HfwCacheMaxSize; | - | ||||||||||||||||||
842 | - | |||||||||||||||||||
843 | int height = QWidgetItem::heightForWidth(width); | - | ||||||||||||||||||
844 | q_cachedHfws[q_firstCachedHfw] = QSize(width, height); | - | ||||||||||||||||||
845 | return height; never executed: return height; | 0 | ||||||||||||||||||
846 | } | - | ||||||||||||||||||
847 | - | |||||||||||||||||||
848 | QT_END_NAMESPACE | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |