| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qboxlayout.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 "qboxlayout.h" | - | ||||||||||||
| 35 | #include "qapplication.h" | - | ||||||||||||
| 36 | #include "qwidget.h" | - | ||||||||||||
| 37 | #include "qlist.h" | - | ||||||||||||
| 38 | #include "qsizepolicy.h" | - | ||||||||||||
| 39 | #include "qvector.h" | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | #include "qlayoutengine_p.h" | - | ||||||||||||
| 42 | #include "qlayout_p.h" | - | ||||||||||||
| 43 | - | |||||||||||||
| 44 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | struct QBoxLayoutItem | - | ||||||||||||
| 47 | { | - | ||||||||||||
| 48 | QBoxLayoutItem(QLayoutItem *it, int stretch_ = 0) | - | ||||||||||||
| 49 | : item(it), stretch(stretch_), magic(false) { } never executed: end of block | 0 | ||||||||||||
| 50 | ~QBoxLayoutItem() { delete item; } never executed: end of block | 0 | ||||||||||||
| 51 | - | |||||||||||||
| 52 | int hfw(int w) { | - | ||||||||||||
| 53 | if (item->hasHeightForWidth()) {
| 0 | ||||||||||||
| 54 | return item->heightForWidth(w); never executed: return item->heightForWidth(w); | 0 | ||||||||||||
| 55 | } else { | - | ||||||||||||
| 56 | return item->sizeHint().height(); never executed: return item->sizeHint().height(); | 0 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | } | - | ||||||||||||
| 59 | int mhfw(int w) { | - | ||||||||||||
| 60 | if (item->hasHeightForWidth()) {
| 0 | ||||||||||||
| 61 | return item->heightForWidth(w); never executed: return item->heightForWidth(w); | 0 | ||||||||||||
| 62 | } else { | - | ||||||||||||
| 63 | return item->minimumSize().height(); never executed: return item->minimumSize().height(); | 0 | ||||||||||||
| 64 | } | - | ||||||||||||
| 65 | } | - | ||||||||||||
| 66 | int hStretch() { | - | ||||||||||||
| 67 | if (stretch == 0 && item->widget()) {
| 0 | ||||||||||||
| 68 | return item->widget()->sizePolicy().horizontalStretch(); never executed: return item->widget()->sizePolicy().horizontalStretch(); | 0 | ||||||||||||
| 69 | } else { | - | ||||||||||||
| 70 | return stretch; never executed: return stretch; | 0 | ||||||||||||
| 71 | } | - | ||||||||||||
| 72 | } | - | ||||||||||||
| 73 | int vStretch() { | - | ||||||||||||
| 74 | if (stretch == 0 && item->widget()) {
| 0 | ||||||||||||
| 75 | return item->widget()->sizePolicy().verticalStretch(); never executed: return item->widget()->sizePolicy().verticalStretch(); | 0 | ||||||||||||
| 76 | } else { | - | ||||||||||||
| 77 | return stretch; never executed: return stretch; | 0 | ||||||||||||
| 78 | } | - | ||||||||||||
| 79 | } | - | ||||||||||||
| 80 | - | |||||||||||||
| 81 | QLayoutItem *item; | - | ||||||||||||
| 82 | int stretch; | - | ||||||||||||
| 83 | bool magic; | - | ||||||||||||
| 84 | }; | - | ||||||||||||
| 85 | - | |||||||||||||
| 86 | class QBoxLayoutPrivate : public QLayoutPrivate | - | ||||||||||||
| 87 | { | - | ||||||||||||
| 88 | Q_DECLARE_PUBLIC(QBoxLayout) | - | ||||||||||||
| 89 | public: | - | ||||||||||||
| 90 | QBoxLayoutPrivate() : hfwWidth(-1), dirty(true), spacing(-1) { } never executed: end of block | 0 | ||||||||||||
| 91 | ~QBoxLayoutPrivate(); | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | void setDirty() { | - | ||||||||||||
| 94 | geomArray.clear(); | - | ||||||||||||
| 95 | hfwWidth = -1; | - | ||||||||||||
| 96 | hfwHeight = -1; | - | ||||||||||||
| 97 | dirty = true; | - | ||||||||||||
| 98 | } never executed: end of block | 0 | ||||||||||||
| 99 | - | |||||||||||||
| 100 | QList<QBoxLayoutItem *> list; | - | ||||||||||||
| 101 | QVector<QLayoutStruct> geomArray; | - | ||||||||||||
| 102 | int hfwWidth; | - | ||||||||||||
| 103 | int hfwHeight; | - | ||||||||||||
| 104 | int hfwMinHeight; | - | ||||||||||||
| 105 | QSize sizeHint; | - | ||||||||||||
| 106 | QSize minSize; | - | ||||||||||||
| 107 | QSize maxSize; | - | ||||||||||||
| 108 | int leftMargin, topMargin, rightMargin, bottomMargin; | - | ||||||||||||
| 109 | Qt::Orientations expanding; | - | ||||||||||||
| 110 | uint hasHfw : 1; | - | ||||||||||||
| 111 | uint dirty : 1; | - | ||||||||||||
| 112 | QBoxLayout::Direction dir; | - | ||||||||||||
| 113 | int spacing; | - | ||||||||||||
| 114 | - | |||||||||||||
| 115 | inline void deleteAll() { while (!list.isEmpty()) delete list.takeFirst(); } never executed: end of blocknever executed: delete list.takeFirst();
| 0 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | void setupGeom(); | - | ||||||||||||
| 118 | void calcHfw(int); | - | ||||||||||||
| 119 | - | |||||||||||||
| 120 | void effectiveMargins(int *left, int *top, int *right, int *bottom) const; | - | ||||||||||||
| 121 | QLayoutItem* replaceAt(int index, QLayoutItem*) Q_DECL_OVERRIDE; | - | ||||||||||||
| 122 | }; | - | ||||||||||||
| 123 | - | |||||||||||||
| 124 | QBoxLayoutPrivate::~QBoxLayoutPrivate() | - | ||||||||||||
| 125 | { | - | ||||||||||||
| 126 | } | - | ||||||||||||
| 127 | - | |||||||||||||
| 128 | static inline bool horz(QBoxLayout::Direction dir) | - | ||||||||||||
| 129 | { | - | ||||||||||||
| 130 | return dir == QBoxLayout::RightToLeft || dir == QBoxLayout::LeftToRight; never executed: return dir == QBoxLayout::RightToLeft || dir == QBoxLayout::LeftToRight;
| 0 | ||||||||||||
| 131 | } | - | ||||||||||||
| 132 | - | |||||||||||||
| 133 | /** | - | ||||||||||||
| 134 | * The purpose of this function is to make sure that widgets are not laid out outside its layout. | - | ||||||||||||
| 135 | * E.g. the layoutItemRect margins are only meant to take of the surrounding margins/spacings. | - | ||||||||||||
| 136 | * However, if the margin is 0, it can easily cover the area of a widget above it. | - | ||||||||||||
| 137 | */ | - | ||||||||||||
| 138 | void QBoxLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *bottom) const | - | ||||||||||||
| 139 | { | - | ||||||||||||
| 140 | int l = leftMargin; | - | ||||||||||||
| 141 | int t = topMargin; | - | ||||||||||||
| 142 | int r = rightMargin; | - | ||||||||||||
| 143 | int b = bottomMargin; | - | ||||||||||||
| 144 | #ifdef Q_OS_MAC | - | ||||||||||||
| 145 | Q_Q(const QBoxLayout); | - | ||||||||||||
| 146 | if (horz(dir)) { | - | ||||||||||||
| 147 | QBoxLayoutItem *leftBox = 0; | - | ||||||||||||
| 148 | QBoxLayoutItem *rightBox = 0; | - | ||||||||||||
| 149 | - | |||||||||||||
| 150 | if (left || right) { | - | ||||||||||||
| 151 | leftBox = list.value(0); | - | ||||||||||||
| 152 | rightBox = list.value(list.count() - 1); | - | ||||||||||||
| 153 | if (dir == QBoxLayout::RightToLeft) | - | ||||||||||||
| 154 | qSwap(leftBox, rightBox); | - | ||||||||||||
| 155 | - | |||||||||||||
| 156 | int leftDelta = 0; | - | ||||||||||||
| 157 | int rightDelta = 0; | - | ||||||||||||
| 158 | if (leftBox) { | - | ||||||||||||
| 159 | QLayoutItem *itm = leftBox->item; | - | ||||||||||||
| 160 | if (QWidget *w = itm->widget()) | - | ||||||||||||
| 161 | leftDelta = itm->geometry().left() - w->geometry().left(); | - | ||||||||||||
| 162 | } | - | ||||||||||||
| 163 | if (rightBox) { | - | ||||||||||||
| 164 | QLayoutItem *itm = rightBox->item; | - | ||||||||||||
| 165 | if (QWidget *w = itm->widget()) | - | ||||||||||||
| 166 | rightDelta = w->geometry().right() - itm->geometry().right(); | - | ||||||||||||
| 167 | } | - | ||||||||||||
| 168 | QWidget *w = q->parentWidget(); | - | ||||||||||||
| 169 | Qt::LayoutDirection layoutDirection = w ? w->layoutDirection() : QApplication::layoutDirection(); | - | ||||||||||||
| 170 | if (layoutDirection == Qt::RightToLeft) | - | ||||||||||||
| 171 | qSwap(leftDelta, rightDelta); | - | ||||||||||||
| 172 | - | |||||||||||||
| 173 | l = qMax(l, leftDelta); | - | ||||||||||||
| 174 | r = qMax(r, rightDelta); | - | ||||||||||||
| 175 | } | - | ||||||||||||
| 176 | - | |||||||||||||
| 177 | int count = top || bottom ? list.count() : 0; | - | ||||||||||||
| 178 | for (int i = 0; i < count; ++i) { | - | ||||||||||||
| 179 | QBoxLayoutItem *box = list.at(i); | - | ||||||||||||
| 180 | QLayoutItem *itm = box->item; | - | ||||||||||||
| 181 | QWidget *w = itm->widget(); | - | ||||||||||||
| 182 | if (w) { | - | ||||||||||||
| 183 | QRect lir = itm->geometry(); | - | ||||||||||||
| 184 | QRect wr = w->geometry(); | - | ||||||||||||
| 185 | if (top) | - | ||||||||||||
| 186 | t = qMax(t, lir.top() - wr.top()); | - | ||||||||||||
| 187 | if (bottom) | - | ||||||||||||
| 188 | b = qMax(b, wr.bottom() - lir.bottom()); | - | ||||||||||||
| 189 | } | - | ||||||||||||
| 190 | } | - | ||||||||||||
| 191 | } else { // vertical layout | - | ||||||||||||
| 192 | QBoxLayoutItem *topBox = 0; | - | ||||||||||||
| 193 | QBoxLayoutItem *bottomBox = 0; | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | if (top || bottom) { | - | ||||||||||||
| 196 | topBox = list.value(0); | - | ||||||||||||
| 197 | bottomBox = list.value(list.count() - 1); | - | ||||||||||||
| 198 | if (dir == QBoxLayout::BottomToTop) { | - | ||||||||||||
| 199 | qSwap(topBox, bottomBox); | - | ||||||||||||
| 200 | } | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | if (top && topBox) { | - | ||||||||||||
| 203 | QLayoutItem *itm = topBox->item; | - | ||||||||||||
| 204 | QWidget *w = itm->widget(); | - | ||||||||||||
| 205 | if (w) | - | ||||||||||||
| 206 | t = qMax(t, itm->geometry().top() - w->geometry().top()); | - | ||||||||||||
| 207 | } | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | if (bottom && bottomBox) { | - | ||||||||||||
| 210 | QLayoutItem *itm = bottomBox->item; | - | ||||||||||||
| 211 | QWidget *w = itm->widget(); | - | ||||||||||||
| 212 | if (w) | - | ||||||||||||
| 213 | b = qMax(b, w->geometry().bottom() - itm->geometry().bottom()); | - | ||||||||||||
| 214 | } | - | ||||||||||||
| 215 | } | - | ||||||||||||
| 216 | - | |||||||||||||
| 217 | int count = left || right ? list.count() : 0; | - | ||||||||||||
| 218 | for (int i = 0; i < count; ++i) { | - | ||||||||||||
| 219 | QBoxLayoutItem *box = list.at(i); | - | ||||||||||||
| 220 | QLayoutItem *itm = box->item; | - | ||||||||||||
| 221 | QWidget *w = itm->widget(); | - | ||||||||||||
| 222 | if (w) { | - | ||||||||||||
| 223 | QRect lir = itm->geometry(); | - | ||||||||||||
| 224 | QRect wr = w->geometry(); | - | ||||||||||||
| 225 | if (left) | - | ||||||||||||
| 226 | l = qMax(l, lir.left() - wr.left()); | - | ||||||||||||
| 227 | if (right) | - | ||||||||||||
| 228 | r = qMax(r, wr.right() - lir.right()); | - | ||||||||||||
| 229 | } | - | ||||||||||||
| 230 | } | - | ||||||||||||
| 231 | } | - | ||||||||||||
| 232 | #endif | - | ||||||||||||
| 233 | if (left)
| 0 | ||||||||||||
| 234 | *left = l; never executed: *left = l; | 0 | ||||||||||||
| 235 | if (top)
| 0 | ||||||||||||
| 236 | *top = t; never executed: *top = t; | 0 | ||||||||||||
| 237 | if (right)
| 0 | ||||||||||||
| 238 | *right = r; never executed: *right = r; | 0 | ||||||||||||
| 239 | if (bottom)
| 0 | ||||||||||||
| 240 | *bottom = b; never executed: *bottom = b; | 0 | ||||||||||||
| 241 | } never executed: end of block | 0 | ||||||||||||
| 242 | - | |||||||||||||
| 243 | - | |||||||||||||
| 244 | /* | - | ||||||||||||
| 245 | Initializes the data structure needed by qGeomCalc and | - | ||||||||||||
| 246 | recalculates max/min and size hint. | - | ||||||||||||
| 247 | */ | - | ||||||||||||
| 248 | void QBoxLayoutPrivate::setupGeom() | - | ||||||||||||
| 249 | { | - | ||||||||||||
| 250 | if (!dirty)
| 0 | ||||||||||||
| 251 | return; never executed: return; | 0 | ||||||||||||
| 252 | - | |||||||||||||
| 253 | Q_Q(QBoxLayout); | - | ||||||||||||
| 254 | int maxw = horz(dir) ? 0 : QLAYOUTSIZE_MAX;
| 0 | ||||||||||||
| 255 | int maxh = horz(dir) ? QLAYOUTSIZE_MAX : 0;
| 0 | ||||||||||||
| 256 | int minw = 0; | - | ||||||||||||
| 257 | int minh = 0; | - | ||||||||||||
| 258 | int hintw = 0; | - | ||||||||||||
| 259 | int hinth = 0; | - | ||||||||||||
| 260 | - | |||||||||||||
| 261 | bool horexp = false; | - | ||||||||||||
| 262 | bool verexp = false; | - | ||||||||||||
| 263 | - | |||||||||||||
| 264 | hasHfw = false; | - | ||||||||||||
| 265 | - | |||||||||||||
| 266 | int n = list.count(); | - | ||||||||||||
| 267 | geomArray.clear(); | - | ||||||||||||
| 268 | QVector<QLayoutStruct> a(n); | - | ||||||||||||
| 269 | - | |||||||||||||
| 270 | QSizePolicy::ControlTypes controlTypes1; | - | ||||||||||||
| 271 | QSizePolicy::ControlTypes controlTypes2; | - | ||||||||||||
| 272 | int fixedSpacing = q->spacing(); | - | ||||||||||||
| 273 | int previousNonEmptyIndex = -1; | - | ||||||||||||
| 274 | - | |||||||||||||
| 275 | QStyle *style = 0; | - | ||||||||||||
| 276 | if (fixedSpacing < 0) {
| 0 | ||||||||||||
| 277 | if (QWidget *parentWidget = q->parentWidget())
| 0 | ||||||||||||
| 278 | style = parentWidget->style(); never executed: style = parentWidget->style(); | 0 | ||||||||||||
| 279 | } never executed: end of block | 0 | ||||||||||||
| 280 | - | |||||||||||||
| 281 | for (int i = 0; i < n; i++) {
| 0 | ||||||||||||
| 282 | QBoxLayoutItem *box = list.at(i); | - | ||||||||||||
| 283 | QSize max = box->item->maximumSize(); | - | ||||||||||||
| 284 | QSize min = box->item->minimumSize(); | - | ||||||||||||
| 285 | QSize hint = box->item->sizeHint(); | - | ||||||||||||
| 286 | Qt::Orientations exp = box->item->expandingDirections(); | - | ||||||||||||
| 287 | bool empty = box->item->isEmpty(); | - | ||||||||||||
| 288 | int spacing = 0; | - | ||||||||||||
| 289 | - | |||||||||||||
| 290 | if (!empty) {
| 0 | ||||||||||||
| 291 | if (fixedSpacing >= 0) {
| 0 | ||||||||||||
| 292 | spacing = (previousNonEmptyIndex >= 0) ? fixedSpacing : 0;
| 0 | ||||||||||||
| 293 | #ifdef Q_OS_MAC | - | ||||||||||||
| 294 | if (!horz(dir) && previousNonEmptyIndex >= 0) { | - | ||||||||||||
| 295 | QBoxLayoutItem *sibling = (dir == QBoxLayout::TopToBottom ? box : list.at(previousNonEmptyIndex)); | - | ||||||||||||
| 296 | if (sibling) { | - | ||||||||||||
| 297 | QWidget *wid = sibling->item->widget(); | - | ||||||||||||
| 298 | if (wid) | - | ||||||||||||
| 299 | spacing = qMax(spacing, sibling->item->geometry().top() - wid->geometry().top()); | - | ||||||||||||
| 300 | } | - | ||||||||||||
| 301 | } | - | ||||||||||||
| 302 | #endif | - | ||||||||||||
| 303 | } else { never executed: end of block | 0 | ||||||||||||
| 304 | controlTypes1 = controlTypes2; | - | ||||||||||||
| 305 | controlTypes2 = box->item->controlTypes(); | - | ||||||||||||
| 306 | if (previousNonEmptyIndex >= 0) {
| 0 | ||||||||||||
| 307 | QSizePolicy::ControlTypes actual1 = controlTypes1; | - | ||||||||||||
| 308 | QSizePolicy::ControlTypes actual2 = controlTypes2; | - | ||||||||||||
| 309 | if (dir == QBoxLayout::RightToLeft || dir == QBoxLayout::BottomToTop)
| 0 | ||||||||||||
| 310 | qSwap(actual1, actual2); never executed: qSwap(actual1, actual2); | 0 | ||||||||||||
| 311 | - | |||||||||||||
| 312 | if (style) {
| 0 | ||||||||||||
| 313 | spacing = style->combinedLayoutSpacing(actual1, actual2, | - | ||||||||||||
| 314 | horz(dir) ? Qt::Horizontal : Qt::Vertical, | - | ||||||||||||
| 315 | 0, q->parentWidget()); | - | ||||||||||||
| 316 | if (spacing < 0)
| 0 | ||||||||||||
| 317 | spacing = 0; never executed: spacing = 0; | 0 | ||||||||||||
| 318 | } never executed: end of block | 0 | ||||||||||||
| 319 | } never executed: end of block | 0 | ||||||||||||
| 320 | } never executed: end of block | 0 | ||||||||||||
| 321 | - | |||||||||||||
| 322 | if (previousNonEmptyIndex >= 0)
| 0 | ||||||||||||
| 323 | a[previousNonEmptyIndex].spacing = spacing; never executed: a[previousNonEmptyIndex].spacing = spacing; | 0 | ||||||||||||
| 324 | previousNonEmptyIndex = i; | - | ||||||||||||
| 325 | } never executed: end of block | 0 | ||||||||||||
| 326 | - | |||||||||||||
| 327 | bool ignore = empty && box->item->widget(); // ignore hidden widgets
| 0 | ||||||||||||
| 328 | bool dummy = true; | - | ||||||||||||
| 329 | if (horz(dir)) {
| 0 | ||||||||||||
| 330 | bool expand = (exp & Qt::Horizontal || box->stretch > 0);
| 0 | ||||||||||||
| 331 | horexp = horexp || expand;
| 0 | ||||||||||||
| 332 | maxw += spacing + max.width(); | - | ||||||||||||
| 333 | minw += spacing + min.width(); | - | ||||||||||||
| 334 | hintw += spacing + hint.width(); | - | ||||||||||||
| 335 | if (!ignore)
| 0 | ||||||||||||
| 336 | qMaxExpCalc(maxh, verexp, dummy, never executed: qMaxExpCalc(maxh, verexp, dummy, max.height(), exp & Qt::Vertical, box->item->isEmpty()); | 0 | ||||||||||||
| 337 | max.height(), exp & Qt::Vertical, box->item->isEmpty()); never executed: qMaxExpCalc(maxh, verexp, dummy, max.height(), exp & Qt::Vertical, box->item->isEmpty()); | 0 | ||||||||||||
| 338 | minh = qMax(minh, min.height()); | - | ||||||||||||
| 339 | hinth = qMax(hinth, hint.height()); | - | ||||||||||||
| 340 | - | |||||||||||||
| 341 | a[i].sizeHint = hint.width(); | - | ||||||||||||
| 342 | a[i].maximumSize = max.width(); | - | ||||||||||||
| 343 | a[i].minimumSize = min.width(); | - | ||||||||||||
| 344 | a[i].expansive = expand; | - | ||||||||||||
| 345 | a[i].stretch = box->stretch ? box->stretch : box->hStretch();
| 0 | ||||||||||||
| 346 | } else { never executed: end of block | 0 | ||||||||||||
| 347 | bool expand = (exp & Qt::Vertical || box->stretch > 0);
| 0 | ||||||||||||
| 348 | verexp = verexp || expand;
| 0 | ||||||||||||
| 349 | maxh += spacing + max.height(); | - | ||||||||||||
| 350 | minh += spacing + min.height(); | - | ||||||||||||
| 351 | hinth += spacing + hint.height(); | - | ||||||||||||
| 352 | if (!ignore)
| 0 | ||||||||||||
| 353 | qMaxExpCalc(maxw, horexp, dummy, never executed: qMaxExpCalc(maxw, horexp, dummy, max.width(), exp & Qt::Horizontal, box->item->isEmpty()); | 0 | ||||||||||||
| 354 | max.width(), exp & Qt::Horizontal, box->item->isEmpty()); never executed: qMaxExpCalc(maxw, horexp, dummy, max.width(), exp & Qt::Horizontal, box->item->isEmpty()); | 0 | ||||||||||||
| 355 | minw = qMax(minw, min.width()); | - | ||||||||||||
| 356 | hintw = qMax(hintw, hint.width()); | - | ||||||||||||
| 357 | - | |||||||||||||
| 358 | a[i].sizeHint = hint.height(); | - | ||||||||||||
| 359 | a[i].maximumSize = max.height(); | - | ||||||||||||
| 360 | a[i].minimumSize = min.height(); | - | ||||||||||||
| 361 | a[i].expansive = expand; | - | ||||||||||||
| 362 | a[i].stretch = box->stretch ? box->stretch : box->vStretch();
| 0 | ||||||||||||
| 363 | } never executed: end of block | 0 | ||||||||||||
| 364 | - | |||||||||||||
| 365 | a[i].empty = empty; | - | ||||||||||||
| 366 | a[i].spacing = 0; // might be initialized with a non-zero value in a later iteration | - | ||||||||||||
| 367 | hasHfw = hasHfw || box->item->hasHeightForWidth();
| 0 | ||||||||||||
| 368 | } never executed: end of block | 0 | ||||||||||||
| 369 | - | |||||||||||||
| 370 | geomArray = a; | - | ||||||||||||
| 371 | - | |||||||||||||
| 372 | expanding = (Qt::Orientations) | - | ||||||||||||
| 373 | ((horexp ? Qt::Horizontal : 0)
| 0 | ||||||||||||
| 374 | | (verexp ? Qt::Vertical : 0)); | - | ||||||||||||
| 375 | - | |||||||||||||
| 376 | minSize = QSize(minw, minh); | - | ||||||||||||
| 377 | maxSize = QSize(maxw, maxh).expandedTo(minSize); | - | ||||||||||||
| 378 | sizeHint = QSize(hintw, hinth).expandedTo(minSize).boundedTo(maxSize); | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - | ||||||||||||
| 381 | int left, top, right, bottom; | - | ||||||||||||
| 382 | effectiveMargins(&left, &top, &right, &bottom); | - | ||||||||||||
| 383 | QSize extra(left + right, top + bottom); | - | ||||||||||||
| 384 | - | |||||||||||||
| 385 | minSize += extra; | - | ||||||||||||
| 386 | maxSize += extra; | - | ||||||||||||
| 387 | sizeHint += extra; | - | ||||||||||||
| 388 | - | |||||||||||||
| 389 | dirty = false; | - | ||||||||||||
| 390 | } never executed: end of block | 0 | ||||||||||||
| 391 | - | |||||||||||||
| 392 | /* | - | ||||||||||||
| 393 | Calculates and stores the preferred height given the width \a w. | - | ||||||||||||
| 394 | */ | - | ||||||||||||
| 395 | void QBoxLayoutPrivate::calcHfw(int w) | - | ||||||||||||
| 396 | { | - | ||||||||||||
| 397 | QVector<QLayoutStruct> &a = geomArray; | - | ||||||||||||
| 398 | int n = a.count(); | - | ||||||||||||
| 399 | int h = 0; | - | ||||||||||||
| 400 | int mh = 0; | - | ||||||||||||
| 401 | - | |||||||||||||
| 402 | Q_ASSERT(n == list.size()); | - | ||||||||||||
| 403 | - | |||||||||||||
| 404 | if (horz(dir)) {
| 0 | ||||||||||||
| 405 | qGeomCalc(a, 0, n, 0, w); | - | ||||||||||||
| 406 | for (int i = 0; i < n; i++) {
| 0 | ||||||||||||
| 407 | QBoxLayoutItem *box = list.at(i); | - | ||||||||||||
| 408 | h = qMax(h, box->hfw(a.at(i).size)); | - | ||||||||||||
| 409 | mh = qMax(mh, box->mhfw(a.at(i).size)); | - | ||||||||||||
| 410 | } never executed: end of block | 0 | ||||||||||||
| 411 | } else { never executed: end of block | 0 | ||||||||||||
| 412 | for (int i = 0; i < n; ++i) {
| 0 | ||||||||||||
| 413 | QBoxLayoutItem *box = list.at(i); | - | ||||||||||||
| 414 | int spacing = a.at(i).spacing; | - | ||||||||||||
| 415 | h += box->hfw(w); | - | ||||||||||||
| 416 | mh += box->mhfw(w); | - | ||||||||||||
| 417 | h += spacing; | - | ||||||||||||
| 418 | mh += spacing; | - | ||||||||||||
| 419 | } never executed: end of block | 0 | ||||||||||||
| 420 | } never executed: end of block | 0 | ||||||||||||
| 421 | hfwWidth = w; | - | ||||||||||||
| 422 | hfwHeight = h; | - | ||||||||||||
| 423 | hfwMinHeight = mh; | - | ||||||||||||
| 424 | } never executed: end of block | 0 | ||||||||||||
| 425 | - | |||||||||||||
| 426 | QLayoutItem* QBoxLayoutPrivate::replaceAt(int index, QLayoutItem *item) | - | ||||||||||||
| 427 | { | - | ||||||||||||
| 428 | Q_Q(QBoxLayout); | - | ||||||||||||
| 429 | if (!item)
| 0 | ||||||||||||
| 430 | return 0; never executed: return 0; | 0 | ||||||||||||
| 431 | QBoxLayoutItem *b = list.value(index); | - | ||||||||||||
| 432 | if (!b)
| 0 | ||||||||||||
| 433 | return 0; never executed: return 0; | 0 | ||||||||||||
| 434 | QLayoutItem *r = b->item; | - | ||||||||||||
| 435 | - | |||||||||||||
| 436 | b->item = item; | - | ||||||||||||
| 437 | q->invalidate(); | - | ||||||||||||
| 438 | return r; never executed: return r; | 0 | ||||||||||||
| 439 | } | - | ||||||||||||
| 440 | - | |||||||||||||
| 441 | - | |||||||||||||
| 442 | /*! | - | ||||||||||||
| 443 | \class QBoxLayout | - | ||||||||||||
| 444 | - | |||||||||||||
| 445 | \brief The QBoxLayout class lines up child widgets horizontally or | - | ||||||||||||
| 446 | vertically. | - | ||||||||||||
| 447 | - | |||||||||||||
| 448 | \ingroup geomanagement | - | ||||||||||||
| 449 | \inmodule QtWidgets | - | ||||||||||||
| 450 | - | |||||||||||||
| 451 | QBoxLayout takes the space it gets (from its parent layout or from | - | ||||||||||||
| 452 | the parentWidget()), divides it up into a row of boxes, and makes | - | ||||||||||||
| 453 | each managed widget fill one box. | - | ||||||||||||
| 454 | - | |||||||||||||
| 455 | \image qhboxlayout-with-5-children.png Horizontal box layout with five child widgets | - | ||||||||||||
| 456 | - | |||||||||||||
| 457 | If the QBoxLayout's orientation is Qt::Horizontal the boxes are | - | ||||||||||||
| 458 | placed in a row, with suitable sizes. Each widget (or other box) | - | ||||||||||||
| 459 | will get at least its minimum size and at most its maximum size. | - | ||||||||||||
| 460 | Any excess space is shared according to the stretch factors (more | - | ||||||||||||
| 461 | about that below). | - | ||||||||||||
| 462 | - | |||||||||||||
| 463 | \image qvboxlayout-with-5-children.png Vertical box layout with five child widgets | - | ||||||||||||
| 464 | - | |||||||||||||
| 465 | If the QBoxLayout's orientation is Qt::Vertical, the boxes are | - | ||||||||||||
| 466 | placed in a column, again with suitable sizes. | - | ||||||||||||
| 467 | - | |||||||||||||
| 468 | The easiest way to create a QBoxLayout is to use one of the | - | ||||||||||||
| 469 | convenience classes, e.g. QHBoxLayout (for Qt::Horizontal boxes) | - | ||||||||||||
| 470 | or QVBoxLayout (for Qt::Vertical boxes). You can also use the | - | ||||||||||||
| 471 | QBoxLayout constructor directly, specifying its direction as | - | ||||||||||||
| 472 | LeftToRight, RightToLeft, TopToBottom, or BottomToTop. | - | ||||||||||||
| 473 | - | |||||||||||||
| 474 | If the QBoxLayout is not the top-level layout (i.e. it is not | - | ||||||||||||
| 475 | managing all of the widget's area and children), you must add it | - | ||||||||||||
| 476 | to its parent layout before you can do anything with it. The | - | ||||||||||||
| 477 | normal way to add a layout is by calling | - | ||||||||||||
| 478 | parentLayout-\>addLayout(). | - | ||||||||||||
| 479 | - | |||||||||||||
| 480 | Once you have done this, you can add boxes to the QBoxLayout using | - | ||||||||||||
| 481 | one of four functions: | - | ||||||||||||
| 482 | - | |||||||||||||
| 483 | \list | - | ||||||||||||
| 484 | \li addWidget() to add a widget to the QBoxLayout and set the | - | ||||||||||||
| 485 | widget's stretch factor. (The stretch factor is along the row of | - | ||||||||||||
| 486 | boxes.) | - | ||||||||||||
| 487 | - | |||||||||||||
| 488 | \li addSpacing() to create an empty box; this is one of the | - | ||||||||||||
| 489 | functions you use to create nice and spacious dialogs. See below | - | ||||||||||||
| 490 | for ways to set margins. | - | ||||||||||||
| 491 | - | |||||||||||||
| 492 | \li addStretch() to create an empty, stretchable box. | - | ||||||||||||
| 493 | - | |||||||||||||
| 494 | \li addLayout() to add a box containing another QLayout to the row | - | ||||||||||||
| 495 | and set that layout's stretch factor. | - | ||||||||||||
| 496 | \endlist | - | ||||||||||||
| 497 | - | |||||||||||||
| 498 | Use insertWidget(), insertSpacing(), insertStretch() or | - | ||||||||||||
| 499 | insertLayout() to insert a box at a specified position in the | - | ||||||||||||
| 500 | layout. | - | ||||||||||||
| 501 | - | |||||||||||||
| 502 | QBoxLayout also includes two margin widths: | - | ||||||||||||
| 503 | - | |||||||||||||
| 504 | \list | - | ||||||||||||
| 505 | \li setContentsMargins() sets the width of the outer border on | - | ||||||||||||
| 506 | each side of the widget. This is the width of the reserved space | - | ||||||||||||
| 507 | along each of the QBoxLayout's four sides. | - | ||||||||||||
| 508 | \li setSpacing() sets the width between neighboring boxes. (You | - | ||||||||||||
| 509 | can use addSpacing() to get more space at a particular spot.) | - | ||||||||||||
| 510 | \endlist | - | ||||||||||||
| 511 | - | |||||||||||||
| 512 | The margin default is provided by the style. The default margin | - | ||||||||||||
| 513 | most Qt styles specify is 9 for child widgets and 11 for windows. | - | ||||||||||||
| 514 | The spacing defaults to the same as the margin width for a | - | ||||||||||||
| 515 | top-level layout, or to the same as the parent layout. | - | ||||||||||||
| 516 | - | |||||||||||||
| 517 | To remove a widget from a layout, call removeWidget(). Calling | - | ||||||||||||
| 518 | QWidget::hide() on a widget also effectively removes the widget | - | ||||||||||||
| 519 | from the layout until QWidget::show() is called. | - | ||||||||||||
| 520 | - | |||||||||||||
| 521 | You will almost always want to use QVBoxLayout and QHBoxLayout | - | ||||||||||||
| 522 | rather than QBoxLayout because of their convenient constructors. | - | ||||||||||||
| 523 | - | |||||||||||||
| 524 | \sa QGridLayout, QStackedLayout, {Layout Management} | - | ||||||||||||
| 525 | */ | - | ||||||||||||
| 526 | - | |||||||||||||
| 527 | /*! | - | ||||||||||||
| 528 | \enum QBoxLayout::Direction | - | ||||||||||||
| 529 | - | |||||||||||||
| 530 | This type is used to determine the direction of a box layout. | - | ||||||||||||
| 531 | - | |||||||||||||
| 532 | \value LeftToRight Horizontal from left to right. | - | ||||||||||||
| 533 | \value RightToLeft Horizontal from right to left. | - | ||||||||||||
| 534 | \value TopToBottom Vertical from top to bottom. | - | ||||||||||||
| 535 | \value BottomToTop Vertical from bottom to top. | - | ||||||||||||
| 536 | - | |||||||||||||
| 537 | \omitvalue Down | - | ||||||||||||
| 538 | \omitvalue Up | - | ||||||||||||
| 539 | */ | - | ||||||||||||
| 540 | - | |||||||||||||
| 541 | /*! | - | ||||||||||||
| 542 | Constructs a new QBoxLayout with direction \a dir and parent widget \a | - | ||||||||||||
| 543 | parent. | - | ||||||||||||
| 544 | - | |||||||||||||
| 545 | \sa direction() | - | ||||||||||||
| 546 | */ | - | ||||||||||||
| 547 | QBoxLayout::QBoxLayout(Direction dir, QWidget *parent) | - | ||||||||||||
| 548 | : QLayout(*new QBoxLayoutPrivate, 0, parent) | - | ||||||||||||
| 549 | { | - | ||||||||||||
| 550 | Q_D(QBoxLayout); | - | ||||||||||||
| 551 | d->dir = dir; | - | ||||||||||||
| 552 | } never executed: end of block | 0 | ||||||||||||
| 553 | - | |||||||||||||
| 554 | - | |||||||||||||
| 555 | - | |||||||||||||
| 556 | /*! | - | ||||||||||||
| 557 | Destroys this box layout. | - | ||||||||||||
| 558 | - | |||||||||||||
| 559 | The layout's widgets aren't destroyed. | - | ||||||||||||
| 560 | */ | - | ||||||||||||
| 561 | QBoxLayout::~QBoxLayout() | - | ||||||||||||
| 562 | { | - | ||||||||||||
| 563 | Q_D(QBoxLayout); | - | ||||||||||||
| 564 | d->deleteAll(); // must do it before QObject deletes children, so can't be in ~QBoxLayoutPrivate | - | ||||||||||||
| 565 | } never executed: end of block | 0 | ||||||||||||
| 566 | - | |||||||||||||
| 567 | /*! | - | ||||||||||||
| 568 | Reimplements QLayout::spacing(). If the spacing property is | - | ||||||||||||
| 569 | valid, that value is returned. Otherwise, a value for the spacing | - | ||||||||||||
| 570 | property is computed and returned. Since layout spacing in a widget | - | ||||||||||||
| 571 | is style dependent, if the parent is a widget, it queries the style | - | ||||||||||||
| 572 | for the (horizontal or vertical) spacing of the layout. Otherwise, | - | ||||||||||||
| 573 | the parent is a layout, and it queries the parent layout for the | - | ||||||||||||
| 574 | spacing(). | - | ||||||||||||
| 575 | - | |||||||||||||
| 576 | \sa QLayout::spacing(), setSpacing() | - | ||||||||||||
| 577 | */ | - | ||||||||||||
| 578 | int QBoxLayout::spacing() const | - | ||||||||||||
| 579 | { | - | ||||||||||||
| 580 | Q_D(const QBoxLayout); | - | ||||||||||||
| 581 | if (d->spacing >=0) {
| 0 | ||||||||||||
| 582 | return d->spacing; never executed: return d->spacing; | 0 | ||||||||||||
| 583 | } else { | - | ||||||||||||
| 584 | return qSmartSpacing(this, d->dir == LeftToRight || d->dir == RightToLeft never executed: return qSmartSpacing(this, d->dir == LeftToRight || d->dir == RightToLeft ? QStyle::PM_LayoutHorizontalSpacing : QStyle::PM_LayoutVerticalSpacing); | 0 | ||||||||||||
| 585 | ? QStyle::PM_LayoutHorizontalSpacing never executed: return qSmartSpacing(this, d->dir == LeftToRight || d->dir == RightToLeft ? QStyle::PM_LayoutHorizontalSpacing : QStyle::PM_LayoutVerticalSpacing); | 0 | ||||||||||||
| 586 | : QStyle::PM_LayoutVerticalSpacing); never executed: return qSmartSpacing(this, d->dir == LeftToRight || d->dir == RightToLeft ? QStyle::PM_LayoutHorizontalSpacing : QStyle::PM_LayoutVerticalSpacing); | 0 | ||||||||||||
| 587 | } | - | ||||||||||||
| 588 | } | - | ||||||||||||
| 589 | - | |||||||||||||
| 590 | /*! | - | ||||||||||||
| 591 | Reimplements QLayout::setSpacing(). Sets the spacing | - | ||||||||||||
| 592 | property to \a spacing. | - | ||||||||||||
| 593 | - | |||||||||||||
| 594 | \sa QLayout::setSpacing(), spacing() | - | ||||||||||||
| 595 | */ | - | ||||||||||||
| 596 | void QBoxLayout::setSpacing(int spacing) | - | ||||||||||||
| 597 | { | - | ||||||||||||
| 598 | Q_D(QBoxLayout); | - | ||||||||||||
| 599 | d->spacing = spacing; | - | ||||||||||||
| 600 | invalidate(); | - | ||||||||||||
| 601 | } never executed: end of block | 0 | ||||||||||||
| 602 | - | |||||||||||||
| 603 | /*! | - | ||||||||||||
| 604 | \reimp | - | ||||||||||||
| 605 | */ | - | ||||||||||||
| 606 | QSize QBoxLayout::sizeHint() const | - | ||||||||||||
| 607 | { | - | ||||||||||||
| 608 | Q_D(const QBoxLayout); | - | ||||||||||||
| 609 | if (d->dirty)
| 0 | ||||||||||||
| 610 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); never executed: const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | 0 | ||||||||||||
| 611 | return d->sizeHint; never executed: return d->sizeHint; | 0 | ||||||||||||
| 612 | } | - | ||||||||||||
| 613 | - | |||||||||||||
| 614 | /*! | - | ||||||||||||
| 615 | \reimp | - | ||||||||||||
| 616 | */ | - | ||||||||||||
| 617 | QSize QBoxLayout::minimumSize() const | - | ||||||||||||
| 618 | { | - | ||||||||||||
| 619 | Q_D(const QBoxLayout); | - | ||||||||||||
| 620 | if (d->dirty)
| 0 | ||||||||||||
| 621 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); never executed: const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | 0 | ||||||||||||
| 622 | return d->minSize; never executed: return d->minSize; | 0 | ||||||||||||
| 623 | } | - | ||||||||||||
| 624 | - | |||||||||||||
| 625 | /*! | - | ||||||||||||
| 626 | \reimp | - | ||||||||||||
| 627 | */ | - | ||||||||||||
| 628 | QSize QBoxLayout::maximumSize() const | - | ||||||||||||
| 629 | { | - | ||||||||||||
| 630 | Q_D(const QBoxLayout); | - | ||||||||||||
| 631 | if (d->dirty)
| 0 | ||||||||||||
| 632 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); never executed: const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | 0 | ||||||||||||
| 633 | - | |||||||||||||
| 634 | QSize s = d->maxSize.boundedTo(QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX)); | - | ||||||||||||
| 635 | - | |||||||||||||
| 636 | if (alignment() & Qt::AlignHorizontal_Mask)
| 0 | ||||||||||||
| 637 | s.setWidth(QLAYOUTSIZE_MAX); never executed: s.setWidth(QLAYOUTSIZE_MAX); | 0 | ||||||||||||
| 638 | if (alignment() & Qt::AlignVertical_Mask)
| 0 | ||||||||||||
| 639 | s.setHeight(QLAYOUTSIZE_MAX); never executed: s.setHeight(QLAYOUTSIZE_MAX); | 0 | ||||||||||||
| 640 | return s; never executed: return s; | 0 | ||||||||||||
| 641 | } | - | ||||||||||||
| 642 | - | |||||||||||||
| 643 | /*! | - | ||||||||||||
| 644 | \reimp | - | ||||||||||||
| 645 | */ | - | ||||||||||||
| 646 | bool QBoxLayout::hasHeightForWidth() const | - | ||||||||||||
| 647 | { | - | ||||||||||||
| 648 | Q_D(const QBoxLayout); | - | ||||||||||||
| 649 | if (d->dirty)
| 0 | ||||||||||||
| 650 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); never executed: const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | 0 | ||||||||||||
| 651 | return d->hasHfw; never executed: return d->hasHfw; | 0 | ||||||||||||
| 652 | } | - | ||||||||||||
| 653 | - | |||||||||||||
| 654 | /*! | - | ||||||||||||
| 655 | \reimp | - | ||||||||||||
| 656 | */ | - | ||||||||||||
| 657 | int QBoxLayout::heightForWidth(int w) const | - | ||||||||||||
| 658 | { | - | ||||||||||||
| 659 | Q_D(const QBoxLayout); | - | ||||||||||||
| 660 | if (!hasHeightForWidth())
| 0 | ||||||||||||
| 661 | return -1; never executed: return -1; | 0 | ||||||||||||
| 662 | - | |||||||||||||
| 663 | int left, top, right, bottom; | - | ||||||||||||
| 664 | d->effectiveMargins(&left, &top, &right, &bottom); | - | ||||||||||||
| 665 | - | |||||||||||||
| 666 | w -= left + right; | - | ||||||||||||
| 667 | if (w != d->hfwWidth)
| 0 | ||||||||||||
| 668 | const_cast<QBoxLayout*>(this)->d_func()->calcHfw(w); never executed: const_cast<QBoxLayout*>(this)->d_func()->calcHfw(w); | 0 | ||||||||||||
| 669 | - | |||||||||||||
| 670 | return d->hfwHeight + top + bottom; never executed: return d->hfwHeight + top + bottom; | 0 | ||||||||||||
| 671 | } | - | ||||||||||||
| 672 | - | |||||||||||||
| 673 | /*! | - | ||||||||||||
| 674 | \reimp | - | ||||||||||||
| 675 | */ | - | ||||||||||||
| 676 | int QBoxLayout::minimumHeightForWidth(int w) const | - | ||||||||||||
| 677 | { | - | ||||||||||||
| 678 | Q_D(const QBoxLayout); | - | ||||||||||||
| 679 | (void) heightForWidth(w); | - | ||||||||||||
| 680 | int top, bottom; | - | ||||||||||||
| 681 | d->effectiveMargins(0, &top, 0, &bottom); | - | ||||||||||||
| 682 | return d->hasHfw ? (d->hfwMinHeight + top + bottom) : -1; never executed: return d->hasHfw ? (d->hfwMinHeight + top + bottom) : -1;
| 0 | ||||||||||||
| 683 | } | - | ||||||||||||
| 684 | - | |||||||||||||
| 685 | /*! | - | ||||||||||||
| 686 | Resets cached information. | - | ||||||||||||
| 687 | */ | - | ||||||||||||
| 688 | void QBoxLayout::invalidate() | - | ||||||||||||
| 689 | { | - | ||||||||||||
| 690 | Q_D(QBoxLayout); | - | ||||||||||||
| 691 | d->setDirty(); | - | ||||||||||||
| 692 | QLayout::invalidate(); | - | ||||||||||||
| 693 | } never executed: end of block | 0 | ||||||||||||
| 694 | - | |||||||||||||
| 695 | /*! | - | ||||||||||||
| 696 | \reimp | - | ||||||||||||
| 697 | */ | - | ||||||||||||
| 698 | int QBoxLayout::count() const | - | ||||||||||||
| 699 | { | - | ||||||||||||
| 700 | Q_D(const QBoxLayout); | - | ||||||||||||
| 701 | return d->list.count(); never executed: return d->list.count(); | 0 | ||||||||||||
| 702 | } | - | ||||||||||||
| 703 | - | |||||||||||||
| 704 | /*! | - | ||||||||||||
| 705 | \reimp | - | ||||||||||||
| 706 | */ | - | ||||||||||||
| 707 | QLayoutItem *QBoxLayout::itemAt(int index) const | - | ||||||||||||
| 708 | { | - | ||||||||||||
| 709 | Q_D(const QBoxLayout); | - | ||||||||||||
| 710 | return index >= 0 && index < d->list.count() ? d->list.at(index)->item : 0; never executed: return index >= 0 && index < d->list.count() ? d->list.at(index)->item : 0;
| 0 | ||||||||||||
| 711 | } | - | ||||||||||||
| 712 | - | |||||||||||||
| 713 | /*! | - | ||||||||||||
| 714 | \reimp | - | ||||||||||||
| 715 | */ | - | ||||||||||||
| 716 | QLayoutItem *QBoxLayout::takeAt(int index) | - | ||||||||||||
| 717 | { | - | ||||||||||||
| 718 | Q_D(QBoxLayout); | - | ||||||||||||
| 719 | if (index < 0 || index >= d->list.count())
| 0 | ||||||||||||
| 720 | return 0; never executed: return 0; | 0 | ||||||||||||
| 721 | QBoxLayoutItem *b = d->list.takeAt(index); | - | ||||||||||||
| 722 | QLayoutItem *item = b->item; | - | ||||||||||||
| 723 | b->item = 0; | - | ||||||||||||
| 724 | delete b; | - | ||||||||||||
| 725 | - | |||||||||||||
| 726 | if (QLayout *l = item->layout()) {
| 0 | ||||||||||||
| 727 | // sanity check in case the user passed something weird to QObject::setParent() | - | ||||||||||||
| 728 | if (l->parent() == this)
| 0 | ||||||||||||
| 729 | l->setParent(0); never executed: l->setParent(0); | 0 | ||||||||||||
| 730 | } never executed: end of block | 0 | ||||||||||||
| 731 | - | |||||||||||||
| 732 | invalidate(); | - | ||||||||||||
| 733 | return item; never executed: return item; | 0 | ||||||||||||
| 734 | } | - | ||||||||||||
| 735 | - | |||||||||||||
| 736 | - | |||||||||||||
| 737 | /*! | - | ||||||||||||
| 738 | \reimp | - | ||||||||||||
| 739 | */ | - | ||||||||||||
| 740 | Qt::Orientations QBoxLayout::expandingDirections() const | - | ||||||||||||
| 741 | { | - | ||||||||||||
| 742 | Q_D(const QBoxLayout); | - | ||||||||||||
| 743 | if (d->dirty)
| 0 | ||||||||||||
| 744 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); never executed: const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | 0 | ||||||||||||
| 745 | return d->expanding; never executed: return d->expanding; | 0 | ||||||||||||
| 746 | } | - | ||||||||||||
| 747 | - | |||||||||||||
| 748 | /*! | - | ||||||||||||
| 749 | \reimp | - | ||||||||||||
| 750 | */ | - | ||||||||||||
| 751 | void QBoxLayout::setGeometry(const QRect &r) | - | ||||||||||||
| 752 | { | - | ||||||||||||
| 753 | Q_D(QBoxLayout); | - | ||||||||||||
| 754 | if (d->dirty || r != geometry()) {
| 0 | ||||||||||||
| 755 | QRect oldRect = geometry(); | - | ||||||||||||
| 756 | QLayout::setGeometry(r); | - | ||||||||||||
| 757 | if (d->dirty)
| 0 | ||||||||||||
| 758 | d->setupGeom(); never executed: d->setupGeom(); | 0 | ||||||||||||
| 759 | QRect cr = alignment() ? alignmentRect(r) : r;
| 0 | ||||||||||||
| 760 | - | |||||||||||||
| 761 | int left, top, right, bottom; | - | ||||||||||||
| 762 | d->effectiveMargins(&left, &top, &right, &bottom); | - | ||||||||||||
| 763 | QRect s(cr.x() + left, cr.y() + top, | - | ||||||||||||
| 764 | cr.width() - (left + right), | - | ||||||||||||
| 765 | cr.height() - (top + bottom)); | - | ||||||||||||
| 766 | - | |||||||||||||
| 767 | QVector<QLayoutStruct> a = d->geomArray; | - | ||||||||||||
| 768 | int pos = horz(d->dir) ? s.x() : s.y();
| 0 | ||||||||||||
| 769 | int space = horz(d->dir) ? s.width() : s.height();
| 0 | ||||||||||||
| 770 | int n = a.count(); | - | ||||||||||||
| 771 | if (d->hasHfw && !horz(d->dir)) {
| 0 | ||||||||||||
| 772 | for (int i = 0; i < n; i++) {
| 0 | ||||||||||||
| 773 | QBoxLayoutItem *box = d->list.at(i); | - | ||||||||||||
| 774 | if (box->item->hasHeightForWidth()) {
| 0 | ||||||||||||
| 775 | int width = qBound(box->item->minimumSize().width(), s.width(), box->item->maximumSize().width()); | - | ||||||||||||
| 776 | a[i].sizeHint = a[i].minimumSize = | - | ||||||||||||
| 777 | box->item->heightForWidth(width); | - | ||||||||||||
| 778 | } never executed: end of block | 0 | ||||||||||||
| 779 | } never executed: end of block | 0 | ||||||||||||
| 780 | } never executed: end of block | 0 | ||||||||||||
| 781 | - | |||||||||||||
| 782 | Direction visualDir = d->dir; | - | ||||||||||||
| 783 | QWidget *parent = parentWidget(); | - | ||||||||||||
| 784 | if (parent && parent->isRightToLeft()) {
| 0 | ||||||||||||
| 785 | if (d->dir == LeftToRight)
| 0 | ||||||||||||
| 786 | visualDir = RightToLeft; never executed: visualDir = RightToLeft; | 0 | ||||||||||||
| 787 | else if (d->dir == RightToLeft)
| 0 | ||||||||||||
| 788 | visualDir = LeftToRight; never executed: visualDir = LeftToRight; | 0 | ||||||||||||
| 789 | } never executed: end of block | 0 | ||||||||||||
| 790 | - | |||||||||||||
| 791 | qGeomCalc(a, 0, n, pos, space); | - | ||||||||||||
| 792 | - | |||||||||||||
| 793 | bool reverse = (horz(visualDir)
| 0 | ||||||||||||
| 794 | ? ((r.right() > oldRect.right()) != (visualDir == RightToLeft)) | - | ||||||||||||
| 795 | : r.bottom() > oldRect.bottom()); | - | ||||||||||||
| 796 | for (int j = 0; j < n; j++) {
| 0 | ||||||||||||
| 797 | int i = reverse ? n-j-1 : j;
| 0 | ||||||||||||
| 798 | QBoxLayoutItem *box = d->list.at(i); | - | ||||||||||||
| 799 | - | |||||||||||||
| 800 | switch (visualDir) { | - | ||||||||||||
| 801 | case LeftToRight: never executed: case LeftToRight: | 0 | ||||||||||||
| 802 | box->item->setGeometry(QRect(a.at(i).pos, s.y(), a.at(i).size, s.height())); | - | ||||||||||||
| 803 | break; never executed: break; | 0 | ||||||||||||
| 804 | case RightToLeft: never executed: case RightToLeft: | 0 | ||||||||||||
| 805 | box->item->setGeometry(QRect(s.left() + s.right() - a.at(i).pos - a.at(i).size + 1, | - | ||||||||||||
| 806 | s.y(), a.at(i).size, s.height())); | - | ||||||||||||
| 807 | break; never executed: break; | 0 | ||||||||||||
| 808 | case TopToBottom: never executed: case TopToBottom: | 0 | ||||||||||||
| 809 | box->item->setGeometry(QRect(s.x(), a.at(i).pos, s.width(), a.at(i).size)); | - | ||||||||||||
| 810 | break; never executed: break; | 0 | ||||||||||||
| 811 | case BottomToTop: never executed: case BottomToTop: | 0 | ||||||||||||
| 812 | box->item->setGeometry(QRect(s.x(), | - | ||||||||||||
| 813 | s.top() + s.bottom() - a.at(i).pos - a.at(i).size + 1, | - | ||||||||||||
| 814 | s.width(), a.at(i).size)); | - | ||||||||||||
| 815 | } never executed: end of block | 0 | ||||||||||||
| 816 | } never executed: end of block | 0 | ||||||||||||
| 817 | } never executed: end of block | 0 | ||||||||||||
| 818 | } never executed: end of block | 0 | ||||||||||||
| 819 | - | |||||||||||||
| 820 | /*! | - | ||||||||||||
| 821 | \reimp | - | ||||||||||||
| 822 | */ | - | ||||||||||||
| 823 | void QBoxLayout::addItem(QLayoutItem *item) | - | ||||||||||||
| 824 | { | - | ||||||||||||
| 825 | Q_D(QBoxLayout); | - | ||||||||||||
| 826 | QBoxLayoutItem *it = new QBoxLayoutItem(item); | - | ||||||||||||
| 827 | d->list.append(it); | - | ||||||||||||
| 828 | invalidate(); | - | ||||||||||||
| 829 | } never executed: end of block | 0 | ||||||||||||
| 830 | - | |||||||||||||
| 831 | /*! | - | ||||||||||||
| 832 | Inserts \a item into this box layout at position \a index. If \a | - | ||||||||||||
| 833 | index is negative, the item is added at the end. | - | ||||||||||||
| 834 | - | |||||||||||||
| 835 | \sa addItem(), insertWidget(), insertLayout(), insertStretch(), | - | ||||||||||||
| 836 | insertSpacing() | - | ||||||||||||
| 837 | */ | - | ||||||||||||
| 838 | void QBoxLayout::insertItem(int index, QLayoutItem *item) | - | ||||||||||||
| 839 | { | - | ||||||||||||
| 840 | Q_D(QBoxLayout); | - | ||||||||||||
| 841 | if (index < 0) // append
| 0 | ||||||||||||
| 842 | index = d->list.count(); never executed: index = d->list.count(); | 0 | ||||||||||||
| 843 | - | |||||||||||||
| 844 | QBoxLayoutItem *it = new QBoxLayoutItem(item); | - | ||||||||||||
| 845 | d->list.insert(index, it); | - | ||||||||||||
| 846 | invalidate(); | - | ||||||||||||
| 847 | } never executed: end of block | 0 | ||||||||||||
| 848 | - | |||||||||||||
| 849 | /*! | - | ||||||||||||
| 850 | Inserts a non-stretchable space (a QSpacerItem) at position \a index, with | - | ||||||||||||
| 851 | size \a size. If \a index is negative the space is added at the end. | - | ||||||||||||
| 852 | - | |||||||||||||
| 853 | The box layout has default margin and spacing. This function adds | - | ||||||||||||
| 854 | additional space. | - | ||||||||||||
| 855 | - | |||||||||||||
| 856 | \sa addSpacing(), insertItem(), QSpacerItem | - | ||||||||||||
| 857 | */ | - | ||||||||||||
| 858 | void QBoxLayout::insertSpacing(int index, int size) | - | ||||||||||||
| 859 | { | - | ||||||||||||
| 860 | Q_D(QBoxLayout); | - | ||||||||||||
| 861 | if (index < 0) // append
| 0 | ||||||||||||
| 862 | index = d->list.count(); never executed: index = d->list.count(); | 0 | ||||||||||||
| 863 | - | |||||||||||||
| 864 | QLayoutItem *b; | - | ||||||||||||
| 865 | if (horz(d->dir))
| 0 | ||||||||||||
| 866 | b = QLayoutPrivate::createSpacerItem(this, size, 0, QSizePolicy::Fixed, QSizePolicy::Minimum); never executed: b = QLayoutPrivate::createSpacerItem(this, size, 0, QSizePolicy::Fixed, QSizePolicy::Minimum); | 0 | ||||||||||||
| 867 | else | - | ||||||||||||
| 868 | b = QLayoutPrivate::createSpacerItem(this, 0, size, QSizePolicy::Minimum, QSizePolicy::Fixed); never executed: b = QLayoutPrivate::createSpacerItem(this, 0, size, QSizePolicy::Minimum, QSizePolicy::Fixed); | 0 | ||||||||||||
| 869 | - | |||||||||||||
| 870 | QT_TRY { | - | ||||||||||||
| 871 | QBoxLayoutItem *it = new QBoxLayoutItem(b); | - | ||||||||||||
| 872 | it->magic = true; | - | ||||||||||||
| 873 | d->list.insert(index, it); | - | ||||||||||||
| 874 | - | |||||||||||||
| 875 | } QT_CATCH(...) { never executed: end of blockdead code: { delete b; qt_noop(); } | - | ||||||||||||
| 876 | delete b; dead code: { delete b; qt_noop(); } | - | ||||||||||||
| 877 | QT_RETHROW; dead code: { delete b; qt_noop(); } | - | ||||||||||||
| 878 | } dead code: { delete b; qt_noop(); } | - | ||||||||||||
| 879 | invalidate(); | - | ||||||||||||
| 880 | } never executed: end of block | 0 | ||||||||||||
| 881 | - | |||||||||||||
| 882 | /*! | - | ||||||||||||
| 883 | Inserts a stretchable space (a QSpacerItem) at position \a | - | ||||||||||||
| 884 | index, with zero minimum size and stretch factor \a stretch. If \a | - | ||||||||||||
| 885 | index is negative the space is added at the end. | - | ||||||||||||
| 886 | - | |||||||||||||
| 887 | \sa addStretch(), insertItem(), QSpacerItem | - | ||||||||||||
| 888 | */ | - | ||||||||||||
| 889 | void QBoxLayout::insertStretch(int index, int stretch) | - | ||||||||||||
| 890 | { | - | ||||||||||||
| 891 | Q_D(QBoxLayout); | - | ||||||||||||
| 892 | if (index < 0) // append
| 0 | ||||||||||||
| 893 | index = d->list.count(); never executed: index = d->list.count(); | 0 | ||||||||||||
| 894 | - | |||||||||||||
| 895 | QLayoutItem *b; | - | ||||||||||||
| 896 | if (horz(d->dir))
| 0 | ||||||||||||
| 897 | b = QLayoutPrivate::createSpacerItem(this, 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); never executed: b = QLayoutPrivate::createSpacerItem(this, 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); | 0 | ||||||||||||
| 898 | else | - | ||||||||||||
| 899 | b = QLayoutPrivate::createSpacerItem(this, 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); never executed: b = QLayoutPrivate::createSpacerItem(this, 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | 0 | ||||||||||||
| 900 | - | |||||||||||||
| 901 | QBoxLayoutItem *it = new QBoxLayoutItem(b, stretch); | - | ||||||||||||
| 902 | it->magic = true; | - | ||||||||||||
| 903 | d->list.insert(index, it); | - | ||||||||||||
| 904 | invalidate(); | - | ||||||||||||
| 905 | } never executed: end of block | 0 | ||||||||||||
| 906 | - | |||||||||||||
| 907 | /*! | - | ||||||||||||
| 908 | \since 4.4 | - | ||||||||||||
| 909 | - | |||||||||||||
| 910 | Inserts \a spacerItem at position \a index, with zero minimum | - | ||||||||||||
| 911 | size and stretch factor. If \a index is negative the | - | ||||||||||||
| 912 | space is added at the end. | - | ||||||||||||
| 913 | - | |||||||||||||
| 914 | \sa addSpacerItem(), insertStretch(), insertSpacing() | - | ||||||||||||
| 915 | */ | - | ||||||||||||
| 916 | void QBoxLayout::insertSpacerItem(int index, QSpacerItem *spacerItem) | - | ||||||||||||
| 917 | { | - | ||||||||||||
| 918 | Q_D(QBoxLayout); | - | ||||||||||||
| 919 | if (index < 0) // append
| 0 | ||||||||||||
| 920 | index = d->list.count(); never executed: index = d->list.count(); | 0 | ||||||||||||
| 921 | - | |||||||||||||
| 922 | QBoxLayoutItem *it = new QBoxLayoutItem(spacerItem); | - | ||||||||||||
| 923 | it->magic = true; | - | ||||||||||||
| 924 | d->list.insert(index, it); | - | ||||||||||||
| 925 | invalidate(); | - | ||||||||||||
| 926 | } never executed: end of block | 0 | ||||||||||||
| 927 | - | |||||||||||||
| 928 | /*! | - | ||||||||||||
| 929 | Inserts \a layout at position \a index, with stretch factor \a | - | ||||||||||||
| 930 | stretch. If \a index is negative, the layout is added at the end. | - | ||||||||||||
| 931 | - | |||||||||||||
| 932 | \a layout becomes a child of the box layout. | - | ||||||||||||
| 933 | - | |||||||||||||
| 934 | \sa addLayout(), insertItem() | - | ||||||||||||
| 935 | */ | - | ||||||||||||
| 936 | void QBoxLayout::insertLayout(int index, QLayout *layout, int stretch) | - | ||||||||||||
| 937 | { | - | ||||||||||||
| 938 | Q_D(QBoxLayout); | - | ||||||||||||
| 939 | if (!d->checkLayout(layout))
| 0 | ||||||||||||
| 940 | return; never executed: return; | 0 | ||||||||||||
| 941 | if (!adoptLayout(layout))
| 0 | ||||||||||||
| 942 | return; never executed: return; | 0 | ||||||||||||
| 943 | if (index < 0) // append
| 0 | ||||||||||||
| 944 | index = d->list.count(); never executed: index = d->list.count(); | 0 | ||||||||||||
| 945 | QBoxLayoutItem *it = new QBoxLayoutItem(layout, stretch); | - | ||||||||||||
| 946 | d->list.insert(index, it); | - | ||||||||||||
| 947 | invalidate(); | - | ||||||||||||
| 948 | } never executed: end of block | 0 | ||||||||||||
| 949 | - | |||||||||||||
| 950 | /*! | - | ||||||||||||
| 951 | Inserts \a widget at position \a index, with stretch factor \a | - | ||||||||||||
| 952 | stretch and alignment \a alignment. If \a index is negative, the | - | ||||||||||||
| 953 | widget is added at the end. | - | ||||||||||||
| 954 | - | |||||||||||||
| 955 | The stretch factor applies only in the \l{direction()}{direction} | - | ||||||||||||
| 956 | of the QBoxLayout, and is relative to the other boxes and widgets | - | ||||||||||||
| 957 | in this QBoxLayout. Widgets and boxes with higher stretch factors | - | ||||||||||||
| 958 | grow more. | - | ||||||||||||
| 959 | - | |||||||||||||
| 960 | If the stretch factor is 0 and nothing else in the QBoxLayout has | - | ||||||||||||
| 961 | a stretch factor greater than zero, the space is distributed | - | ||||||||||||
| 962 | according to the QWidget:sizePolicy() of each widget that's | - | ||||||||||||
| 963 | involved. | - | ||||||||||||
| 964 | - | |||||||||||||
| 965 | The alignment is specified by \a alignment. The default alignment | - | ||||||||||||
| 966 | is 0, which means that the widget fills the entire cell. | - | ||||||||||||
| 967 | - | |||||||||||||
| 968 | \sa addWidget(), insertItem() | - | ||||||||||||
| 969 | */ | - | ||||||||||||
| 970 | void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch, | - | ||||||||||||
| 971 | Qt::Alignment alignment) | - | ||||||||||||
| 972 | { | - | ||||||||||||
| 973 | Q_D(QBoxLayout); | - | ||||||||||||
| 974 | if (!d->checkWidget(widget))
| 0 | ||||||||||||
| 975 | return; never executed: return; | 0 | ||||||||||||
| 976 | addChildWidget(widget); | - | ||||||||||||
| 977 | if (index < 0) // append
| 0 | ||||||||||||
| 978 | index = d->list.count(); never executed: index = d->list.count(); | 0 | ||||||||||||
| 979 | QWidgetItem *b = QLayoutPrivate::createWidgetItem(this, widget); | - | ||||||||||||
| 980 | b->setAlignment(alignment); | - | ||||||||||||
| 981 | - | |||||||||||||
| 982 | QBoxLayoutItem *it; | - | ||||||||||||
| 983 | QT_TRY{ | - | ||||||||||||
| 984 | it = new QBoxLayoutItem(b, stretch); | - | ||||||||||||
| 985 | } QT_CATCH(...) { never executed: end of blockdead code: { delete b; qt_noop(); } | - | ||||||||||||
| 986 | delete b; dead code: { delete b; qt_noop(); } | - | ||||||||||||
| 987 | QT_RETHROW; dead code: { delete b; qt_noop(); } | - | ||||||||||||
| 988 | } dead code: { delete b; qt_noop(); } | - | ||||||||||||
| 989 | - | |||||||||||||
| 990 | QT_TRY{ | - | ||||||||||||
| 991 | d->list.insert(index, it); | - | ||||||||||||
| 992 | } QT_CATCH(...) { never executed: end of blockdead code: { delete it; qt_noop(); } | - | ||||||||||||
| 993 | delete it; dead code: { delete it; qt_noop(); } | - | ||||||||||||
| 994 | QT_RETHROW; dead code: { delete it; qt_noop(); } | - | ||||||||||||
| 995 | } dead code: { delete it; qt_noop(); } | - | ||||||||||||
| 996 | invalidate(); | - | ||||||||||||
| 997 | } never executed: end of block | 0 | ||||||||||||
| 998 | - | |||||||||||||
| 999 | /*! | - | ||||||||||||
| 1000 | Adds a non-stretchable space (a QSpacerItem) with size \a size | - | ||||||||||||
| 1001 | to the end of this box layout. QBoxLayout provides default margin | - | ||||||||||||
| 1002 | and spacing. This function adds additional space. | - | ||||||||||||
| 1003 | - | |||||||||||||
| 1004 | \sa insertSpacing(), addItem(), QSpacerItem | - | ||||||||||||
| 1005 | */ | - | ||||||||||||
| 1006 | void QBoxLayout::addSpacing(int size) | - | ||||||||||||
| 1007 | { | - | ||||||||||||
| 1008 | insertSpacing(-1, size); | - | ||||||||||||
| 1009 | } never executed: end of block | 0 | ||||||||||||
| 1010 | - | |||||||||||||
| 1011 | /*! | - | ||||||||||||
| 1012 | Adds a stretchable space (a QSpacerItem) with zero minimum | - | ||||||||||||
| 1013 | size and stretch factor \a stretch to the end of this box layout. | - | ||||||||||||
| 1014 | - | |||||||||||||
| 1015 | \sa insertStretch(), addItem(), QSpacerItem | - | ||||||||||||
| 1016 | */ | - | ||||||||||||
| 1017 | void QBoxLayout::addStretch(int stretch) | - | ||||||||||||
| 1018 | { | - | ||||||||||||
| 1019 | insertStretch(-1, stretch); | - | ||||||||||||
| 1020 | } never executed: end of block | 0 | ||||||||||||
| 1021 | - | |||||||||||||
| 1022 | /*! | - | ||||||||||||
| 1023 | \since 4.4 | - | ||||||||||||
| 1024 | - | |||||||||||||
| 1025 | Adds \a spacerItem to the end of this box layout. | - | ||||||||||||
| 1026 | - | |||||||||||||
| 1027 | \sa addSpacing(), addStretch() | - | ||||||||||||
| 1028 | */ | - | ||||||||||||
| 1029 | void QBoxLayout::addSpacerItem(QSpacerItem *spacerItem) | - | ||||||||||||
| 1030 | { | - | ||||||||||||
| 1031 | insertSpacerItem(-1, spacerItem); | - | ||||||||||||
| 1032 | } never executed: end of block | 0 | ||||||||||||
| 1033 | - | |||||||||||||
| 1034 | /*! | - | ||||||||||||
| 1035 | Adds \a widget to the end of this box layout, with a stretch | - | ||||||||||||
| 1036 | factor of \a stretch and alignment \a alignment. | - | ||||||||||||
| 1037 | - | |||||||||||||
| 1038 | The stretch factor applies only in the \l{direction()}{direction} | - | ||||||||||||
| 1039 | of the QBoxLayout, and is relative to the other boxes and widgets | - | ||||||||||||
| 1040 | in this QBoxLayout. Widgets and boxes with higher stretch factors | - | ||||||||||||
| 1041 | grow more. | - | ||||||||||||
| 1042 | - | |||||||||||||
| 1043 | If the stretch factor is 0 and nothing else in the QBoxLayout has | - | ||||||||||||
| 1044 | a stretch factor greater than zero, the space is distributed | - | ||||||||||||
| 1045 | according to the QWidget:sizePolicy() of each widget that's | - | ||||||||||||
| 1046 | involved. | - | ||||||||||||
| 1047 | - | |||||||||||||
| 1048 | The alignment is specified by \a alignment. The default | - | ||||||||||||
| 1049 | alignment is 0, which means that the widget fills the entire cell. | - | ||||||||||||
| 1050 | - | |||||||||||||
| 1051 | \sa insertWidget(), addItem(), addLayout(), addStretch(), | - | ||||||||||||
| 1052 | addSpacing(), addStrut() | - | ||||||||||||
| 1053 | */ | - | ||||||||||||
| 1054 | void QBoxLayout::addWidget(QWidget *widget, int stretch, Qt::Alignment alignment) | - | ||||||||||||
| 1055 | { | - | ||||||||||||
| 1056 | insertWidget(-1, widget, stretch, alignment); | - | ||||||||||||
| 1057 | } never executed: end of block | 0 | ||||||||||||
| 1058 | - | |||||||||||||
| 1059 | /*! | - | ||||||||||||
| 1060 | Adds \a layout to the end of the box, with serial stretch factor | - | ||||||||||||
| 1061 | \a stretch. | - | ||||||||||||
| 1062 | - | |||||||||||||
| 1063 | \sa insertLayout(), addItem(), addWidget() | - | ||||||||||||
| 1064 | */ | - | ||||||||||||
| 1065 | void QBoxLayout::addLayout(QLayout *layout, int stretch) | - | ||||||||||||
| 1066 | { | - | ||||||||||||
| 1067 | insertLayout(-1, layout, stretch); | - | ||||||||||||
| 1068 | } never executed: end of block | 0 | ||||||||||||
| 1069 | - | |||||||||||||
| 1070 | /*! | - | ||||||||||||
| 1071 | Limits the perpendicular dimension of the box (e.g. height if the | - | ||||||||||||
| 1072 | box is \l LeftToRight) to a minimum of \a size. Other constraints | - | ||||||||||||
| 1073 | may increase the limit. | - | ||||||||||||
| 1074 | - | |||||||||||||
| 1075 | \sa addItem() | - | ||||||||||||
| 1076 | */ | - | ||||||||||||
| 1077 | void QBoxLayout::addStrut(int size) | - | ||||||||||||
| 1078 | { | - | ||||||||||||
| 1079 | Q_D(QBoxLayout); | - | ||||||||||||
| 1080 | QLayoutItem *b; | - | ||||||||||||
| 1081 | if (horz(d->dir))
| 0 | ||||||||||||
| 1082 | b = QLayoutPrivate::createSpacerItem(this, 0, size, QSizePolicy::Fixed, QSizePolicy::Minimum); never executed: b = QLayoutPrivate::createSpacerItem(this, 0, size, QSizePolicy::Fixed, QSizePolicy::Minimum); | 0 | ||||||||||||
| 1083 | else | - | ||||||||||||
| 1084 | b = QLayoutPrivate::createSpacerItem(this, size, 0, QSizePolicy::Minimum, QSizePolicy::Fixed); never executed: b = QLayoutPrivate::createSpacerItem(this, size, 0, QSizePolicy::Minimum, QSizePolicy::Fixed); | 0 | ||||||||||||
| 1085 | - | |||||||||||||
| 1086 | QBoxLayoutItem *it = new QBoxLayoutItem(b); | - | ||||||||||||
| 1087 | it->magic = true; | - | ||||||||||||
| 1088 | d->list.append(it); | - | ||||||||||||
| 1089 | invalidate(); | - | ||||||||||||
| 1090 | } never executed: end of block | 0 | ||||||||||||
| 1091 | - | |||||||||||||
| 1092 | /*! | - | ||||||||||||
| 1093 | Sets the stretch factor for \a widget to \a stretch and returns | - | ||||||||||||
| 1094 | true if \a widget is found in this layout (not including child | - | ||||||||||||
| 1095 | layouts); otherwise returns \c false. | - | ||||||||||||
| 1096 | - | |||||||||||||
| 1097 | \sa setAlignment() | - | ||||||||||||
| 1098 | */ | - | ||||||||||||
| 1099 | bool QBoxLayout::setStretchFactor(QWidget *widget, int stretch) | - | ||||||||||||
| 1100 | { | - | ||||||||||||
| 1101 | Q_D(QBoxLayout); | - | ||||||||||||
| 1102 | if (!widget)
| 0 | ||||||||||||
| 1103 | return false; never executed: return false; | 0 | ||||||||||||
| 1104 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||
| 1105 | QBoxLayoutItem *box = d->list.at(i); | - | ||||||||||||
| 1106 | if (box->item->widget() == widget) {
| 0 | ||||||||||||
| 1107 | box->stretch = stretch; | - | ||||||||||||
| 1108 | invalidate(); | - | ||||||||||||
| 1109 | return true; never executed: return true; | 0 | ||||||||||||
| 1110 | } | - | ||||||||||||
| 1111 | } never executed: end of block | 0 | ||||||||||||
| 1112 | return false; never executed: return false; | 0 | ||||||||||||
| 1113 | } | - | ||||||||||||
| 1114 | - | |||||||||||||
| 1115 | /*! | - | ||||||||||||
| 1116 | \overload | - | ||||||||||||
| 1117 | - | |||||||||||||
| 1118 | Sets the stretch factor for the layout \a layout to \a stretch and | - | ||||||||||||
| 1119 | returns \c true if \a layout is found in this layout (not including | - | ||||||||||||
| 1120 | child layouts); otherwise returns \c false. | - | ||||||||||||
| 1121 | */ | - | ||||||||||||
| 1122 | bool QBoxLayout::setStretchFactor(QLayout *layout, int stretch) | - | ||||||||||||
| 1123 | { | - | ||||||||||||
| 1124 | Q_D(QBoxLayout); | - | ||||||||||||
| 1125 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||
| 1126 | QBoxLayoutItem *box = d->list.at(i); | - | ||||||||||||
| 1127 | if (box->item->layout() == layout) {
| 0 | ||||||||||||
| 1128 | if (box->stretch != stretch) {
| 0 | ||||||||||||
| 1129 | box->stretch = stretch; | - | ||||||||||||
| 1130 | invalidate(); | - | ||||||||||||
| 1131 | } never executed: end of block | 0 | ||||||||||||
| 1132 | return true; never executed: return true; | 0 | ||||||||||||
| 1133 | } | - | ||||||||||||
| 1134 | } never executed: end of block | 0 | ||||||||||||
| 1135 | return false; never executed: return false; | 0 | ||||||||||||
| 1136 | } | - | ||||||||||||
| 1137 | - | |||||||||||||
| 1138 | /*! | - | ||||||||||||
| 1139 | Sets the stretch factor at position \a index. to \a stretch. | - | ||||||||||||
| 1140 | - | |||||||||||||
| 1141 | \since 4.5 | - | ||||||||||||
| 1142 | */ | - | ||||||||||||
| 1143 | - | |||||||||||||
| 1144 | void QBoxLayout::setStretch(int index, int stretch) | - | ||||||||||||
| 1145 | { | - | ||||||||||||
| 1146 | Q_D(QBoxLayout); | - | ||||||||||||
| 1147 | if (index >= 0 && index < d->list.size()) {
| 0 | ||||||||||||
| 1148 | QBoxLayoutItem *box = d->list.at(index); | - | ||||||||||||
| 1149 | if (box->stretch != stretch) {
| 0 | ||||||||||||
| 1150 | box->stretch = stretch; | - | ||||||||||||
| 1151 | invalidate(); | - | ||||||||||||
| 1152 | } never executed: end of block | 0 | ||||||||||||
| 1153 | } never executed: end of block | 0 | ||||||||||||
| 1154 | } never executed: end of block | 0 | ||||||||||||
| 1155 | - | |||||||||||||
| 1156 | /*! | - | ||||||||||||
| 1157 | Returns the stretch factor at position \a index. | - | ||||||||||||
| 1158 | - | |||||||||||||
| 1159 | \since 4.5 | - | ||||||||||||
| 1160 | */ | - | ||||||||||||
| 1161 | - | |||||||||||||
| 1162 | int QBoxLayout::stretch(int index) const | - | ||||||||||||
| 1163 | { | - | ||||||||||||
| 1164 | Q_D(const QBoxLayout); | - | ||||||||||||
| 1165 | if (index >= 0 && index < d->list.size())
| 0 | ||||||||||||
| 1166 | return d->list.at(index)->stretch; never executed: return d->list.at(index)->stretch; | 0 | ||||||||||||
| 1167 | return -1; never executed: return -1; | 0 | ||||||||||||
| 1168 | } | - | ||||||||||||
| 1169 | - | |||||||||||||
| 1170 | /*! | - | ||||||||||||
| 1171 | Sets the direction of this layout to \a direction. | - | ||||||||||||
| 1172 | */ | - | ||||||||||||
| 1173 | void QBoxLayout::setDirection(Direction direction) | - | ||||||||||||
| 1174 | { | - | ||||||||||||
| 1175 | Q_D(QBoxLayout); | - | ||||||||||||
| 1176 | if (d->dir == direction)
| 0 | ||||||||||||
| 1177 | return; never executed: return; | 0 | ||||||||||||
| 1178 | if (horz(d->dir) != horz(direction)) {
| 0 | ||||||||||||
| 1179 | //swap around the spacers (the "magic" bits) | - | ||||||||||||
| 1180 | //#### a bit yucky, knows too much. | - | ||||||||||||
| 1181 | //#### probably best to add access functions to spacerItem | - | ||||||||||||
| 1182 | //#### or even a QSpacerItem::flip() | - | ||||||||||||
| 1183 | for (int i = 0; i < d->list.size(); ++i) {
| 0 | ||||||||||||
| 1184 | QBoxLayoutItem *box = d->list.at(i); | - | ||||||||||||
| 1185 | if (box->magic) {
| 0 | ||||||||||||
| 1186 | QSpacerItem *sp = box->item->spacerItem(); | - | ||||||||||||
| 1187 | if (sp) {
| 0 | ||||||||||||
| 1188 | if (sp->expandingDirections() == Qt::Orientations(0) /*No Direction*/) {
| 0 | ||||||||||||
| 1189 | //spacing or strut | - | ||||||||||||
| 1190 | QSize s = sp->sizeHint(); | - | ||||||||||||
| 1191 | sp->changeSize(s.height(), s.width(), | - | ||||||||||||
| 1192 | horz(direction) ? QSizePolicy::Fixed:QSizePolicy::Minimum, | - | ||||||||||||
| 1193 | horz(direction) ? QSizePolicy::Minimum:QSizePolicy::Fixed); | - | ||||||||||||
| 1194 | - | |||||||||||||
| 1195 | } else { never executed: end of block | 0 | ||||||||||||
| 1196 | //stretch | - | ||||||||||||
| 1197 | if (horz(direction))
| 0 | ||||||||||||
| 1198 | sp->changeSize(0, 0, QSizePolicy::Expanding, never executed: sp->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); | 0 | ||||||||||||
| 1199 | QSizePolicy::Minimum); never executed: sp->changeSize(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); | 0 | ||||||||||||
| 1200 | else | - | ||||||||||||
| 1201 | sp->changeSize(0, 0, QSizePolicy::Minimum, never executed: sp->changeSize(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | 0 | ||||||||||||
| 1202 | QSizePolicy::Expanding); never executed: sp->changeSize(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | 0 | ||||||||||||
| 1203 | } | - | ||||||||||||
| 1204 | } | - | ||||||||||||
| 1205 | } never executed: end of block | 0 | ||||||||||||
| 1206 | } never executed: end of block | 0 | ||||||||||||
| 1207 | } never executed: end of block | 0 | ||||||||||||
| 1208 | d->dir = direction; | - | ||||||||||||
| 1209 | invalidate(); | - | ||||||||||||
| 1210 | } never executed: end of block | 0 | ||||||||||||
| 1211 | - | |||||||||||||
| 1212 | /*! | - | ||||||||||||
| 1213 | \fn QBoxLayout::Direction QBoxLayout::direction() const | - | ||||||||||||
| 1214 | - | |||||||||||||
| 1215 | Returns the direction of the box. addWidget() and addSpacing() | - | ||||||||||||
| 1216 | work in this direction; the stretch stretches in this direction. | - | ||||||||||||
| 1217 | - | |||||||||||||
| 1218 | \sa QBoxLayout::Direction, addWidget(), addSpacing() | - | ||||||||||||
| 1219 | */ | - | ||||||||||||
| 1220 | - | |||||||||||||
| 1221 | QBoxLayout::Direction QBoxLayout::direction() const | - | ||||||||||||
| 1222 | { | - | ||||||||||||
| 1223 | Q_D(const QBoxLayout); | - | ||||||||||||
| 1224 | return d->dir; never executed: return d->dir; | 0 | ||||||||||||
| 1225 | } | - | ||||||||||||
| 1226 | - | |||||||||||||
| 1227 | /*! | - | ||||||||||||
| 1228 | \class QHBoxLayout | - | ||||||||||||
| 1229 | \brief The QHBoxLayout class lines up widgets horizontally. | - | ||||||||||||
| 1230 | - | |||||||||||||
| 1231 | \ingroup geomanagement | - | ||||||||||||
| 1232 | \inmodule QtWidgets | - | ||||||||||||
| 1233 | - | |||||||||||||
| 1234 | This class is used to construct horizontal box layout objects. See | - | ||||||||||||
| 1235 | QBoxLayout for details. | - | ||||||||||||
| 1236 | - | |||||||||||||
| 1237 | The simplest use of the class is like this: | - | ||||||||||||
| 1238 | - | |||||||||||||
| 1239 | \snippet layouts/layouts.cpp 0 | - | ||||||||||||
| 1240 | \snippet layouts/layouts.cpp 1 | - | ||||||||||||
| 1241 | \snippet layouts/layouts.cpp 2 | - | ||||||||||||
| 1242 | \codeline | - | ||||||||||||
| 1243 | \snippet layouts/layouts.cpp 3 | - | ||||||||||||
| 1244 | \snippet layouts/layouts.cpp 4 | - | ||||||||||||
| 1245 | \snippet layouts/layouts.cpp 5 | - | ||||||||||||
| 1246 | - | |||||||||||||
| 1247 | First, we create the widgets we want in the layout. Then, we | - | ||||||||||||
| 1248 | create the QHBoxLayout object and add the widgets into the | - | ||||||||||||
| 1249 | layout. Finally, we call QWidget::setLayout() to install the | - | ||||||||||||
| 1250 | QHBoxLayout object onto the widget. At that point, the widgets in | - | ||||||||||||
| 1251 | the layout are reparented to have \c window as their parent. | - | ||||||||||||
| 1252 | - | |||||||||||||
| 1253 | \image qhboxlayout-with-5-children.png Horizontal box layout with five child widgets | - | ||||||||||||
| 1254 | - | |||||||||||||
| 1255 | \sa QVBoxLayout, QGridLayout, QStackedLayout, {Layout Management}, {Basic Layouts Example} | - | ||||||||||||
| 1256 | */ | - | ||||||||||||
| 1257 | - | |||||||||||||
| 1258 | - | |||||||||||||
| 1259 | /*! | - | ||||||||||||
| 1260 | Constructs a new top-level horizontal box with | - | ||||||||||||
| 1261 | parent \a parent. | - | ||||||||||||
| 1262 | */ | - | ||||||||||||
| 1263 | QHBoxLayout::QHBoxLayout(QWidget *parent) | - | ||||||||||||
| 1264 | : QBoxLayout(LeftToRight, parent) | - | ||||||||||||
| 1265 | { | - | ||||||||||||
| 1266 | } never executed: end of block | 0 | ||||||||||||
| 1267 | - | |||||||||||||
| 1268 | /*! | - | ||||||||||||
| 1269 | Constructs a new horizontal box. You must add | - | ||||||||||||
| 1270 | it to another layout. | - | ||||||||||||
| 1271 | */ | - | ||||||||||||
| 1272 | QHBoxLayout::QHBoxLayout() | - | ||||||||||||
| 1273 | : QBoxLayout(LeftToRight) | - | ||||||||||||
| 1274 | { | - | ||||||||||||
| 1275 | } never executed: end of block | 0 | ||||||||||||
| 1276 | - | |||||||||||||
| 1277 | - | |||||||||||||
| 1278 | - | |||||||||||||
| 1279 | - | |||||||||||||
| 1280 | - | |||||||||||||
| 1281 | /*! | - | ||||||||||||
| 1282 | Destroys this box layout. | - | ||||||||||||
| 1283 | - | |||||||||||||
| 1284 | The layout's widgets aren't destroyed. | - | ||||||||||||
| 1285 | */ | - | ||||||||||||
| 1286 | QHBoxLayout::~QHBoxLayout() | - | ||||||||||||
| 1287 | { | - | ||||||||||||
| 1288 | } | - | ||||||||||||
| 1289 | - | |||||||||||||
| 1290 | /*! | - | ||||||||||||
| 1291 | \class QVBoxLayout | - | ||||||||||||
| 1292 | \brief The QVBoxLayout class lines up widgets vertically. | - | ||||||||||||
| 1293 | - | |||||||||||||
| 1294 | \ingroup geomanagement | - | ||||||||||||
| 1295 | \inmodule QtWidgets | - | ||||||||||||
| 1296 | - | |||||||||||||
| 1297 | This class is used to construct vertical box layout objects. See | - | ||||||||||||
| 1298 | QBoxLayout for details. | - | ||||||||||||
| 1299 | - | |||||||||||||
| 1300 | The simplest use of the class is like this: | - | ||||||||||||
| 1301 | - | |||||||||||||
| 1302 | \snippet layouts/layouts.cpp 6 | - | ||||||||||||
| 1303 | \snippet layouts/layouts.cpp 7 | - | ||||||||||||
| 1304 | \snippet layouts/layouts.cpp 8 | - | ||||||||||||
| 1305 | \codeline | - | ||||||||||||
| 1306 | \snippet layouts/layouts.cpp 9 | - | ||||||||||||
| 1307 | \snippet layouts/layouts.cpp 10 | - | ||||||||||||
| 1308 | \snippet layouts/layouts.cpp 11 | - | ||||||||||||
| 1309 | - | |||||||||||||
| 1310 | First, we create the widgets we want in the layout. Then, we | - | ||||||||||||
| 1311 | create the QVBoxLayout object and add the widgets into the | - | ||||||||||||
| 1312 | layout. Finally, we call QWidget::setLayout() to install the | - | ||||||||||||
| 1313 | QVBoxLayout object onto the widget. At that point, the widgets in | - | ||||||||||||
| 1314 | the layout are reparented to have \c window as their parent. | - | ||||||||||||
| 1315 | - | |||||||||||||
| 1316 | \image qvboxlayout-with-5-children.png Horizontal box layout with five child widgets | - | ||||||||||||
| 1317 | - | |||||||||||||
| 1318 | \sa QHBoxLayout, QGridLayout, QStackedLayout, {Layout Management}, {Basic Layouts Example} | - | ||||||||||||
| 1319 | */ | - | ||||||||||||
| 1320 | - | |||||||||||||
| 1321 | /*! | - | ||||||||||||
| 1322 | Constructs a new top-level vertical box with | - | ||||||||||||
| 1323 | parent \a parent. | - | ||||||||||||
| 1324 | */ | - | ||||||||||||
| 1325 | QVBoxLayout::QVBoxLayout(QWidget *parent) | - | ||||||||||||
| 1326 | : QBoxLayout(TopToBottom, parent) | - | ||||||||||||
| 1327 | { | - | ||||||||||||
| 1328 | } never executed: end of block | 0 | ||||||||||||
| 1329 | - | |||||||||||||
| 1330 | /*! | - | ||||||||||||
| 1331 | Constructs a new vertical box. You must add | - | ||||||||||||
| 1332 | it to another layout. | - | ||||||||||||
| 1333 | - | |||||||||||||
| 1334 | */ | - | ||||||||||||
| 1335 | QVBoxLayout::QVBoxLayout() | - | ||||||||||||
| 1336 | : QBoxLayout(TopToBottom) | - | ||||||||||||
| 1337 | { | - | ||||||||||||
| 1338 | } never executed: end of block | 0 | ||||||||||||
| 1339 | - | |||||||||||||
| 1340 | - | |||||||||||||
| 1341 | /*! | - | ||||||||||||
| 1342 | Destroys this box layout. | - | ||||||||||||
| 1343 | - | |||||||||||||
| 1344 | The layout's widgets aren't destroyed. | - | ||||||||||||
| 1345 | */ | - | ||||||||||||
| 1346 | QVBoxLayout::~QVBoxLayout() | - | ||||||||||||
| 1347 | { | - | ||||||||||||
| 1348 | } | - | ||||||||||||
| 1349 | - | |||||||||||||
| 1350 | QT_END_NAMESPACE | - | ||||||||||||
| 1351 | - | |||||||||||||
| 1352 | #include "moc_qboxlayout.cpp" | - | ||||||||||||
| Source code | Switch to Preprocessed file |