| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/kernel/qboxlayout.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count |
|---|---|---|
| 1 | - | |
| 2 | - | |
| 3 | - | |
| 4 | - | |
| 5 | struct QBoxLayoutItem | - |
| 6 | { | - |
| 7 | QBoxLayoutItem(QLayoutItem *it, int stretch_ = 0) | - |
| 8 | : item(it), stretch(stretch_), magic(false) { } | - |
| 9 | ~QBoxLayoutItem() { delete item; } | - |
| 10 | - | |
| 11 | int hfw(int w) { | - |
| 12 | if (item->hasHeightForWidth()) { | - |
| 13 | return item->heightForWidth(w); | - |
| 14 | } else { | - |
| 15 | return item->sizeHint().height(); | - |
| 16 | } | - |
| 17 | } | - |
| 18 | int mhfw(int w) { | - |
| 19 | if (item->hasHeightForWidth()) { | - |
| 20 | return item->heightForWidth(w); | - |
| 21 | } else { | - |
| 22 | return item->minimumSize().height(); | - |
| 23 | } | - |
| 24 | } | - |
| 25 | int hStretch() { | - |
| 26 | if (stretch == 0 && item->widget()) { | - |
| 27 | return item->widget()->sizePolicy().horizontalStretch(); | - |
| 28 | } else { | - |
| 29 | return stretch; | - |
| 30 | } | - |
| 31 | } | - |
| 32 | int vStretch() { | - |
| 33 | if (stretch == 0 && item->widget()) { | - |
| 34 | return item->widget()->sizePolicy().verticalStretch(); | - |
| 35 | } else { | - |
| 36 | return stretch; | - |
| 37 | } | - |
| 38 | } | - |
| 39 | - | |
| 40 | QLayoutItem *item; | - |
| 41 | int stretch; | - |
| 42 | bool magic; | - |
| 43 | }; | - |
| 44 | - | |
| 45 | class QBoxLayoutPrivate : public QLayoutPrivate | - |
| 46 | { | - |
| 47 | inline QBoxLayout* q_func() { return static_cast<QBoxLayout *>(q_ptr); } inline const QBoxLayout* q_func() const { return static_cast<const QBoxLayout *>(q_ptr); } friend class QBoxLayout; | - |
| 48 | public: | - |
| 49 | QBoxLayoutPrivate() : hfwWidth(-1), dirty(true), spacing(-1) { } | - |
| 50 | ~QBoxLayoutPrivate(); | - |
| 51 | - | |
| 52 | void setDirty() { | - |
| 53 | geomArray.clear(); | - |
| 54 | hfwWidth = -1; | - |
| 55 | hfwHeight = -1; | - |
| 56 | dirty = true; | - |
| 57 | } | - |
| 58 | - | |
| 59 | QList<QBoxLayoutItem *> list; | - |
| 60 | QVector<QLayoutStruct> geomArray; | - |
| 61 | int hfwWidth; | - |
| 62 | int hfwHeight; | - |
| 63 | int hfwMinHeight; | - |
| 64 | QSize sizeHint; | - |
| 65 | QSize minSize; | - |
| 66 | QSize maxSize; | - |
| 67 | int leftMargin, topMargin, rightMargin, bottomMargin; | - |
| 68 | Qt::Orientations expanding; | - |
| 69 | uint hasHfw : 1; | - |
| 70 | uint dirty : 1; | - |
| 71 | QBoxLayout::Direction dir; | - |
| 72 | int spacing; | - |
| 73 | - | |
| 74 | inline void deleteAll() { while (!list.isEmpty()) delete list.takeFirst(); } | - |
| 75 | - | |
| 76 | void setupGeom(); | - |
| 77 | void calcHfw(int); | - |
| 78 | - | |
| 79 | void effectiveMargins(int *left, int *top, int *right, int *bottom) const; | - |
| 80 | QLayoutItem* replaceAt(int index, QLayoutItem*) override; | - |
| 81 | }; | - |
| 82 | - | |
| 83 | QBoxLayoutPrivate::~QBoxLayoutPrivate() | - |
| 84 | { | - |
| 85 | } | - |
| 86 | - | |
| 87 | static inline bool horz(QBoxLayout::Direction dir) | - |
| 88 | { | - |
| 89 | return dir == QBoxLayout::RightToLeft || dir == QBoxLayout::LeftToRight; | - |
| 90 | } | - |
| 91 | - | |
| 92 | - | |
| 93 | - | |
| 94 | - | |
| 95 | - | |
| 96 | - | |
| 97 | void QBoxLayoutPrivate::effectiveMargins(int *left, int *top, int *right, int *bottom) const | - |
| 98 | { | - |
| 99 | int l = leftMargin; | - |
| 100 | int t = topMargin; | - |
| 101 | int r = rightMargin; | - |
| 102 | int b = bottomMargin; | - |
| 103 | if (left) | - |
| 104 | *left = l; | - |
| 105 | if (top) | - |
| 106 | *top = t; | - |
| 107 | if (right) | - |
| 108 | *right = r; | - |
| 109 | if (bottom) | - |
| 110 | *bottom = b; | - |
| 111 | } | - |
| 112 | - | |
| 113 | - | |
| 114 | - | |
| 115 | - | |
| 116 | - | |
| 117 | - | |
| 118 | void QBoxLayoutPrivate::setupGeom() | - |
| 119 | { | - |
| 120 | if (!dirty) | - |
| 121 | return; | - |
| 122 | - | |
| 123 | QBoxLayout * const q = q_func(); | - |
| 124 | int maxw = horz(dir) ? 0 : QLAYOUTSIZE_MAX; | - |
| 125 | int maxh = horz(dir) ? QLAYOUTSIZE_MAX : 0; | - |
| 126 | int minw = 0; | - |
| 127 | int minh = 0; | - |
| 128 | int hintw = 0; | - |
| 129 | int hinth = 0; | - |
| 130 | - | |
| 131 | bool horexp = false; | - |
| 132 | bool verexp = false; | - |
| 133 | - | |
| 134 | hasHfw = false; | - |
| 135 | - | |
| 136 | int n = list.count(); | - |
| 137 | geomArray.clear(); | - |
| 138 | QVector<QLayoutStruct> a(n); | - |
| 139 | - | |
| 140 | QSizePolicy::ControlTypes controlTypes1; | - |
| 141 | QSizePolicy::ControlTypes controlTypes2; | - |
| 142 | int fixedSpacing = q->spacing(); | - |
| 143 | int previousNonEmptyIndex = -1; | - |
| 144 | - | |
| 145 | QStyle *style = 0; | - |
| 146 | if (fixedSpacing < 0) { | - |
| 147 | if (QWidget *parentWidget = q->parentWidget()) | - |
| 148 | style = parentWidget->style(); | - |
| 149 | } | - |
| 150 | - | |
| 151 | for (int i = 0; i < n; i++) { | - |
| 152 | QBoxLayoutItem *box = list.at(i); | - |
| 153 | QSize max = box->item->maximumSize(); | - |
| 154 | QSize min = box->item->minimumSize(); | - |
| 155 | QSize hint = box->item->sizeHint(); | - |
| 156 | Qt::Orientations exp = box->item->expandingDirections(); | - |
| 157 | bool empty = box->item->isEmpty(); | - |
| 158 | int spacing = 0; | - |
| 159 | - | |
| 160 | if (!empty) { | - |
| 161 | if (fixedSpacing >= 0) { | - |
| 162 | spacing = (previousNonEmptyIndex >= 0) ? fixedSpacing : 0; | - |
| 163 | } else { | - |
| 164 | controlTypes1 = controlTypes2; | - |
| 165 | controlTypes2 = box->item->controlTypes(); | - |
| 166 | if (previousNonEmptyIndex >= 0) { | - |
| 167 | QSizePolicy::ControlTypes actual1 = controlTypes1; | - |
| 168 | QSizePolicy::ControlTypes actual2 = controlTypes2; | - |
| 169 | if (dir == QBoxLayout::RightToLeft || dir == QBoxLayout::BottomToTop) | - |
| 170 | qSwap(actual1, actual2); | - |
| 171 | - | |
| 172 | if (style) { | - |
| 173 | spacing = style->combinedLayoutSpacing(actual1, actual2, | - |
| 174 | horz(dir) ? Qt::Horizontal : Qt::Vertical, | - |
| 175 | 0, q->parentWidget()); | - |
| 176 | if (spacing < 0) | - |
| 177 | spacing = 0; | - |
| 178 | } | - |
| 179 | } | - |
| 180 | } | - |
| 181 | - | |
| 182 | if (previousNonEmptyIndex >= 0) | - |
| 183 | a[previousNonEmptyIndex].spacing = spacing; | - |
| 184 | previousNonEmptyIndex = i; | - |
| 185 | } | - |
| 186 | - | |
| 187 | bool ignore = empty && box->item->widget(); | - |
| 188 | bool dummy = true; | - |
| 189 | if (horz(dir)) { | - |
| 190 | bool expand = (exp & Qt::Horizontal || box->stretch > 0); | - |
| 191 | horexp = horexp || expand; | - |
| 192 | maxw += spacing + max.width(); | - |
| 193 | minw += spacing + min.width(); | - |
| 194 | hintw += spacing + hint.width(); | - |
| 195 | if (!ignore) | - |
| 196 | qMaxExpCalc(maxh, verexp, dummy, | - |
| 197 | max.height(), exp & Qt::Vertical, box->item->isEmpty()); | - |
| 198 | minh = qMax(minh, min.height()); | - |
| 199 | hinth = qMax(hinth, hint.height()); | - |
| 200 | - | |
| 201 | a[i].sizeHint = hint.width(); | - |
| 202 | a[i].maximumSize = max.width(); | - |
| 203 | a[i].minimumSize = min.width(); | - |
| 204 | a[i].expansive = expand; | - |
| 205 | a[i].stretch = box->stretch ? box->stretch : box->hStretch(); | - |
| 206 | } else { | - |
| 207 | bool expand = (exp & Qt::Vertical || box->stretch > 0); | - |
| 208 | verexp = verexp || expand; | - |
| 209 | maxh += spacing + max.height(); | - |
| 210 | minh += spacing + min.height(); | - |
| 211 | hinth += spacing + hint.height(); | - |
| 212 | if (!ignore) | - |
| 213 | qMaxExpCalc(maxw, horexp, dummy, | - |
| 214 | max.width(), exp & Qt::Horizontal, box->item->isEmpty()); | - |
| 215 | minw = qMax(minw, min.width()); | - |
| 216 | hintw = qMax(hintw, hint.width()); | - |
| 217 | - | |
| 218 | a[i].sizeHint = hint.height(); | - |
| 219 | a[i].maximumSize = max.height(); | - |
| 220 | a[i].minimumSize = min.height(); | - |
| 221 | a[i].expansive = expand; | - |
| 222 | a[i].stretch = box->stretch ? box->stretch : box->vStretch(); | - |
| 223 | } | - |
| 224 | - | |
| 225 | a[i].empty = empty; | - |
| 226 | a[i].spacing = 0; | - |
| 227 | hasHfw = hasHfw || box->item->hasHeightForWidth(); | - |
| 228 | } | - |
| 229 | - | |
| 230 | geomArray = a; | - |
| 231 | - | |
| 232 | expanding = (Qt::Orientations) | - |
| 233 | ((horexp ? Qt::Horizontal : 0) | - |
| 234 | | (verexp ? Qt::Vertical : 0)); | - |
| 235 | - | |
| 236 | minSize = QSize(minw, minh); | - |
| 237 | maxSize = QSize(maxw, maxh).expandedTo(minSize); | - |
| 238 | sizeHint = QSize(hintw, hinth).expandedTo(minSize).boundedTo(maxSize); | - |
| 239 | - | |
| 240 | q->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); | - |
| 241 | int left, top, right, bottom; | - |
| 242 | effectiveMargins(&left, &top, &right, &bottom); | - |
| 243 | QSize extra(left + right, top + bottom); | - |
| 244 | - | |
| 245 | minSize += extra; | - |
| 246 | maxSize += extra; | - |
| 247 | sizeHint += extra; | - |
| 248 | - | |
| 249 | dirty = false; | - |
| 250 | } | - |
| 251 | - | |
| 252 | - | |
| 253 | - | |
| 254 | - | |
| 255 | void QBoxLayoutPrivate::calcHfw(int w) | - |
| 256 | { | - |
| 257 | QVector<QLayoutStruct> &a = geomArray; | - |
| 258 | int n = a.count(); | - |
| 259 | int h = 0; | - |
| 260 | int mh = 0; | - |
| 261 | - | |
| 262 | ((!(n == list.size())) ? qt_assert("n == list.size()",__FILE__,402408) : qt_noop()); | - |
| 263 | - | |
| 264 | if (horz(dir)) { | - |
| 265 | qGeomCalc(a, 0, n, 0, w); | - |
| 266 | for (int i = 0; i < n; i++) { | - |
| 267 | QBoxLayoutItem *box = list.at(i); | - |
| 268 | h = qMax(h, box->hfw(a.at(i).size)); | - |
| 269 | mh = qMax(mh, box->mhfw(a.at(i).size)); | - |
| 270 | } | - |
| 271 | } else { | - |
| 272 | for (int i = 0; i < n; ++i) { | - |
| 273 | QBoxLayoutItem *box = list.at(i); | - |
| 274 | int spacing = a.at(i).spacing; | - |
| 275 | h += box->hfw(w); | - |
| 276 | mh += box->mhfw(w); | - |
| 277 | h += spacing; | - |
| 278 | mh += spacing; | - |
| 279 | } | - |
| 280 | } | - |
| 281 | hfwWidth = w; | - |
| 282 | hfwHeight = h; | - |
| 283 | hfwMinHeight = mh; | - |
| 284 | } | - |
| 285 | - | |
| 286 | QLayoutItem* QBoxLayoutPrivate::replaceAt(int index, QLayoutItem *item) | - |
| 287 | { | - |
| 288 | QBoxLayout * const q = q_func(); | - |
| 289 | if (!item) | - |
| 290 | return 0; | - |
| 291 | QBoxLayoutItem *b = list.value(index); | - |
| 292 | if (!b) | - |
| 293 | return 0; | - |
| 294 | QLayoutItem *r = b->item; | - |
| 295 | - | |
| 296 | b->item = item; | - |
| 297 | q->invalidate(); | - |
| 298 | return r; | - |
| 299 | } | - |
| 300 | QBoxLayout::QBoxLayout(Direction dir, QWidget *parent) | - |
| 301 | : QLayout(*new QBoxLayoutPrivate, 0, parent) | - |
| 302 | { | - |
| 303 | QBoxLayoutPrivate * const d = d_func(); | - |
| 304 | d->dir = dir; | - |
| 305 | } | - |
| 306 | QBoxLayout::~QBoxLayout() | - |
| 307 | { | - |
| 308 | QBoxLayoutPrivate * const d = d_func(); | - |
| 309 | d->deleteAll(); | - |
| 310 | } | - |
| 311 | int QBoxLayout::spacing() const | - |
| 312 | { | - |
| 313 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 314 | if (d->spacing >=0) { | - |
| 315 | return d->spacing; | - |
| 316 | } else { | - |
| 317 | return qSmartSpacing(this, d->dir == LeftToRight || d->dir == RightToLeft | - |
| 318 | ? QStyle::PM_LayoutHorizontalSpacing | - |
| 319 | : QStyle::PM_LayoutVerticalSpacing); | - |
| 320 | } | - |
| 321 | } | - |
| 322 | - | |
| 323 | - | |
| 324 | - | |
| 325 | - | |
| 326 | - | |
| 327 | - | |
| 328 | - | |
| 329 | void QBoxLayout::setSpacing(int spacing) | - |
| 330 | { | - |
| 331 | QBoxLayoutPrivate * const d = d_func(); | - |
| 332 | d->spacing = spacing; | - |
| 333 | invalidate(); | - |
| 334 | } | - |
| 335 | - | |
| 336 | - | |
| 337 | - | |
| 338 | - | |
| 339 | QSize QBoxLayout::sizeHint() const | - |
| 340 | { | - |
| 341 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 342 | if (d->dirty) | - |
| 343 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | - |
| 344 | return d->sizeHint; | - |
| 345 | } | - |
| 346 | - | |
| 347 | - | |
| 348 | - | |
| 349 | - | |
| 350 | QSize QBoxLayout::minimumSize() const | - |
| 351 | { | - |
| 352 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 353 | if (d->dirty) | - |
| 354 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | - |
| 355 | return d->minSize; | - |
| 356 | } | - |
| 357 | - | |
| 358 | - | |
| 359 | - | |
| 360 | - | |
| 361 | QSize QBoxLayout::maximumSize() const | - |
| 362 | { | - |
| 363 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 364 | if (d->dirty) | - |
| 365 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | - |
| 366 | - | |
| 367 | QSize s = d->maxSize.boundedTo(QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX)); | - |
| 368 | - | |
| 369 | if (alignment() & Qt::AlignHorizontal_Mask) | - |
| 370 | s.setWidth(QLAYOUTSIZE_MAX); | - |
| 371 | if (alignment() & Qt::AlignVertical_Mask) | - |
| 372 | s.setHeight(QLAYOUTSIZE_MAX); | - |
| 373 | return s; | - |
| 374 | } | - |
| 375 | - | |
| 376 | - | |
| 377 | - | |
| 378 | - | |
| 379 | bool QBoxLayout::hasHeightForWidth() const | - |
| 380 | { | - |
| 381 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 382 | if (d->dirty) | - |
| 383 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | - |
| 384 | return d->hasHfw; | - |
| 385 | } | - |
| 386 | - | |
| 387 | - | |
| 388 | - | |
| 389 | - | |
| 390 | int QBoxLayout::heightForWidth(int w) const | - |
| 391 | { | - |
| 392 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 393 | if (!hasHeightForWidth()) | - |
| 394 | return -1; | - |
| 395 | - | |
| 396 | int left, top, right, bottom; | - |
| 397 | d->effectiveMargins(&left, &top, &right, &bottom); | - |
| 398 | - | |
| 399 | w -= left + right; | - |
| 400 | if (w != d->hfwWidth) | - |
| 401 | const_cast<QBoxLayout*>(this)->d_func()->calcHfw(w); | - |
| 402 | - | |
| 403 | return d->hfwHeight + top + bottom; | - |
| 404 | } | - |
| 405 | - | |
| 406 | - | |
| 407 | - | |
| 408 | - | |
| 409 | int QBoxLayout::minimumHeightForWidth(int w) const | - |
| 410 | { | - |
| 411 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 412 | (void) heightForWidth(w); | - |
| 413 | int top, bottom; | - |
| 414 | d->effectiveMargins(0, &top, 0, &bottom); | - |
| 415 | return d->hasHfw ? (d->hfwMinHeight + top + bottom) : -1; | - |
| 416 | } | - |
| 417 | - | |
| 418 | - | |
| 419 | - | |
| 420 | - | |
| 421 | void QBoxLayout::invalidate() | - |
| 422 | { | - |
| 423 | QBoxLayoutPrivate * const d = d_func(); | - |
| 424 | d->setDirty(); | - |
| 425 | QLayout::invalidate(); | - |
| 426 | } | - |
| 427 | - | |
| 428 | - | |
| 429 | - | |
| 430 | - | |
| 431 | int QBoxLayout::count() const | - |
| 432 | { | - |
| 433 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 434 | return d->list.count(); | - |
| 435 | } | - |
| 436 | - | |
| 437 | - | |
| 438 | - | |
| 439 | - | |
| 440 | QLayoutItem *QBoxLayout::itemAt(int index) const | - |
| 441 | { | - |
| 442 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 443 | return index >= 0 && index < d->list.count() ? d->list.at(index)->item : 0; | - |
| 444 | } | - |
| 445 | - | |
| 446 | - | |
| 447 | - | |
| 448 | - | |
| 449 | QLayoutItem *QBoxLayout::takeAt(int index) | - |
| 450 | { | - |
| 451 | QBoxLayoutPrivate * const d = d_func(); | - |
| 452 | if (index < 0 || index >= d->list.count()) | - |
| 453 | return 0; | - |
| 454 | QBoxLayoutItem *b = d->list.takeAt(index); | - |
| 455 | QLayoutItem *item = b->item; | - |
| 456 | b->item = 0; | - |
| 457 | delete b; | - |
| 458 | - | |
| 459 | if (QLayout *l = item->layout()) { | - |
| 460 | - | |
| 461 | if (l->parent() == this) | - |
| 462 | l->setParent(0); | - |
| 463 | } | - |
| 464 | - | |
| 465 | invalidate(); | - |
| 466 | return item; | - |
| 467 | } | - |
| 468 | - | |
| 469 | - | |
| 470 | - | |
| 471 | - | |
| 472 | - | |
| 473 | Qt::Orientations QBoxLayout::expandingDirections() const | - |
| 474 | { | - |
| 475 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 476 | if (d->dirty) | - |
| 477 | const_cast<QBoxLayout*>(this)->d_func()->setupGeom(); | - |
| 478 | return d->expanding; | - |
| 479 | } | - |
| 480 | - | |
| 481 | - | |
| 482 | - | |
| 483 | - | |
| 484 | void QBoxLayout::setGeometry(const QRect &r) | - |
| 485 | { | - |
| 486 | QBoxLayoutPrivate * const d = d_func(); | - |
| 487 | if (d->dirty || r != geometry()) { | - |
| 488 | QRect oldRect = geometry(); | - |
| 489 | QLayout::setGeometry(r); | - |
| 490 | if (d->dirty) | - |
| 491 | d->setupGeom(); | - |
| 492 | QRect cr = alignment() ? alignmentRect(r) : r; | - |
| 493 | - | |
| 494 | int left, top, right, bottom; | - |
| 495 | d->effectiveMargins(&left, &top, &right, &bottom); | - |
| 496 | QRect s(cr.x() + left, cr.y() + top, | - |
| 497 | cr.width() - (left + right), | - |
| 498 | cr.height() - (top + bottom)); | - |
| 499 | - | |
| 500 | QVector<QLayoutStruct> a = d->geomArray; | - |
| 501 | int pos = horz(d->dir) ? s.x() : s.y(); | - |
| 502 | int space = horz(d->dir) ? s.width() : s.height(); | - |
| 503 | int n = a.count(); | - |
| 504 | if (d->hasHfw && !horz(d->dir)) { | - |
| 505 | for (int i = 0; i < n; i++) { | - |
| 506 | QBoxLayoutItem *box = d->list.at(i); | - |
| 507 | if (box->item->hasHeightForWidth()) { | - |
| 508 | int width = qBound(box->item->minimumSize().width(), s.width(), box->item->maximumSize().width()); | - |
| 509 | a[i].sizeHint = a[i].minimumSize = | - |
| 510 | box->item->heightForWidth(width); | - |
| 511 | } | - |
| 512 | } | - |
| 513 | } | - |
| 514 | - | |
| 515 | Direction visualDir = d->dir; | - |
| 516 | QWidget *parent = parentWidget(); | - |
| 517 | if (parent && parent->isRightToLeft()) { | - |
| 518 | if (d->dir == LeftToRight) | - |
| 519 | visualDir = RightToLeft; | - |
| 520 | else if (d->dir == RightToLeft) | - |
| 521 | visualDir = LeftToRight; | - |
| 522 | } | - |
| 523 | - | |
| 524 | qGeomCalc(a, 0, n, pos, space); | - |
| 525 | - | |
| 526 | bool reverse = (horz(visualDir) | - |
| 527 | ? ((r.right() > oldRect.right()) != (visualDir == RightToLeft)) | - |
| 528 | : r.bottom() > oldRect.bottom()); | - |
| 529 | for (int j = 0; j < n; j++) { | - |
| 530 | int i = reverse ? n-j-1 : j; | - |
| 531 | QBoxLayoutItem *box = d->list.at(i); | - |
| 532 | - | |
| 533 | switch (visualDir) { | - |
| 534 | case LeftToRight: | - |
| 535 | box->item->setGeometry(QRect(a.at(i).pos, s.y(), a.at(i).size, s.height())); | - |
| 536 | break; | - |
| 537 | case RightToLeft: | - |
| 538 | box->item->setGeometry(QRect(s.left() + s.right() - a.at(i).pos - a.at(i).size + 1, | - |
| 539 | s.y(), a.at(i).size, s.height())); | - |
| 540 | break; | - |
| 541 | case TopToBottom: | - |
| 542 | box->item->setGeometry(QRect(s.x(), a.at(i).pos, s.width(), a.at(i).size)); | - |
| 543 | break; | - |
| 544 | case BottomToTop: | - |
| 545 | box->item->setGeometry(QRect(s.x(), | - |
| 546 | s.top() + s.bottom() - a.at(i).pos - a.at(i).size + 1, | - |
| 547 | s.width(), a.at(i).size)); | - |
| 548 | } | - |
| 549 | } | - |
| 550 | } | - |
| 551 | } | - |
| 552 | - | |
| 553 | - | |
| 554 | - | |
| 555 | - | |
| 556 | void QBoxLayout::addItem(QLayoutItem *item) | - |
| 557 | { | - |
| 558 | QBoxLayoutPrivate * const d = d_func(); | - |
| 559 | QBoxLayoutItem *it = new QBoxLayoutItem(item); | - |
| 560 | d->list.append(it); | - |
| 561 | invalidate(); | - |
| 562 | } | - |
| 563 | void QBoxLayout::insertItem(int index, QLayoutItem *item) | - |
| 564 | { | - |
| 565 | QBoxLayoutPrivate * const d = d_func(); | - |
| 566 | if (index < 0) | - |
| 567 | index = d->list.count(); | - |
| 568 | - | |
| 569 | QBoxLayoutItem *it = new QBoxLayoutItem(item); | - |
| 570 | d->list.insert(index, it); | - |
| 571 | invalidate(); | - |
| 572 | } | - |
| 573 | void QBoxLayout::insertSpacing(int index, int size) | - |
| 574 | { | - |
| 575 | QBoxLayoutPrivate * const d = d_func(); | - |
| 576 | if (index < 0) | - |
| 577 | index = d->list.count(); | - |
| 578 | - | |
| 579 | QLayoutItem *b; | - |
| 580 | if (horz(d->dir)) | - |
| 581 | b = QLayoutPrivate::createSpacerItem(this, size, 0, QSizePolicy::Fixed, QSizePolicy::Minimum); | - |
| 582 | else | - |
| 583 | b = QLayoutPrivate::createSpacerItem(this, 0, size, QSizePolicy::Minimum, QSizePolicy::Fixed); | - |
| 584 | - | |
| 585 | if (true) { | - |
| 586 | QBoxLayoutItem *it = new QBoxLayoutItem(b); | - |
| 587 | it->magic = true; | - |
| 588 | d->list.insert(index, it); | - |
| 589 | - | |
| 590 | } else { dead code: { delete b; qt_noop(); } | - |
| 591 | delete b; dead code: { delete b; qt_noop(); } | - |
| 592 | qt_noop(); dead code: { delete b; qt_noop(); } | - |
| 593 | } dead code: { delete b; qt_noop(); } | - |
| 594 | invalidate(); | - |
| 595 | } | - |
| 596 | void QBoxLayout::insertStretch(int index, int stretch) | - |
| 597 | { | - |
| 598 | QBoxLayoutPrivate * const d = d_func(); | - |
| 599 | if (index < 0) | - |
| 600 | index = d->list.count(); | - |
| 601 | - | |
| 602 | QLayoutItem *b; | - |
| 603 | if (horz(d->dir)) | - |
| 604 | b = QLayoutPrivate::createSpacerItem(this, 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); | - |
| 605 | else | - |
| 606 | b = QLayoutPrivate::createSpacerItem(this, 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); | - |
| 607 | - | |
| 608 | QBoxLayoutItem *it = new QBoxLayoutItem(b, stretch); | - |
| 609 | it->magic = true; | - |
| 610 | d->list.insert(index, it); | - |
| 611 | invalidate(); | - |
| 612 | } | - |
| 613 | void QBoxLayout::insertSpacerItem(int index, QSpacerItem *spacerItem) | - |
| 614 | { | - |
| 615 | QBoxLayoutPrivate * const d = d_func(); | - |
| 616 | if (index < 0) | - |
| 617 | index = d->list.count(); | - |
| 618 | - | |
| 619 | QBoxLayoutItem *it = new QBoxLayoutItem(spacerItem); | - |
| 620 | it->magic = true; | - |
| 621 | d->list.insert(index, it); | - |
| 622 | invalidate(); | - |
| 623 | } | - |
| 624 | void QBoxLayout::insertLayout(int index, QLayout *layout, int stretch) | - |
| 625 | { | - |
| 626 | QBoxLayoutPrivate * const d = d_func(); | - |
| 627 | if (!d->checkLayout(layout)) | - |
| 628 | return; | - |
| 629 | if (!adoptLayout(layout)) | - |
| 630 | return; | - |
| 631 | if (index < 0) | - |
| 632 | index = d->list.count(); | - |
| 633 | QBoxLayoutItem *it = new QBoxLayoutItem(layout, stretch); | - |
| 634 | d->list.insert(index, it); | - |
| 635 | invalidate(); | - |
| 636 | } | - |
| 637 | void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch, | - |
| 638 | Qt::Alignment alignment) | - |
| 639 | { | - |
| 640 | QBoxLayoutPrivate * const d = d_func(); | - |
| 641 | if (!d->checkWidget(widget)) | - |
| 642 | return; | - |
| 643 | addChildWidget(widget); | - |
| 644 | if (index < 0) | - |
| 645 | index = d->list.count(); | - |
| 646 | QWidgetItem *b = QLayoutPrivate::createWidgetItem(this, widget); | - |
| 647 | b->setAlignment(alignment); | - |
| 648 | - | |
| 649 | QBoxLayoutItem *it; | - |
| 650 | if (true){ | - |
| 651 | it = new QBoxLayoutItem(b, stretch); | - |
| 652 | } else { dead code: { delete b; qt_noop(); } | - |
| 653 | delete b; dead code: { delete b; qt_noop(); } | - |
| 654 | qt_noop(); dead code: { delete b; qt_noop(); } | - |
| 655 | } dead code: { delete b; qt_noop(); } | - |
| 656 | - | |
| 657 | if (true){ | - |
| 658 | d->list.insert(index, it); | - |
| 659 | } else { dead code: { delete it; qt_noop(); } | - |
| 660 | delete it; dead code: { delete it; qt_noop(); } | - |
| 661 | qt_noop(); dead code: { delete it; qt_noop(); } | - |
| 662 | } dead code: { delete it; qt_noop(); } | - |
| 663 | invalidate(); | - |
| 664 | } | - |
| 665 | void QBoxLayout::addSpacing(int size) | - |
| 666 | { | - |
| 667 | insertSpacing(-1, size); | - |
| 668 | } | - |
| 669 | - | |
| 670 | - | |
| 671 | - | |
| 672 | - | |
| 673 | - | |
| 674 | - | |
| 675 | - | |
| 676 | void QBoxLayout::addStretch(int stretch) | - |
| 677 | { | - |
| 678 | insertStretch(-1, stretch); | - |
| 679 | } | - |
| 680 | void QBoxLayout::addSpacerItem(QSpacerItem *spacerItem) | - |
| 681 | { | - |
| 682 | insertSpacerItem(-1, spacerItem); | - |
| 683 | } | - |
| 684 | void QBoxLayout::addWidget(QWidget *widget, int stretch, Qt::Alignment alignment) | - |
| 685 | { | - |
| 686 | insertWidget(-1, widget, stretch, alignment); | - |
| 687 | } | - |
| 688 | - | |
| 689 | - | |
| 690 | - | |
| 691 | - | |
| 692 | - | |
| 693 | - | |
| 694 | - | |
| 695 | void QBoxLayout::addLayout(QLayout *layout, int stretch) | - |
| 696 | { | - |
| 697 | insertLayout(-1, layout, stretch); | - |
| 698 | } | - |
| 699 | void QBoxLayout::addStrut(int size) | - |
| 700 | { | - |
| 701 | QBoxLayoutPrivate * const d = d_func(); | - |
| 702 | QLayoutItem *b; | - |
| 703 | if (horz(d->dir)) | - |
| 704 | b = QLayoutPrivate::createSpacerItem(this, 0, size, QSizePolicy::Fixed, QSizePolicy::Minimum); | - |
| 705 | else | - |
| 706 | b = QLayoutPrivate::createSpacerItem(this, size, 0, QSizePolicy::Minimum, QSizePolicy::Fixed); | - |
| 707 | - | |
| 708 | QBoxLayoutItem *it = new QBoxLayoutItem(b); | - |
| 709 | it->magic = true; | - |
| 710 | d->list.append(it); | - |
| 711 | invalidate(); | - |
| 712 | } | - |
| 713 | bool QBoxLayout::setStretchFactor(QWidget *widget, int stretch) | - |
| 714 | { | - |
| 715 | QBoxLayoutPrivate * const d = d_func(); | - |
| 716 | if (!widget) | - |
| 717 | return false; | - |
| 718 | for (int i = 0; i < d->list.size(); ++i) { | - |
| 719 | QBoxLayoutItem *box = d->list.at(i); | - |
| 720 | if (box->item->widget() == widget) { | - |
| 721 | box->stretch = stretch; | - |
| 722 | invalidate(); | - |
| 723 | return true; | - |
| 724 | } | - |
| 725 | } | - |
| 726 | return false; | - |
| 727 | } | - |
| 728 | bool QBoxLayout::setStretchFactor(QLayout *layout, int stretch) | - |
| 729 | { | - |
| 730 | QBoxLayoutPrivate * const d = d_func(); | - |
| 731 | for (int i = 0; i < d->list.size(); ++i) { | - |
| 732 | QBoxLayoutItem *box = d->list.at(i); | - |
| 733 | if (box->item->layout() == layout) { | - |
| 734 | if (box->stretch != stretch) { | - |
| 735 | box->stretch = stretch; | - |
| 736 | invalidate(); | - |
| 737 | } | - |
| 738 | return true; | - |
| 739 | } | - |
| 740 | } | - |
| 741 | return false; | - |
| 742 | } | - |
| 743 | - | |
| 744 | - | |
| 745 | - | |
| 746 | - | |
| 747 | - | |
| 748 | - | |
| 749 | - | |
| 750 | void QBoxLayout::setStretch(int index, int stretch) | - |
| 751 | { | - |
| 752 | QBoxLayoutPrivate * const d = d_func(); | - |
| 753 | if (index >= 0 && index < d->list.size()) { | - |
| 754 | QBoxLayoutItem *box = d->list.at(index); | - |
| 755 | if (box->stretch != stretch) { | - |
| 756 | box->stretch = stretch; | - |
| 757 | invalidate(); | - |
| 758 | } | - |
| 759 | } | - |
| 760 | } | - |
| 761 | - | |
| 762 | - | |
| 763 | - | |
| 764 | - | |
| 765 | - | |
| 766 | - | |
| 767 | - | |
| 768 | int QBoxLayout::stretch(int index) const | - |
| 769 | { | - |
| 770 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 771 | if (index >= 0 && index < d->list.size()) | - |
| 772 | return d->list.at(index)->stretch; | - |
| 773 | return -1; | - |
| 774 | } | - |
| 775 | - | |
| 776 | - | |
| 777 | - | |
| 778 | - | |
| 779 | void QBoxLayout::setDirection(Direction direction) | - |
| 780 | { | - |
| 781 | QBoxLayoutPrivate * const d = d_func(); | - |
| 782 | if (d->dir == direction) | - |
| 783 | return; | - |
| 784 | if (horz(d->dir) != horz(direction)) { | - |
| 785 | - | |
| 786 | - | |
| 787 | - | |
| 788 | - | |
| 789 | for (int i = 0; i < d->list.size(); ++i) { | - |
| 790 | QBoxLayoutItem *box = d->list.at(i); | - |
| 791 | if (box->magic) { | - |
| 792 | QSpacerItem *sp = box->item->spacerItem(); | - |
| 793 | if (sp) { | - |
| 794 | if (sp->expandingDirections() == Qt::Orientations(0) ) { | - |
| 795 | - | |
| 796 | QSize s = sp->sizeHint(); | - |
| 797 | sp->changeSize(s.height(), s.width(), | - |
| 798 | horz(direction) ? QSizePolicy::Fixed:QSizePolicy::Minimum, | - |
| 799 | horz(direction) ? QSizePolicy::Minimum:QSizePolicy::Fixed); | - |
| 800 | - | |
| 801 | } else { | - |
| 802 | - | |
| 803 | if (horz(direction)) | - |
| 804 | sp->changeSize(0, 0, QSizePolicy::Expanding, | - |
| 805 | QSizePolicy::Minimum); | - |
| 806 | else | - |
| 807 | sp->changeSize(0, 0, QSizePolicy::Minimum, | - |
| 808 | QSizePolicy::Expanding); | - |
| 809 | } | - |
| 810 | } | - |
| 811 | } | - |
| 812 | } | - |
| 813 | } | - |
| 814 | d->dir = direction; | - |
| 815 | invalidate(); | - |
| 816 | } | - |
| 817 | QBoxLayout::Direction QBoxLayout::direction() const | - |
| 818 | { | - |
| 819 | const QBoxLayoutPrivate * const d = d_func(); | - |
| 820 | return d->dir; | - |
| 821 | } | - |
| 822 | QHBoxLayout::QHBoxLayout(QWidget *parent) | - |
| 823 | : QBoxLayout(LeftToRight, parent) | - |
| 824 | { | - |
| 825 | } | - |
| 826 | - | |
| 827 | - | |
| 828 | - | |
| 829 | - | |
| 830 | - | |
| 831 | QHBoxLayout::QHBoxLayout() | - |
| 832 | : QBoxLayout(LeftToRight) | - |
| 833 | { | - |
| 834 | } | - |
| 835 | QHBoxLayout::~QHBoxLayout() | - |
| 836 | { | - |
| 837 | } | - |
| 838 | QVBoxLayout::QVBoxLayout(QWidget *parent) | - |
| 839 | : QBoxLayout(TopToBottom, parent) | - |
| 840 | { | - |
| 841 | } | - |
| 842 | - | |
| 843 | - | |
| 844 | - | |
| 845 | - | |
| 846 | - | |
| 847 | - | |
| 848 | QVBoxLayout::QVBoxLayout() | - |
| 849 | : QBoxLayout(TopToBottom) | - |
| 850 | { | - |
| 851 | } | - |
| 852 | - | |
| 853 | - | |
| 854 | - | |
| 855 | - | |
| 856 | - | |
| 857 | - | |
| 858 | - | |
| 859 | QVBoxLayout::~QVBoxLayout() | - |
| 860 | { | - |
| 861 | } | - |
| 862 | - | |
| 863 | - | |
| 864 | - | |
| Switch to Source code | Preprocessed file |