| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | | - |
| 27 | | - |
| 28 | | - |
| 29 | | - |
| 30 | | - |
| 31 | | - |
| 32 | | - |
| 33 | | - |
| 34 | | - |
| 35 | | - |
| 36 | | - |
| 37 | | - |
| 38 | | - |
| 39 | | - |
| 40 | #include "qstackedlayout.h" | - |
| 41 | #include "qlayout_p.h" | - |
| 42 | | - |
| 43 | #include <qlist.h> | - |
| 44 | #include "private/qwidget_p.h" | - |
| 45 | #include "private/qlayoutengine_p.h" | - |
| 46 | | - |
| 47 | QT_BEGIN_NAMESPACE | - |
| 48 | | - |
| 49 | class QStackedLayoutPrivate : public QLayoutPrivate | - |
| 50 | { | - |
| 51 | Q_DECLARE_PUBLIC(QStackedLayout) | - |
| 52 | public: | - |
| 53 | QStackedLayoutPrivate() : index(-1), stackingMode(QStackedLayout::StackOne) {} | - |
| 54 | QLayoutItem* replaceAt(int index, QLayoutItem *newitem) Q_DECL_OVERRIDE; | - |
| 55 | QList<QLayoutItem *> list; | - |
| 56 | int index; | - |
| 57 | QStackedLayout::StackingMode stackingMode; | - |
| 58 | }; | - |
| 59 | | - |
| 60 | QLayoutItem* QStackedLayoutPrivate::replaceAt(int idx, QLayoutItem *newitem) | - |
| 61 | { | - |
| 62 | Q_Q(QStackedLayout); | - |
| 63 | if (idx < 0 || idx >= list.size() || !newitem)| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 64 | return 0; never executed: return 0; | 0 |
| 65 | QWidget *wdg = newitem->widget(); | - |
| 66 | if (Q_UNLIKELY(!wdg))) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 67 | qWarning("QStackedLayout::replaceAt: Only widgets can be added"); | - |
| 68 | return 0; never executed: return 0; | 0 |
| 69 | } | - |
| 70 | QLayoutItem *orgitem = list.at(idx); | - |
| 71 | list.replace(idx, newitem); | - |
| 72 | if (idx == index)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 73 | q->setCurrentIndex(index); never executed: q->setCurrentIndex(index); | 0 |
| 74 | return orgitem; never executed: return orgitem; | 0 |
| 75 | } | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | | - |
| 80 | | - |
| 81 | | - |
| 82 | | - |
| 83 | | - |
| 84 | | - |
| 85 | | - |
| 86 | | - |
| 87 | | - |
| 88 | | - |
| 89 | | - |
| 90 | | - |
| 91 | | - |
| 92 | | - |
| 93 | | - |
| 94 | | - |
| 95 | | - |
| 96 | | - |
| 97 | | - |
| 98 | | - |
| 99 | | - |
| 100 | | - |
| 101 | | - |
| 102 | | - |
| 103 | | - |
| 104 | | - |
| 105 | | - |
| 106 | | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | | - |
| 113 | | - |
| 114 | | - |
| 115 | | - |
| 116 | | - |
| 117 | | - |
| 118 | | - |
| 119 | | - |
| 120 | | - |
| 121 | | - |
| 122 | | - |
| 123 | | - |
| 124 | | - |
| 125 | | - |
| 126 | | - |
| 127 | | - |
| 128 | | - |
| 129 | | - |
| 130 | | - |
| 131 | | - |
| 132 | | - |
| 133 | | - |
| 134 | | - |
| 135 | | - |
| 136 | | - |
| 137 | | - |
| 138 | | - |
| 139 | | - |
| 140 | | - |
| 141 | | - |
| 142 | | - |
| 143 | | - |
| 144 | | - |
| 145 | | - |
| 146 | | - |
| 147 | | - |
| 148 | | - |
| 149 | | - |
| 150 | | - |
| 151 | | - |
| 152 | | - |
| 153 | | - |
| 154 | | - |
| 155 | | - |
| 156 | QStackedLayout::QStackedLayout() | - |
| 157 | : QLayout(*new QStackedLayoutPrivate, 0, 0) | - |
| 158 | { | - |
| 159 | } | - |
| 160 | | - |
| 161 | | - |
| 162 | | - |
| 163 | | - |
| 164 | | - |
| 165 | | - |
| 166 | | - |
| 167 | QStackedLayout::QStackedLayout(QWidget *parent) | - |
| 168 | : QLayout(*new QStackedLayoutPrivate, 0, parent) | - |
| 169 | { | - |
| 170 | } | - |
| 171 | | - |
| 172 | | - |
| 173 | | - |
| 174 | | - |
| 175 | | - |
| 176 | QStackedLayout::QStackedLayout(QLayout *parentLayout) | - |
| 177 | : QLayout(*new QStackedLayoutPrivate, parentLayout, 0) | - |
| 178 | { | - |
| 179 | } | - |
| 180 | | - |
| 181 | | - |
| 182 | | - |
| 183 | | - |
| 184 | | - |
| 185 | QStackedLayout::~QStackedLayout() | - |
| 186 | { | - |
| 187 | Q_D(QStackedLayout); | - |
| 188 | qDeleteAll(d->list); | - |
| 189 | } | - |
| 190 | | - |
| 191 | | - |
| 192 | | - |
| 193 | | - |
| 194 | | - |
| 195 | | - |
| 196 | | - |
| 197 | | - |
| 198 | | - |
| 199 | | - |
| 200 | int QStackedLayout::addWidget(QWidget *widget) | - |
| 201 | { | - |
| 202 | Q_D(QStackedLayout); | - |
| 203 | return insertWidget(d->list.count(), widget); | - |
| 204 | } | - |
| 205 | | - |
| 206 | | - |
| 207 | | - |
| 208 | | - |
| 209 | | - |
| 210 | | - |
| 211 | | - |
| 212 | | - |
| 213 | | - |
| 214 | | - |
| 215 | | - |
| 216 | | - |
| 217 | | - |
| 218 | | - |
| 219 | | - |
| 220 | int QStackedLayout::insertWidget(int index, QWidget *widget) | - |
| 221 | { | - |
| 222 | Q_D(QStackedLayout); | - |
| 223 | addChildWidget(widget); | - |
| 224 | index = qMin(index, d->list.count()); | - |
| 225 | if (index < 0) | - |
| 226 | index = d->list.count(); | - |
| 227 | QWidgetItem *wi = QLayoutPrivate::createWidgetItem(this, widget); | - |
| 228 | d->list.insert(index, wi); | - |
| 229 | invalidate(); | - |
| 230 | if (d->index < 0) { | - |
| 231 | setCurrentIndex(index); | - |
| 232 | } else { | - |
| 233 | if (index <= d->index) | - |
| 234 | ++d->index; | - |
| 235 | if (d->stackingMode == StackOne) | - |
| 236 | widget->hide(); | - |
| 237 | widget->lower(); | - |
| 238 | } | - |
| 239 | return index; | - |
| 240 | } | - |
| 241 | | - |
| 242 | | - |
| 243 | | - |
| 244 | | - |
| 245 | QLayoutItem *QStackedLayout::itemAt(int index) const | - |
| 246 | { | - |
| 247 | Q_D(const QStackedLayout); | - |
| 248 | return d->list.value(index); | - |
| 249 | } | - |
| 250 | | - |
| 251 | | - |
| 252 | | - |
| 253 | | - |
| 254 | static bool qt_wasDeleted(const QWidget *w) | - |
| 255 | { | - |
| 256 | return QWidgetPrivate::get(w)->wasDeleted; | - |
| 257 | } | - |
| 258 | | - |
| 259 | | - |
| 260 | | - |
| 261 | | - |
| 262 | | - |
| 263 | QLayoutItem *QStackedLayout::takeAt(int index) | - |
| 264 | { | - |
| 265 | Q_D(QStackedLayout); | - |
| 266 | if (index <0 || index >= d->list.size()) | - |
| 267 | return 0; | - |
| 268 | QLayoutItem *item = d->list.takeAt(index); | - |
| 269 | if (index == d->index) { | - |
| 270 | d->index = -1; | - |
| 271 | if ( d->list.count() > 0 ) { | - |
| 272 | int newIndex = (index == d->list.count()) ? index-1 : index; | - |
| 273 | setCurrentIndex(newIndex); | - |
| 274 | } else { | - |
| 275 | emit currentChanged(-1); | - |
| 276 | } | - |
| 277 | } else if (index < d->index) { | - |
| 278 | --d->index; | - |
| 279 | } | - |
| 280 | emit widgetRemoved(index); | - |
| 281 | if (item->widget() && !qt_wasDeleted(item->widget())) | - |
| 282 | item->widget()->hide(); | - |
| 283 | return item; | - |
| 284 | } | - |
| 285 | | - |
| 286 | | - |
| 287 | | - |
| 288 | | - |
| 289 | | - |
| 290 | | - |
| 291 | | - |
| 292 | | - |
| 293 | | - |
| 294 | void QStackedLayout::setCurrentIndex(int index) | - |
| 295 | { | - |
| 296 | Q_D(QStackedLayout); | - |
| 297 | QWidget *prev = currentWidget(); | - |
| 298 | QWidget *next = widget(index); | - |
| 299 | if (!next || next == prev) | - |
| 300 | return; | - |
| 301 | | - |
| 302 | bool reenableUpdates = false; | - |
| 303 | QWidget *parent = parentWidget(); | - |
| 304 | | - |
| 305 | if (parent && parent->updatesEnabled()) { | - |
| 306 | reenableUpdates = true; | - |
| 307 | parent->setUpdatesEnabled(false); | - |
| 308 | } | - |
| 309 | | - |
| 310 | QPointer<QWidget> fw = parent ? parent->window()->focusWidget() : 0; | - |
| 311 | const bool focusWasOnOldPage = fw && (prev && prev->isAncestorOf(fw)); | - |
| 312 | | - |
| 313 | if (prev) { | - |
| 314 | prev->clearFocus(); | - |
| 315 | if (d->stackingMode == StackOne) | - |
| 316 | prev->hide(); | - |
| 317 | } | - |
| 318 | | - |
| 319 | d->index = index; | - |
| 320 | next->raise(); | - |
| 321 | next->show(); | - |
| 322 | | - |
| 323 | | - |
| 324 | | - |
| 325 | | - |
| 326 | if (parent) { | - |
| 327 | if (focusWasOnOldPage) { | - |
| 328 | | - |
| 329 | if (QWidget *nfw = next->focusWidget()) | - |
| 330 | nfw->setFocus(); | - |
| 331 | else { | - |
| 332 | | - |
| 333 | if (QWidget *i = fw) { | - |
| 334 | while ((i = i->nextInFocusChain()) != fw) { | - |
| 335 | if (((i->focusPolicy() & Qt::TabFocus) == Qt::TabFocus) | - |
| 336 | && !i->focusProxy() && i->isVisibleTo(next) && i->isEnabled() | - |
| 337 | && next->isAncestorOf(i)) { | - |
| 338 | i->setFocus(); | - |
| 339 | break; | - |
| 340 | } | - |
| 341 | } | - |
| 342 | | - |
| 343 | if (i == fw ) | - |
| 344 | next->setFocus(); | - |
| 345 | } | - |
| 346 | } | - |
| 347 | } | - |
| 348 | } | - |
| 349 | if (reenableUpdates) | - |
| 350 | parent->setUpdatesEnabled(true); | - |
| 351 | emit currentChanged(index); | - |
| 352 | } | - |
| 353 | | - |
| 354 | int QStackedLayout::currentIndex() const | - |
| 355 | { | - |
| 356 | Q_D(const QStackedLayout); | - |
| 357 | return d->index; | - |
| 358 | } | - |
| 359 | | - |
| 360 | | - |
| 361 | | - |
| 362 | | - |
| 363 | | - |
| 364 | | - |
| 365 | | - |
| 366 | | - |
| 367 | | - |
| 368 | | - |
| 369 | void QStackedLayout::setCurrentWidget(QWidget *widget) | - |
| 370 | { | - |
| 371 | int index = indexOf(widget); | - |
| 372 | if (Q_UNLIKELY(index == -1))) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 373 | qWarning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget); | - |
| 374 | return; never executed: return; | 0 |
| 375 | } | - |
| 376 | setCurrentIndex(index); | - |
| 377 | } never executed: end of block | 0 |
| 378 | | - |
| 379 | | - |
| 380 | | - |
| 381 | | - |
| 382 | | - |
| 383 | | - |
| 384 | | - |
| 385 | | - |
| 386 | QWidget *QStackedLayout::currentWidget() const | - |
| 387 | { | - |
| 388 | Q_D(const QStackedLayout); | - |
| 389 | return d->index >= 0 ? d->list.at(d->index)->widget() : 0; | - |
| 390 | } | - |
| 391 | | - |
| 392 | | - |
| 393 | | - |
| 394 | | - |
| 395 | | - |
| 396 | | - |
| 397 | | - |
| 398 | QWidget *QStackedLayout::widget(int index) const | - |
| 399 | { | - |
| 400 | Q_D(const QStackedLayout); | - |
| 401 | if (index < 0 || index >= d->list.size()) | - |
| 402 | return 0; | - |
| 403 | return d->list.at(index)->widget(); | - |
| 404 | } | - |
| 405 | | - |
| 406 | | - |
| 407 | | - |
| 408 | | - |
| 409 | | - |
| 410 | | - |
| 411 | | - |
| 412 | int QStackedLayout::count() const | - |
| 413 | { | - |
| 414 | Q_D(const QStackedLayout); | - |
| 415 | return d->list.size(); | - |
| 416 | } | - |
| 417 | | - |
| 418 | | - |
| 419 | | - |
| 420 | | - |
| 421 | | - |
| 422 | void QStackedLayout::addItem(QLayoutItem *item) | - |
| 423 | { | - |
| 424 | QWidget *widget = item->widget(); | - |
| 425 | if (widget) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| addWidget| TRUE | never evaluated | | FALSE | never evaluated |
(Q_UNLIKELY(!widget);| TRUE | never evaluated | | FALSE | never evaluated |
| |
| delete item;| TRUE | never evaluated | | FALSE | never evaluated |
| |
| } else| TRUE | never evaluated | | FALSE | never evaluated |
)) {| TRUE | never evaluated | | FALSE | never evaluated |
| |
| 426 | qWarning("QStackedLayout::addItem: Only widgets can be added"); | - |
| 427 | return; never executed: return; | 0 |
| 428 | } | - |
| 429 | addWidget(widget); | - |
| 430 | delete item; | - |
| 431 | } never executed: end of block | 0 |
| 432 | | - |
| 433 | | - |
| 434 | | - |
| 435 | | - |
| 436 | QSize QStackedLayout::sizeHint() const | - |
| 437 | { | - |
| 438 | Q_D(const QStackedLayout); | - |
| 439 | QSize s(0, 0); | - |
| 440 | int n = d->list.count(); | - |
| 441 | | - |
| 442 | for (int i = 0; i < n; ++i) | - |
| 443 | if (QWidget *widget = d->list.at(i)->widget()) { | - |
| 444 | QSize ws(widget->sizeHint()); | - |
| 445 | if (widget->sizePolicy().horizontalPolicy() == QSizePolicy::Ignored) | - |
| 446 | ws.setWidth(0); | - |
| 447 | if (widget->sizePolicy().verticalPolicy() == QSizePolicy::Ignored) | - |
| 448 | ws.setHeight(0); | - |
| 449 | s = s.expandedTo(ws); | - |
| 450 | } | - |
| 451 | return s; | - |
| 452 | } | - |
| 453 | | - |
| 454 | | - |
| 455 | | - |
| 456 | | - |
| 457 | QSize QStackedLayout::minimumSize() const | - |
| 458 | { | - |
| 459 | Q_D(const QStackedLayout); | - |
| 460 | QSize s(0, 0); | - |
| 461 | int n = d->list.count(); | - |
| 462 | | - |
| 463 | for (int i = 0; i < n; ++i) | - |
| 464 | if (QWidget *widget = d->list.at(i)->widget()) | - |
| 465 | s = s.expandedTo(qSmartMinSize(widget)); | - |
| 466 | return s; | - |
| 467 | } | - |
| 468 | | - |
| 469 | | - |
| 470 | | - |
| 471 | | - |
| 472 | void QStackedLayout::setGeometry(const QRect &rect) | - |
| 473 | { | - |
| 474 | Q_D(QStackedLayout); | - |
| 475 | switch (d->stackingMode) { | - |
| 476 | case StackOne: | - |
| 477 | if (QWidget *widget = currentWidget()) | - |
| 478 | widget->setGeometry(rect); | - |
| 479 | break; | - |
| 480 | case StackAll: | - |
| 481 | if (const int n = d->list.count()) | - |
| 482 | for (int i = 0; i < n; ++i) | - |
| 483 | if (QWidget *widget = d->list.at(i)->widget()) | - |
| 484 | widget->setGeometry(rect); | - |
| 485 | break; | - |
| 486 | } | - |
| 487 | } | - |
| 488 | | - |
| 489 | | - |
| 490 | | - |
| 491 | | - |
| 492 | bool QStackedLayout::hasHeightForWidth() const | - |
| 493 | { | - |
| 494 | const int n = count(); | - |
| 495 | | - |
| 496 | for (int i = 0; i < n; ++i) { | - |
| 497 | if (QLayoutItem *item = itemAt(i)) { | - |
| 498 | if (item->hasHeightForWidth()) | - |
| 499 | return true; | - |
| 500 | } | - |
| 501 | } | - |
| 502 | return false; | - |
| 503 | } | - |
| 504 | | - |
| 505 | | - |
| 506 | | - |
| 507 | | - |
| 508 | int QStackedLayout::heightForWidth(int width) const | - |
| 509 | { | - |
| 510 | const int n = count(); | - |
| 511 | | - |
| 512 | int hfw = 0; | - |
| 513 | for (int i = 0; i < n; ++i) { | - |
| 514 | if (QLayoutItem *item = itemAt(i)) { | - |
| 515 | if (QWidget *w = item->widget()) | - |
| 516 | | - |
| 517 | | - |
| 518 | | - |
| 519 | | - |
| 520 | | - |
| 521 | | - |
| 522 | hfw = qMax(hfw, w->heightForWidth(width)); | - |
| 523 | } | - |
| 524 | } | - |
| 525 | hfw = qMax(hfw, minimumSize().height()); | - |
| 526 | return hfw; | - |
| 527 | } | - |
| 528 | | - |
| 529 | | - |
| 530 | | - |
| 531 | | - |
| 532 | | - |
| 533 | | - |
| 534 | | - |
| 535 | | - |
| 536 | | - |
| 537 | | - |
| 538 | | - |
| 539 | | - |
| 540 | | - |
| 541 | | - |
| 542 | | - |
| 543 | | - |
| 544 | | - |
| 545 | | - |
| 546 | | - |
| 547 | | - |
| 548 | | - |
| 549 | | - |
| 550 | | - |
| 551 | | - |
| 552 | | - |
| 553 | | - |
| 554 | | - |
| 555 | QStackedLayout::StackingMode QStackedLayout::stackingMode() const | - |
| 556 | { | - |
| 557 | Q_D(const QStackedLayout); | - |
| 558 | return d->stackingMode; | - |
| 559 | } | - |
| 560 | | - |
| 561 | void QStackedLayout::setStackingMode(StackingMode stackingMode) | - |
| 562 | { | - |
| 563 | Q_D(QStackedLayout); | - |
| 564 | if (d->stackingMode == stackingMode) | - |
| 565 | return; | - |
| 566 | d->stackingMode = stackingMode; | - |
| 567 | | - |
| 568 | const int n = d->list.count(); | - |
| 569 | if (n == 0) | - |
| 570 | return; | - |
| 571 | | - |
| 572 | switch (d->stackingMode) { | - |
| 573 | case StackOne: | - |
| 574 | if (const int idx = currentIndex()) | - |
| 575 | for (int i = 0; i < n; ++i) | - |
| 576 | if (QWidget *widget = d->list.at(i)->widget()) | - |
| 577 | widget->setVisible(i == idx); | - |
| 578 | break; | - |
| 579 | case StackAll: { | - |
| 580 | QRect geometry; | - |
| 581 | if (const QWidget *widget = currentWidget()) | - |
| 582 | geometry = widget->geometry(); | - |
| 583 | for (int i = 0; i < n; ++i) | - |
| 584 | if (QWidget *widget = d->list.at(i)->widget()) { | - |
| 585 | if (!geometry.isNull()) | - |
| 586 | widget->setGeometry(geometry); | - |
| 587 | widget->setVisible(true); | - |
| 588 | } | - |
| 589 | } | - |
| 590 | break; | - |
| 591 | } | - |
| 592 | } | - |
| 593 | | - |
| 594 | QT_END_NAMESPACE | - |
| 595 | | - |
| 596 | #include "moc_qstackedlayout.cpp" | - |
| | |