| 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 "qsplitter.h" | - |
| 41 | #ifndef QT_NO_SPLITTER | - |
| 42 | | - |
| 43 | #include "qapplication.h" | - |
| 44 | #include "qcursor.h" | - |
| 45 | #include "qdrawutil.h" | - |
| 46 | #include "qevent.h" | - |
| 47 | #include "qlayout.h" | - |
| 48 | #include "qlist.h" | - |
| 49 | #include "qpainter.h" | - |
| 50 | #include "qrubberband.h" | - |
| 51 | #include "qstyle.h" | - |
| 52 | #include "qstyleoption.h" | - |
| 53 | #include "qtextstream.h" | - |
| 54 | #include "qvarlengtharray.h" | - |
| 55 | #include "qvector.h" | - |
| 56 | #include "private/qlayoutengine_p.h" | - |
| 57 | #include "private/qsplitter_p.h" | - |
| 58 | #include "qtimer.h" | - |
| 59 | #include "qdebug.h" | - |
| 60 | | - |
| 61 | #include <ctype.h> | - |
| 62 | | - |
| 63 | QT_BEGIN_NAMESPACE | - |
| 64 | | - |
| 65 | | - |
| 66 | | - |
| 67 | QSplitterPrivate::~QSplitterPrivate() | - |
| 68 | { | - |
| 69 | } | - |
| 70 | | - |
| 71 | | - |
| 72 | | - |
| 73 | | - |
| 74 | | - |
| 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 | QSplitterHandle::QSplitterHandle(Qt::Orientation orientation, QSplitter *parent) | - |
| 121 | : QWidget(*new QSplitterHandlePrivate, parent, 0) | - |
| 122 | { | - |
| 123 | Q_D(QSplitterHandle); | - |
| 124 | d->s = parent; | - |
| 125 | setOrientation(orientation); | - |
| 126 | } | - |
| 127 | | - |
| 128 | | - |
| 129 | | - |
| 130 | | - |
| 131 | QSplitterHandle::~QSplitterHandle() | - |
| 132 | { | - |
| 133 | } | - |
| 134 | | - |
| 135 | | - |
| 136 | | - |
| 137 | | - |
| 138 | | - |
| 139 | | - |
| 140 | | - |
| 141 | void QSplitterHandle::setOrientation(Qt::Orientation orientation) | - |
| 142 | { | - |
| 143 | Q_D(QSplitterHandle); | - |
| 144 | d->orient = orientation; | - |
| 145 | #ifndef QT_NO_CURSOR | - |
| 146 | setCursor(orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor); | - |
| 147 | #endif | - |
| 148 | } | - |
| 149 | | - |
| 150 | | - |
| 151 | | - |
| 152 | | - |
| 153 | | - |
| 154 | | - |
| 155 | Qt::Orientation QSplitterHandle::orientation() const | - |
| 156 | { | - |
| 157 | Q_D(const QSplitterHandle); | - |
| 158 | return d->orient; | - |
| 159 | } | - |
| 160 | | - |
| 161 | | - |
| 162 | | - |
| 163 | | - |
| 164 | | - |
| 165 | | - |
| 166 | | - |
| 167 | | - |
| 168 | | - |
| 169 | bool QSplitterHandle::opaqueResize() const | - |
| 170 | { | - |
| 171 | Q_D(const QSplitterHandle); | - |
| 172 | return d->s->opaqueResize(); | - |
| 173 | } | - |
| 174 | | - |
| 175 | | - |
| 176 | | - |
| 177 | | - |
| 178 | | - |
| 179 | | - |
| 180 | | - |
| 181 | QSplitter *QSplitterHandle::splitter() const | - |
| 182 | { | - |
| 183 | return d_func()->s; | - |
| 184 | } | - |
| 185 | | - |
| 186 | | - |
| 187 | | - |
| 188 | | - |
| 189 | | - |
| 190 | | - |
| 191 | | - |
| 192 | | - |
| 193 | | - |
| 194 | | - |
| 195 | | - |
| 196 | void QSplitterHandle::moveSplitter(int pos) | - |
| 197 | { | - |
| 198 | Q_D(QSplitterHandle); | - |
| 199 | if (d->s->isRightToLeft() && d->orient == Qt::Horizontal) | - |
| 200 | pos = d->s->contentsRect().width() - pos; | - |
| 201 | d->s->moveSplitter(pos, d->s->indexOf(this)); | - |
| 202 | } | - |
| 203 | | - |
| 204 | | - |
| 205 | | - |
| 206 | | - |
| 207 | | - |
| 208 | | - |
| 209 | | - |
| 210 | | - |
| 211 | | - |
| 212 | int QSplitterHandle::closestLegalPosition(int pos) | - |
| 213 | { | - |
| 214 | Q_D(QSplitterHandle); | - |
| 215 | QSplitter *s = d->s; | - |
| 216 | if (s->isRightToLeft() && d->orient == Qt::Horizontal) { | - |
| 217 | int w = s->contentsRect().width(); | - |
| 218 | return w - s->closestLegalPosition(w - pos, s->indexOf(this)); | - |
| 219 | } | - |
| 220 | return s->closestLegalPosition(pos, s->indexOf(this)); | - |
| 221 | } | - |
| 222 | | - |
| 223 | | - |
| 224 | | - |
| 225 | | - |
| 226 | QSize QSplitterHandle::sizeHint() const | - |
| 227 | { | - |
| 228 | Q_D(const QSplitterHandle); | - |
| 229 | int hw = d->s->handleWidth(); | - |
| 230 | QStyleOption opt(0); | - |
| 231 | opt.init(d->s); | - |
| 232 | opt.state = QStyle::State_None; | - |
| 233 | return parentWidget()->style()->sizeFromContents(QStyle::CT_Splitter, &opt, QSize(hw, hw), d->s) | - |
| 234 | .expandedTo(QApplication::globalStrut()); | - |
| 235 | } | - |
| 236 | | - |
| 237 | | - |
| 238 | | - |
| 239 | | - |
| 240 | void QSplitterHandle::resizeEvent(QResizeEvent *event) | - |
| 241 | { | - |
| 242 | Q_D(const QSplitterHandle); | - |
| 243 | | - |
| 244 | | - |
| 245 | | - |
| 246 | | - |
| 247 | | - |
| 248 | | - |
| 249 | | - |
| 250 | | - |
| 251 | bool useTinyMode = (d->s->handleWidth() <= 1); | - |
| 252 | setAttribute(Qt::WA_MouseNoMask, useTinyMode); | - |
| 253 | if (useTinyMode) { | - |
| 254 | if (orientation() == Qt::Horizontal) | - |
| 255 | setContentsMargins(2, 0, 2, 0); | - |
| 256 | else | - |
| 257 | setContentsMargins(0, 2, 0, 2); | - |
| 258 | setMask(QRegion(contentsRect())); | - |
| 259 | } | - |
| 260 | | - |
| 261 | QWidget::resizeEvent(event); | - |
| 262 | } | - |
| 263 | | - |
| 264 | | - |
| 265 | | - |
| 266 | | - |
| 267 | bool QSplitterHandle::event(QEvent *event) | - |
| 268 | { | - |
| 269 | Q_D(QSplitterHandle); | - |
| 270 | switch(event->type()) { | - |
| 271 | case QEvent::HoverEnter: | - |
| 272 | d->hover = true; | - |
| 273 | update(); | - |
| 274 | break; | - |
| 275 | case QEvent::HoverLeave: | - |
| 276 | d->hover = false; | - |
| 277 | update(); | - |
| 278 | break; | - |
| 279 | default: | - |
| 280 | break; | - |
| 281 | } | - |
| 282 | return QWidget::event(event); | - |
| 283 | } | - |
| 284 | | - |
| 285 | | - |
| 286 | | - |
| 287 | | - |
| 288 | void QSplitterHandle::mouseMoveEvent(QMouseEvent *e) | - |
| 289 | { | - |
| 290 | Q_D(QSplitterHandle); | - |
| 291 | if (!(e->buttons() & Qt::LeftButton)) | - |
| 292 | return; | - |
| 293 | int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos())) | - |
| 294 | - d->mouseOffset; | - |
| 295 | if (opaqueResize()) { | - |
| 296 | moveSplitter(pos); | - |
| 297 | } else { | - |
| 298 | d->s->setRubberBand(closestLegalPosition(pos)); | - |
| 299 | } | - |
| 300 | } | - |
| 301 | | - |
| 302 | | - |
| 303 | | - |
| 304 | | - |
| 305 | void QSplitterHandle::mousePressEvent(QMouseEvent *e) | - |
| 306 | { | - |
| 307 | Q_D(QSplitterHandle); | - |
| 308 | if (e->button() == Qt::LeftButton) { | - |
| 309 | d->mouseOffset = d->pick(e->pos()); | - |
| 310 | d->pressed = true; | - |
| 311 | update(); | - |
| 312 | } | - |
| 313 | } | - |
| 314 | | - |
| 315 | | - |
| 316 | | - |
| 317 | | - |
| 318 | void QSplitterHandle::mouseReleaseEvent(QMouseEvent *e) | - |
| 319 | { | - |
| 320 | Q_D(QSplitterHandle); | - |
| 321 | if (!opaqueResize() && e->button() == Qt::LeftButton) { | - |
| 322 | int pos = d->pick(parentWidget()->mapFromGlobal(e->globalPos())) | - |
| 323 | - d->mouseOffset; | - |
| 324 | d->s->setRubberBand(-1); | - |
| 325 | moveSplitter(pos); | - |
| 326 | } | - |
| 327 | if (e->button() == Qt::LeftButton) { | - |
| 328 | d->pressed = false; | - |
| 329 | update(); | - |
| 330 | } | - |
| 331 | } | - |
| 332 | | - |
| 333 | | - |
| 334 | | - |
| 335 | | - |
| 336 | void QSplitterHandle::paintEvent(QPaintEvent *) | - |
| 337 | { | - |
| 338 | Q_D(QSplitterHandle); | - |
| 339 | QPainter p(this); | - |
| 340 | QStyleOption opt(0); | - |
| 341 | opt.rect = contentsRect(); | - |
| 342 | opt.palette = palette(); | - |
| 343 | if (orientation() == Qt::Horizontal) | - |
| 344 | opt.state = QStyle::State_Horizontal; | - |
| 345 | else | - |
| 346 | opt.state = QStyle::State_None; | - |
| 347 | if (d->hover) | - |
| 348 | opt.state |= QStyle::State_MouseOver; | - |
| 349 | if (d->pressed) | - |
| 350 | opt.state |= QStyle::State_Sunken; | - |
| 351 | if (isEnabled()) | - |
| 352 | opt.state |= QStyle::State_Enabled; | - |
| 353 | parentWidget()->style()->drawControl(QStyle::CE_Splitter, &opt, &p, d->s); | - |
| 354 | } | - |
| 355 | | - |
| 356 | | - |
| 357 | int QSplitterLayoutStruct::getWidgetSize(Qt::Orientation orient) | - |
| 358 | { | - |
| 359 | if (sizer == -1) { | - |
| 360 | QSize s = widget->sizeHint(); | - |
| 361 | const int presizer = pick(s, orient); | - |
| 362 | const int realsize = pick(widget->size(), orient); | - |
| 363 | if (!s.isValid() || (widget->testAttribute(Qt::WA_Resized) && (realsize > presizer))) { | - |
| 364 | sizer = pick(widget->size(), orient); | - |
| 365 | } else { | - |
| 366 | sizer = presizer; | - |
| 367 | } | - |
| 368 | QSizePolicy p = widget->sizePolicy(); | - |
| 369 | int sf = (orient == Qt::Horizontal) ? p.horizontalStretch() : p.verticalStretch(); | - |
| 370 | if (sf > 1) | - |
| 371 | sizer *= sf; | - |
| 372 | } | - |
| 373 | return sizer; | - |
| 374 | } | - |
| 375 | | - |
| 376 | int QSplitterLayoutStruct::getHandleSize(Qt::Orientation orient) | - |
| 377 | { | - |
| 378 | return pick(handle->sizeHint(), orient); | - |
| 379 | } | - |
| 380 | | - |
| 381 | void QSplitterPrivate::init() | - |
| 382 | { | - |
| 383 | Q_Q(QSplitter); | - |
| 384 | QSizePolicy sp(QSizePolicy::Expanding, QSizePolicy::Preferred); | - |
| 385 | if (orient == Qt::Vertical) | - |
| 386 | sp.transpose(); | - |
| 387 | q->setSizePolicy(sp); | - |
| 388 | q->setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - |
| 389 | } | - |
| 390 | | - |
| 391 | void QSplitterPrivate::recalc(bool update) | - |
| 392 | { | - |
| 393 | Q_Q(QSplitter); | - |
| 394 | int n = list.count(); | - |
| 395 | | - |
| 396 | | - |
| 397 | | - |
| 398 | | - |
| 399 | bool first = true; | - |
| 400 | bool allInvisible = n != 0; | - |
| 401 | for (int i = 0; i < n ; ++i) { | - |
| 402 | QSplitterLayoutStruct *s = list.at(i); | - |
| 403 | bool widgetHidden = s->widget->isHidden(); | - |
| 404 | if (allInvisible && !widgetHidden && !s->collapsed) | - |
| 405 | allInvisible = false; | - |
| 406 | s->handle->setHidden(first || widgetHidden); | - |
| 407 | if (!widgetHidden) | - |
| 408 | first = false; | - |
| 409 | } | - |
| 410 | | - |
| 411 | if (allInvisible) | - |
| 412 | for (int i = 0; i < n ; ++i) { | - |
| 413 | QSplitterLayoutStruct *s = list.at(i); | - |
| 414 | if (!s->widget->isHidden()) { | - |
| 415 | s->collapsed = false; | - |
| 416 | break; | - |
| 417 | } | - |
| 418 | } | - |
| 419 | | - |
| 420 | int fi = 2 * q->frameWidth(); | - |
| 421 | int maxl = fi; | - |
| 422 | int minl = fi; | - |
| 423 | int maxt = QWIDGETSIZE_MAX; | - |
| 424 | int mint = fi; | - |
| 425 | | - |
| 426 | | - |
| 427 | | - |
| 428 | bool empty = true; | - |
| 429 | for (int j = 0; j < n; j++) { | - |
| 430 | QSplitterLayoutStruct *s = list.at(j); | - |
| 431 | | - |
| 432 | if (!s->widget->isHidden()) { | - |
| 433 | empty = false; | - |
| 434 | if (!s->handle->isHidden()) { | - |
| 435 | minl += s->getHandleSize(orient); | - |
| 436 | maxl += s->getHandleSize(orient); | - |
| 437 | } | - |
| 438 | | - |
| 439 | QSize minS = qSmartMinSize(s->widget); | - |
| 440 | minl += pick(minS); | - |
| 441 | maxl += pick(s->widget->maximumSize()); | - |
| 442 | mint = qMax(mint, trans(minS)); | - |
| 443 | int tm = trans(s->widget->maximumSize()); | - |
| 444 | if (tm > 0) | - |
| 445 | maxt = qMin(maxt, tm); | - |
| 446 | } | - |
| 447 | } | - |
| 448 | | - |
| 449 | if (empty) { | - |
| 450 | if (qobject_cast<QSplitter *>(parent)) { | - |
| 451 | | - |
| 452 | maxl = maxt = 0; | - |
| 453 | } else { | - |
| 454 | | - |
| 455 | maxl = QWIDGETSIZE_MAX; | - |
| 456 | } | - |
| 457 | } else { | - |
| 458 | maxl = qMin<int>(maxl, QWIDGETSIZE_MAX); | - |
| 459 | } | - |
| 460 | if (maxt < mint) | - |
| 461 | maxt = mint; | - |
| 462 | | - |
| 463 | if (update) { | - |
| 464 | if (orient == Qt::Horizontal) { | - |
| 465 | q->setMaximumSize(maxl, maxt); | - |
| 466 | if (q->isWindow()) | - |
| 467 | q->setMinimumSize(minl,mint); | - |
| 468 | } else { | - |
| 469 | q->setMaximumSize(maxt, maxl); | - |
| 470 | if (q->isWindow()) | - |
| 471 | q->setMinimumSize(mint,minl); | - |
| 472 | } | - |
| 473 | doResize(); | - |
| 474 | q->updateGeometry(); | - |
| 475 | } else { | - |
| 476 | firstShow = true; | - |
| 477 | } | - |
| 478 | } | - |
| 479 | | - |
| 480 | void QSplitterPrivate::doResize() | - |
| 481 | { | - |
| 482 | Q_Q(QSplitter); | - |
| 483 | QRect r = q->contentsRect(); | - |
| 484 | int n = list.count(); | - |
| 485 | QVector<QLayoutStruct> a(n*2); | - |
| 486 | int i; | - |
| 487 | | - |
| 488 | bool noStretchFactorsSet = true; | - |
| 489 | for (i = 0; i < n; ++i) { | - |
| 490 | QSizePolicy p = list.at(i)->widget->sizePolicy(); | - |
| 491 | int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch(); | - |
| 492 | if (sf != 0) { | - |
| 493 | noStretchFactorsSet = false; | - |
| 494 | break; | - |
| 495 | } | - |
| 496 | } | - |
| 497 | | - |
| 498 | int j=0; | - |
| 499 | for (i = 0; i < n; ++i) { | - |
| 500 | QSplitterLayoutStruct *s = list.at(i); | - |
| 501 | #ifdef QSPLITTER_DEBUG | - |
| 502 | qDebug("widget %d hidden: %d collapsed: %d handle hidden: %d", i, s->widget->isHidden(), | - |
| 503 | s->collapsed, s->handle->isHidden()); | - |
| 504 | #endif | - |
| 505 | | - |
| 506 | a[j].init(); | - |
| 507 | if (s->handle->isHidden()) { | - |
| 508 | a[j].maximumSize = 0; | - |
| 509 | } else { | - |
| 510 | a[j].sizeHint = a[j].minimumSize = a[j].maximumSize = s->getHandleSize(orient); | - |
| 511 | a[j].empty = false; | - |
| 512 | } | - |
| 513 | ++j; | - |
| 514 | | - |
| 515 | a[j].init(); | - |
| 516 | if (s->widget->isHidden() || s->collapsed) { | - |
| 517 | a[j].maximumSize = 0; | - |
| 518 | } else { | - |
| 519 | a[j].minimumSize = pick(qSmartMinSize(s->widget)); | - |
| 520 | a[j].maximumSize = pick(s->widget->maximumSize()); | - |
| 521 | a[j].empty = false; | - |
| 522 | | - |
| 523 | bool stretch = noStretchFactorsSet; | - |
| 524 | if (!stretch) { | - |
| 525 | QSizePolicy p = s->widget->sizePolicy(); | - |
| 526 | int sf = orient == Qt::Horizontal ? p.horizontalStretch() : p.verticalStretch(); | - |
| 527 | stretch = (sf != 0); | - |
| 528 | } | - |
| 529 | if (stretch) { | - |
| 530 | a[j].stretch = s->getWidgetSize(orient); | - |
| 531 | a[j].sizeHint = a[j].minimumSize; | - |
| 532 | a[j].expansive = true; | - |
| 533 | } else { | - |
| 534 | a[j].sizeHint = qMax(s->getWidgetSize(orient), a[j].minimumSize); | - |
| 535 | } | - |
| 536 | } | - |
| 537 | ++j; | - |
| 538 | } | - |
| 539 | | - |
| 540 | qGeomCalc(a, 0, n*2, pick(r.topLeft()), pick(r.size()), 0); | - |
| 541 | | - |
| 542 | #ifdef QSPLITTER_DEBUG | - |
| 543 | for (i = 0; i < n*2; ++i) { | - |
| 544 | qDebug("%*s%d: stretch %d, sh %d, minS %d, maxS %d, exp %d, emp %d -> %d, %d", | - |
| 545 | i, "", i, | - |
| 546 | a[i].stretch, | - |
| 547 | a[i].sizeHint, | - |
| 548 | a[i].minimumSize, | - |
| 549 | a[i].maximumSize, | - |
| 550 | a[i].expansive, | - |
| 551 | a[i].empty, | - |
| 552 | a[i].pos, | - |
| 553 | a[i].size); | - |
| 554 | } | - |
| 555 | #endif | - |
| 556 | | - |
| 557 | for (i = 0; i < n; ++i) { | - |
| 558 | QSplitterLayoutStruct *s = list.at(i); | - |
| 559 | setGeo(s, a[i*2+1].pos, a[i*2+1].size, false); | - |
| 560 | } | - |
| 561 | } | - |
| 562 | | - |
| 563 | void QSplitterPrivate::storeSizes() | - |
| 564 | { | - |
| 565 | for (int i = 0; i < list.size(); ++i) { | - |
| 566 | QSplitterLayoutStruct *sls = list.at(i); | - |
| 567 | sls->sizer = pick(sls->rect.size()); | - |
| 568 | } | - |
| 569 | } | - |
| 570 | | - |
| 571 | void QSplitterPrivate::addContribution(int index, int *min, int *max, bool mayCollapse) const | - |
| 572 | { | - |
| 573 | QSplitterLayoutStruct *s = list.at(index); | - |
| 574 | if (!s->widget->isHidden()) { | - |
| 575 | if (!s->handle->isHidden()) { | - |
| 576 | *min += s->getHandleSize(orient); | - |
| 577 | *max += s->getHandleSize(orient); | - |
| 578 | } | - |
| 579 | if (mayCollapse || !s->collapsed) | - |
| 580 | *min += pick(qSmartMinSize(s->widget)); | - |
| 581 | | - |
| 582 | *max += pick(s->widget->maximumSize()); | - |
| 583 | } | - |
| 584 | } | - |
| 585 | | - |
| 586 | int QSplitterPrivate::findWidgetJustBeforeOrJustAfter(int index, int delta, int &collapsibleSize) const | - |
| 587 | { | - |
| 588 | if (delta < 0) | - |
| 589 | index += delta; | - |
| 590 | do { | - |
| 591 | QWidget *w = list.at(index)->widget; | - |
| 592 | if (!w->isHidden()) { | - |
| 593 | if (collapsible(list.at(index))) | - |
| 594 | collapsibleSize = pick(qSmartMinSize(w)); | - |
| 595 | return index; | - |
| 596 | } | - |
| 597 | index += delta; | - |
| 598 | } while (index >= 0 && index < list.count()); | - |
| 599 | | - |
| 600 | return -1; | - |
| 601 | } | - |
| 602 | | - |
| 603 | | - |
| 604 | | - |
| 605 | | - |
| 606 | | - |
| 607 | void QSplitterPrivate::getRange(int index, int *farMin, int *min, int *max, int *farMax) const | - |
| 608 | { | - |
| 609 | Q_Q(const QSplitter); | - |
| 610 | int n = list.count(); | - |
| 611 | if (index <= 0 || index >= n) | - |
| 612 | return; | - |
| 613 | | - |
| 614 | int collapsibleSizeBefore = 0; | - |
| 615 | int idJustBefore = findWidgetJustBeforeOrJustAfter(index, -1, collapsibleSizeBefore); | - |
| 616 | | - |
| 617 | int collapsibleSizeAfter = 0; | - |
| 618 | int idJustAfter = findWidgetJustBeforeOrJustAfter(index, +1, collapsibleSizeAfter); | - |
| 619 | | - |
| 620 | int minBefore = 0; | - |
| 621 | int minAfter = 0; | - |
| 622 | int maxBefore = 0; | - |
| 623 | int maxAfter = 0; | - |
| 624 | int i; | - |
| 625 | | - |
| 626 | for (i = 0; i < index; ++i) | - |
| 627 | addContribution(i, &minBefore, &maxBefore, i == idJustBefore); | - |
| 628 | for (i = index; i < n; ++i) | - |
| 629 | addContribution(i, &minAfter, &maxAfter, i == idJustAfter); | - |
| 630 | | - |
| 631 | QRect r = q->contentsRect(); | - |
| 632 | int farMinVal; | - |
| 633 | int minVal; | - |
| 634 | int maxVal; | - |
| 635 | int farMaxVal; | - |
| 636 | | - |
| 637 | int smartMinBefore = qMax(minBefore, pick(r.size()) - maxAfter); | - |
| 638 | int smartMaxBefore = qMin(maxBefore, pick(r.size()) - minAfter); | - |
| 639 | | - |
| 640 | minVal = pick(r.topLeft()) + smartMinBefore; | - |
| 641 | maxVal = pick(r.topLeft()) + smartMaxBefore; | - |
| 642 | | - |
| 643 | farMinVal = minVal; | - |
| 644 | if (minBefore - collapsibleSizeBefore >= pick(r.size()) - maxAfter) | - |
| 645 | farMinVal -= collapsibleSizeBefore; | - |
| 646 | farMaxVal = maxVal; | - |
| 647 | if (pick(r.size()) - (minAfter - collapsibleSizeAfter) <= maxBefore) | - |
| 648 | farMaxVal += collapsibleSizeAfter; | - |
| 649 | | - |
| 650 | if (farMin) | - |
| 651 | *farMin = farMinVal; | - |
| 652 | if (min) | - |
| 653 | *min = minVal; | - |
| 654 | if (max) | - |
| 655 | *max = maxVal; | - |
| 656 | if (farMax) | - |
| 657 | *farMax = farMaxVal; | - |
| 658 | } | - |
| 659 | | - |
| 660 | int QSplitterPrivate::adjustPos(int pos, int index, int *farMin, int *min, int *max, int *farMax) const | - |
| 661 | { | - |
| 662 | const int Threshold = 40; | - |
| 663 | | - |
| 664 | getRange(index, farMin, min, max, farMax); | - |
| 665 | | - |
| 666 | if (pos >= *min) { | - |
| 667 | if (pos <= *max) { | - |
| 668 | return pos; | - |
| 669 | } else { | - |
| 670 | int delta = pos - *max; | - |
| 671 | int width = *farMax - *max; | - |
| 672 | | - |
| 673 | if (delta > width / 2 && delta >= qMin(Threshold, width)) { | - |
| 674 | return *farMax; | - |
| 675 | } else { | - |
| 676 | return *max; | - |
| 677 | } | - |
| 678 | } | - |
| 679 | } else { | - |
| 680 | int delta = *min - pos; | - |
| 681 | int width = *min - *farMin; | - |
| 682 | | - |
| 683 | if (delta > width / 2 && delta >= qMin(Threshold, width)) { | - |
| 684 | return *farMin; | - |
| 685 | } else { | - |
| 686 | return *min; | - |
| 687 | } | - |
| 688 | } | - |
| 689 | } | - |
| 690 | | - |
| 691 | bool QSplitterPrivate::collapsible(QSplitterLayoutStruct *s) const | - |
| 692 | { | - |
| 693 | if (s->collapsible != Default) { | - |
| 694 | return (bool)s->collapsible; | - |
| 695 | } else { | - |
| 696 | return childrenCollapsible; | - |
| 697 | } | - |
| 698 | } | - |
| 699 | | - |
| 700 | void QSplitterPrivate::updateHandles() | - |
| 701 | { | - |
| 702 | Q_Q(QSplitter); | - |
| 703 | recalc(q->isVisible()); | - |
| 704 | } | - |
| 705 | | - |
| 706 | void QSplitterPrivate::setSizes_helper(const QList<int> &sizes, bool clampNegativeSize) | - |
| 707 | { | - |
| 708 | int j = 0; | - |
| 709 | | - |
| 710 | for (int i = 0; i < list.size(); ++i) { | - |
| 711 | QSplitterLayoutStruct *s = list.at(i); | - |
| 712 | | - |
| 713 | s->collapsed = false; | - |
| 714 | s->sizer = sizes.value(j++); | - |
| 715 | if (clampNegativeSize && s->sizer < 0) | - |
| 716 | s->sizer = 0; | - |
| 717 | int smartMinSize = pick(qSmartMinSize(s->widget)); | - |
| 718 | | - |
| 719 | | - |
| 720 | if (s->sizer == 0) { | - |
| 721 | if (collapsible(s) && smartMinSize > 0) { | - |
| 722 | s->collapsed = true; | - |
| 723 | } else { | - |
| 724 | s->sizer = smartMinSize; | - |
| 725 | } | - |
| 726 | } else { | - |
| 727 | if (s->sizer < smartMinSize) | - |
| 728 | s->sizer = smartMinSize; | - |
| 729 | } | - |
| 730 | } | - |
| 731 | doResize(); | - |
| 732 | } | - |
| 733 | | - |
| 734 | void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool allowCollapse) | - |
| 735 | { | - |
| 736 | Q_Q(QSplitter); | - |
| 737 | QWidget *w = sls->widget; | - |
| 738 | QRect r; | - |
| 739 | QRect contents = q->contentsRect(); | - |
| 740 | if (orient == Qt::Horizontal) { | - |
| 741 | r.setRect(p, contents.y(), s, contents.height()); | - |
| 742 | } else { | - |
| 743 | r.setRect(contents.x(), p, contents.width(), s); | - |
| 744 | } | - |
| 745 | sls->rect = r; | - |
| 746 | | - |
| 747 | int minSize = pick(qSmartMinSize(w)); | - |
| 748 | | - |
| 749 | if (orient == Qt::Horizontal && q->isRightToLeft()) | - |
| 750 | r.moveRight(contents.width() - r.left()); | - |
| 751 | | - |
| 752 | if (allowCollapse) | - |
| 753 | sls->collapsed = s <= 0 && minSize > 0 && !w->isHidden(); | - |
| 754 | | - |
| 755 | | - |
| 756 | | - |
| 757 | if (sls->collapsed) | - |
| 758 | r.moveTopLeft(QPoint(-r.width()-1, -r.height()-1)); | - |
| 759 | | - |
| 760 | w->setGeometry(r); | - |
| 761 | | - |
| 762 | if (!sls->handle->isHidden()) { | - |
| 763 | QSplitterHandle *h = sls->handle; | - |
| 764 | QSize hs = h->sizeHint(); | - |
| 765 | int left, top, right, bottom; | - |
| 766 | h->getContentsMargins(&left, &top, &right, &bottom); | - |
| 767 | if (orient==Qt::Horizontal) { | - |
| 768 | if (q->isRightToLeft()) | - |
| 769 | p = contents.width() - p + hs.width(); | - |
| 770 | h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height()); | - |
| 771 | } else { | - |
| 772 | h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom); | - |
| 773 | } | - |
| 774 | } | - |
| 775 | } | - |
| 776 | | - |
| 777 | void QSplitterPrivate::doMove(bool backwards, int hPos, int index, int delta, bool mayCollapse, | - |
| 778 | int *positions, int *widths) | - |
| 779 | { | - |
| 780 | if (index < 0 || index >= list.count()) | - |
| 781 | return; | - |
| 782 | | - |
| 783 | #ifdef QSPLITTER_DEBUG | - |
| 784 | qDebug() << "QSplitterPrivate::doMove" << backwards << hPos << index << delta << mayCollapse; | - |
| 785 | #endif | - |
| 786 | | - |
| 787 | QSplitterLayoutStruct *s = list.at(index); | - |
| 788 | QWidget *w = s->widget; | - |
| 789 | | - |
| 790 | int nextId = backwards ? index - delta : index + delta; | - |
| 791 | | - |
| 792 | if (w->isHidden()) { | - |
| 793 | doMove(backwards, hPos, nextId, delta, collapsible(nextId), positions, widths); | - |
| 794 | } else { | - |
| 795 | int hs =s->handle->isHidden() ? 0 : s->getHandleSize(orient); | - |
| 796 | | - |
| 797 | int ws = backwards ? hPos - pick(s->rect.topLeft()) | - |
| 798 | : pick(s->rect.bottomRight()) - hPos -hs + 1; | - |
| 799 | if (ws > 0 || (!s->collapsed && !mayCollapse)) { | - |
| 800 | ws = qMin(ws, pick(w->maximumSize())); | - |
| 801 | ws = qMax(ws, pick(qSmartMinSize(w))); | - |
| 802 | } else { | - |
| 803 | ws = 0; | - |
| 804 | } | - |
| 805 | positions[index] = backwards ? hPos - ws : hPos + hs; | - |
| 806 | widths[index] = ws; | - |
| 807 | doMove(backwards, backwards ? hPos - ws - hs : hPos + hs + ws, nextId, delta, | - |
| 808 | collapsible(nextId), positions, widths); | - |
| 809 | } | - |
| 810 | | - |
| 811 | } | - |
| 812 | | - |
| 813 | QSplitterLayoutStruct *QSplitterPrivate::findWidget(QWidget *w) const | - |
| 814 | { | - |
| 815 | for (int i = 0; i < list.size(); ++i) { | - |
| 816 | if (list.at(i)->widget == w) | - |
| 817 | return list.at(i); | - |
| 818 | } | - |
| 819 | return 0; | - |
| 820 | } | - |
| 821 | | - |
| 822 | | - |
| 823 | | - |
| 824 | | - |
| 825 | | - |
| 826 | void QSplitterPrivate::insertWidget_helper(int index, QWidget *widget, bool show) | - |
| 827 | { | - |
| 828 | Q_Q(QSplitter); | - |
| 829 | QBoolBlocker b(blockChildAdd); | - |
| 830 | bool needShow = show && q->isVisible() && | - |
| 831 | !(widget->isHidden() && widget->testAttribute(Qt::WA_WState_ExplicitShowHide)); | - |
| 832 | if (widget->parentWidget() != q) | - |
| 833 | widget->setParent(q); | - |
| 834 | if (needShow) | - |
| 835 | widget->show(); | - |
| 836 | insertWidget(index, widget); | - |
| 837 | recalc(q->isVisible()); | - |
| 838 | } | - |
| 839 | | - |
| 840 | | - |
| 841 | | - |
| 842 | | - |
| 843 | | - |
| 844 | | - |
| 845 | | - |
| 846 | QSplitterLayoutStruct *QSplitterPrivate::insertWidget(int index, QWidget *w) | - |
| 847 | { | - |
| 848 | Q_Q(QSplitter); | - |
| 849 | QSplitterLayoutStruct *sls = 0; | - |
| 850 | int i; | - |
| 851 | int last = list.count(); | - |
| 852 | for (i = 0; i < list.size(); ++i) { | - |
| 853 | QSplitterLayoutStruct *s = list.at(i); | - |
| 854 | if (s->widget == w) { | - |
| 855 | sls = s; | - |
| 856 | --last; | - |
| 857 | break; | - |
| 858 | } | - |
| 859 | } | - |
| 860 | if (index < 0 || index > last) | - |
| 861 | index = last; | - |
| 862 | | - |
| 863 | if (sls) { | - |
| 864 | list.move(i,index); | - |
| 865 | } else { | - |
| 866 | QSplitterHandle *newHandle = 0; | - |
| 867 | sls = new QSplitterLayoutStruct; | - |
| 868 | QString tmp = QLatin1String("qt_splithandle_"); | - |
| 869 | tmp += w->objectName(); | - |
| 870 | newHandle = q->createHandle(); | - |
| 871 | newHandle->setObjectName(tmp); | - |
| 872 | sls->handle = newHandle; | - |
| 873 | sls->widget = w; | - |
| 874 | w->lower(); | - |
| 875 | list.insert(index,sls); | - |
| 876 | | - |
| 877 | if (newHandle && q->isVisible()) | - |
| 878 | newHandle->show(); | - |
| 879 | | - |
| 880 | } | - |
| 881 | return sls; | - |
| 882 | } | - |
| 883 | | - |
| 884 | | - |
| 885 | | - |
| 886 | | - |
| 887 | | - |
| 888 | | - |
| 889 | | - |
| 890 | | - |
| 891 | | - |
| 892 | | - |
| 893 | | - |
| 894 | | - |
| 895 | | - |
| 896 | | - |
| 897 | | - |
| 898 | | - |
| 899 | | - |
| 900 | | - |
| 901 | | - |
| 902 | | - |
| 903 | | - |
| 904 | | - |
| 905 | | - |
| 906 | | - |
| 907 | | - |
| 908 | | - |
| 909 | | - |
| 910 | | - |
| 911 | | - |
| 912 | | - |
| 913 | | - |
| 914 | | - |
| 915 | | - |
| 916 | | - |
| 917 | | - |
| 918 | | - |
| 919 | | - |
| 920 | | - |
| 921 | | - |
| 922 | | - |
| 923 | | - |
| 924 | | - |
| 925 | | - |
| 926 | | - |
| 927 | | - |
| 928 | | - |
| 929 | | - |
| 930 | | - |
| 931 | | - |
| 932 | | - |
| 933 | | - |
| 934 | | - |
| 935 | | - |
| 936 | | - |
| 937 | | - |
| 938 | | - |
| 939 | | - |
| 940 | | - |
| 941 | | - |
| 942 | | - |
| 943 | QSplitter::QSplitter(QWidget *parent) | - |
| 944 | : QFrame(*new QSplitterPrivate, parent) | - |
| 945 | { | - |
| 946 | Q_D(QSplitter); | - |
| 947 | d->orient = Qt::Horizontal; | - |
| 948 | d->init(); | - |
| 949 | } | - |
| 950 | | - |
| 951 | | - |
| 952 | | - |
| 953 | | - |
| 954 | | - |
| 955 | | - |
| 956 | | - |
| 957 | QSplitter::QSplitter(Qt::Orientation orientation, QWidget *parent) | - |
| 958 | : QFrame(*new QSplitterPrivate, parent) | - |
| 959 | { | - |
| 960 | Q_D(QSplitter); | - |
| 961 | d->orient = orientation; | - |
| 962 | d->init(); | - |
| 963 | } | - |
| 964 | | - |
| 965 | | - |
| 966 | | - |
| 967 | | - |
| 968 | | - |
| 969 | | - |
| 970 | QSplitter::~QSplitter() | - |
| 971 | { | - |
| 972 | Q_D(QSplitter); | - |
| 973 | delete d->rubberBand; | - |
| 974 | while (!d->list.isEmpty()) | - |
| 975 | delete d->list.takeFirst(); | - |
| 976 | } | - |
| 977 | | - |
| 978 | | - |
| 979 | | - |
| 980 | | - |
| 981 | | - |
| 982 | void QSplitter::refresh() | - |
| 983 | { | - |
| 984 | Q_D(QSplitter); | - |
| 985 | d->recalc(true); | - |
| 986 | } | - |
| 987 | | - |
| 988 | | - |
| 989 | | - |
| 990 | | - |
| 991 | | - |
| 992 | | - |
| 993 | | - |
| 994 | | - |
| 995 | | - |
| 996 | | - |
| 997 | | - |
| 998 | | - |
| 999 | void QSplitter::setOrientation(Qt::Orientation orientation) | - |
| 1000 | { | - |
| 1001 | Q_D(QSplitter); | - |
| 1002 | if (d->orient == orientation) | - |
| 1003 | return; | - |
| 1004 | | - |
| 1005 | if (!testAttribute(Qt::WA_WState_OwnSizePolicy)) { | - |
| 1006 | QSizePolicy sp = sizePolicy(); | - |
| 1007 | sp.transpose(); | - |
| 1008 | setSizePolicy(sp); | - |
| 1009 | setAttribute(Qt::WA_WState_OwnSizePolicy, false); | - |
| 1010 | } | - |
| 1011 | | - |
| 1012 | d->orient = orientation; | - |
| 1013 | | - |
| 1014 | for (int i = 0; i < d->list.size(); ++i) { | - |
| 1015 | QSplitterLayoutStruct *s = d->list.at(i); | - |
| 1016 | s->handle->setOrientation(orientation); | - |
| 1017 | } | - |
| 1018 | d->recalc(isVisible()); | - |
| 1019 | } | - |
| 1020 | | - |
| 1021 | Qt::Orientation QSplitter::orientation() const | - |
| 1022 | { | - |
| 1023 | Q_D(const QSplitter); | - |
| 1024 | return d->orient; | - |
| 1025 | } | - |
| 1026 | | - |
| 1027 | | - |
| 1028 | | - |
| 1029 | | - |
| 1030 | | - |
| 1031 | | - |
| 1032 | | - |
| 1033 | | - |
| 1034 | | - |
| 1035 | | - |
| 1036 | | - |
| 1037 | | - |
| 1038 | void QSplitter::setChildrenCollapsible(bool collapse) | - |
| 1039 | { | - |
| 1040 | Q_D(QSplitter); | - |
| 1041 | d->childrenCollapsible = collapse; | - |
| 1042 | } | - |
| 1043 | | - |
| 1044 | bool QSplitter::childrenCollapsible() const | - |
| 1045 | { | - |
| 1046 | Q_D(const QSplitter); | - |
| 1047 | return d->childrenCollapsible; | - |
| 1048 | } | - |
| 1049 | | - |
| 1050 | | - |
| 1051 | | - |
| 1052 | | - |
| 1053 | | - |
| 1054 | | - |
| 1055 | | - |
| 1056 | | - |
| 1057 | | - |
| 1058 | | - |
| 1059 | | - |
| 1060 | | - |
| 1061 | | - |
| 1062 | | - |
| 1063 | void QSplitter::setCollapsible(int index, bool collapse) | - |
| 1064 | { | - |
| 1065 | Q_D(QSplitter); | - |
| 1066 | | - |
| 1067 | if (Q_UNLIKELY(index < 0 || index >= d->list.size())())) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1068 | qWarning("QSplitter::setCollapsible: Index %d out of range", index); | - |
| 1069 | return; never executed: return; | 0 |
| 1070 | } | - |
| 1071 | d->list.at(index)->collapsible = collapse ? 1 : 0;| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1072 | } never executed: end of block | 0 |
| 1073 | | - |
| 1074 | | - |
| 1075 | | - |
| 1076 | | - |
| 1077 | bool QSplitter::isCollapsible(int index) const | - |
| 1078 | { | - |
| 1079 | Q_D(const QSplitter); | - |
| 1080 | if (Q_UNLIKELY(index < 0 || index >= d->list.size())())) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1081 | qWarning("QSplitter::isCollapsible: Index %d out of range", index); | - |
| 1082 | return false; never executed: return false; | 0 |
| 1083 | } | - |
| 1084 | return d->list.at(index)->collapsible; never executed: return d->list.at(index)->collapsible; | 0 |
| 1085 | } | - |
| 1086 | | - |
| 1087 | | - |
| 1088 | | - |
| 1089 | | - |
| 1090 | void QSplitter::resizeEvent(QResizeEvent *) | - |
| 1091 | { | - |
| 1092 | Q_D(QSplitter); | - |
| 1093 | d->doResize(); | - |
| 1094 | } | - |
| 1095 | | - |
| 1096 | | - |
| 1097 | | - |
| 1098 | | - |
| 1099 | | - |
| 1100 | | - |
| 1101 | | - |
| 1102 | | - |
| 1103 | | - |
| 1104 | | - |
| 1105 | | - |
| 1106 | void QSplitter::addWidget(QWidget *widget) | - |
| 1107 | { | - |
| 1108 | Q_D(QSplitter); | - |
| 1109 | insertWidget(d->list.count(), widget); | - |
| 1110 | } | - |
| 1111 | | - |
| 1112 | | - |
| 1113 | | - |
| 1114 | | - |
| 1115 | | - |
| 1116 | | - |
| 1117 | | - |
| 1118 | | - |
| 1119 | | - |
| 1120 | | - |
| 1121 | | - |
| 1122 | | - |
| 1123 | | - |
| 1124 | void QSplitter::insertWidget(int index, QWidget *widget) | - |
| 1125 | { | - |
| 1126 | Q_D(QSplitter); | - |
| 1127 | d->insertWidget_helper(index, widget, true); | - |
| 1128 | } | - |
| 1129 | | - |
| 1130 | | - |
| 1131 | | - |
| 1132 | | - |
| 1133 | | - |
| 1134 | | - |
| 1135 | | - |
| 1136 | | - |
| 1137 | | - |
| 1138 | | - |
| 1139 | | - |
| 1140 | | - |
| 1141 | | - |
| 1142 | int QSplitter::indexOf(QWidget *w) const | - |
| 1143 | { | - |
| 1144 | Q_D(const QSplitter); | - |
| 1145 | for (int i = 0; i < d->list.size(); ++i) { | - |
| 1146 | QSplitterLayoutStruct *s = d->list.at(i); | - |
| 1147 | if (s->widget == w || s->handle == w) | - |
| 1148 | return i; | - |
| 1149 | } | - |
| 1150 | return -1; | - |
| 1151 | } | - |
| 1152 | | - |
| 1153 | | - |
| 1154 | | - |
| 1155 | | - |
| 1156 | | - |
| 1157 | | - |
| 1158 | | - |
| 1159 | | - |
| 1160 | QSplitterHandle *QSplitter::createHandle() | - |
| 1161 | { | - |
| 1162 | Q_D(QSplitter); | - |
| 1163 | return new QSplitterHandle(d->orient, this); | - |
| 1164 | } | - |
| 1165 | | - |
| 1166 | | - |
| 1167 | | - |
| 1168 | | - |
| 1169 | | - |
| 1170 | | - |
| 1171 | | - |
| 1172 | | - |
| 1173 | | - |
| 1174 | | - |
| 1175 | | - |
| 1176 | | - |
| 1177 | QSplitterHandle *QSplitter::handle(int index) const | - |
| 1178 | { | - |
| 1179 | Q_D(const QSplitter); | - |
| 1180 | if (index < 0 || index >= d->list.size()) | - |
| 1181 | return 0; | - |
| 1182 | return d->list.at(index)->handle; | - |
| 1183 | } | - |
| 1184 | | - |
| 1185 | | - |
| 1186 | | - |
| 1187 | | - |
| 1188 | | - |
| 1189 | | - |
| 1190 | QWidget *QSplitter::widget(int index) const | - |
| 1191 | { | - |
| 1192 | Q_D(const QSplitter); | - |
| 1193 | if (index < 0 || index >= d->list.size()) | - |
| 1194 | return 0; | - |
| 1195 | return d->list.at(index)->widget; | - |
| 1196 | } | - |
| 1197 | | - |
| 1198 | | - |
| 1199 | | - |
| 1200 | | - |
| 1201 | | - |
| 1202 | | - |
| 1203 | int QSplitter::count() const | - |
| 1204 | { | - |
| 1205 | Q_D(const QSplitter); | - |
| 1206 | return d->list.count(); | - |
| 1207 | } | - |
| 1208 | | - |
| 1209 | | - |
| 1210 | | - |
| 1211 | | - |
| 1212 | | - |
| 1213 | | - |
| 1214 | | - |
| 1215 | | - |
| 1216 | | - |
| 1217 | | - |
| 1218 | | - |
| 1219 | | - |
| 1220 | | - |
| 1221 | | - |
| 1222 | | - |
| 1223 | | - |
| 1224 | void QSplitter::childEvent(QChildEvent *c) | - |
| 1225 | { | - |
| 1226 | Q_D(QSplitter); | - |
| 1227 | if (!c->child()->isWidgetType()) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1228 | if (Q_UNLIKELY(c->type() == QEvent::ChildAdded && qobject_cast<QLayout *>(c->child()))())))| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1229 | qWarning("Adding a QLayout to a QSplitter is not supported."); never executed: QMessageLogger(__FILE__, 1229, __PRETTY_FUNCTION__).warning("Adding a QLayout to a QSplitter is not supported."); | 0 |
| 1230 | return; never executed: return; | 0 |
| 1231 | } | - |
| 1232 | QWidget *w = static_cast<QWidget*>(c->child()); | - |
| 1233 | if (w->isWindow())| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1234 | return; never executed: return; | 0 |
| 1235 | if (c->added() && !d->blockChildAdd && !d->findWidget(w)) {| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1236 | d->insertWidget_helper(d->list.count(), w, false); | - |
| 1237 | } else if (c->polished() && !d->blockChildAdd) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1238 | if (isVisible() && !(w->isHidden() && w->testAttribute(Qt::WA_WState_ExplicitShowHide)))| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1239 | w->show(); never executed: w->show(); | 0 |
| 1240 | } else if (c->type() == QEvent::ChildRemoved) { never executed: end of block | TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1241 | for (int i = 0; i < d->list.size(); ++i) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1242 | QSplitterLayoutStruct *s = d->list.at(i); | - |
| 1243 | if (s->widget == w) {| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 1244 | d->list.removeAt(i); | - |
| 1245 | delete s; | - |
| 1246 | d->recalc(isVisible()); | - |
| 1247 | return; never executed: return; | 0 |
| 1248 | } | - |
| 1249 | } never executed: end of block | 0 |
| 1250 | } never executed: end of block | 0 |
| 1251 | } never executed: end of block | 0 |
| 1252 | | - |
| 1253 | | - |
| 1254 | | - |
| 1255 | | - |
| 1256 | | - |
| 1257 | | - |
| 1258 | | - |
| 1259 | void QSplitter::setRubberBand(int pos) | - |
| 1260 | { | - |
| 1261 | Q_D(QSplitter); | - |
| 1262 | if (pos < 0) { | - |
| 1263 | if (d->rubberBand) | - |
| 1264 | d->rubberBand->deleteLater(); | - |
| 1265 | return; | - |
| 1266 | } | - |
| 1267 | QRect r = contentsRect(); | - |
| 1268 | const int rBord = 3; | - |
| 1269 | int hw = handleWidth(); | - |
| 1270 | if (!d->rubberBand) { | - |
| 1271 | QBoolBlocker b(d->blockChildAdd); | - |
| 1272 | d->rubberBand = new QRubberBand(QRubberBand::Line, this); | - |
| 1273 | | - |
| 1274 | d->rubberBand->setObjectName(QLatin1String("qt_rubberband")); | - |
| 1275 | } | - |
| 1276 | | - |
| 1277 | const QRect newGeom = d->orient == Qt::Horizontal ? QRect(QPoint(pos + hw / 2 - rBord, r.y()), QSize(2 * rBord, r.height())) | - |
| 1278 | : QRect(QPoint(r.x(), pos + hw / 2 - rBord), QSize(r.width(), 2 * rBord)); | - |
| 1279 | d->rubberBand->setGeometry(newGeom); | - |
| 1280 | d->rubberBand->show(); | - |
| 1281 | } | - |
| 1282 | | - |
| 1283 | | - |
| 1284 | | - |
| 1285 | | - |
| 1286 | | - |
| 1287 | bool QSplitter::event(QEvent *e) | - |
| 1288 | { | - |
| 1289 | Q_D(QSplitter); | - |
| 1290 | switch (e->type()) { | - |
| 1291 | case QEvent::Hide: | - |
| 1292 | | - |
| 1293 | if (!d->firstShow) | - |
| 1294 | d->firstShow = true; | - |
| 1295 | break; | - |
| 1296 | case QEvent::Show: | - |
| 1297 | if (!d->firstShow) | - |
| 1298 | break; | - |
| 1299 | d->firstShow = false; | - |
| 1300 | | - |
| 1301 | case QEvent::HideToParent: | - |
| 1302 | case QEvent::ShowToParent: | - |
| 1303 | case QEvent::LayoutRequest: | - |
| 1304 | d->recalc(isVisible()); | - |
| 1305 | break; | - |
| 1306 | default: | - |
| 1307 | ; | - |
| 1308 | } | - |
| 1309 | return QWidget::event(e); | - |
| 1310 | } | - |
| 1311 | | - |
| 1312 | | - |
| 1313 | | - |
| 1314 | | - |
| 1315 | | - |
| 1316 | | - |
| 1317 | | - |
| 1318 | | - |
| 1319 | | - |
| 1320 | | - |
| 1321 | | - |
| 1322 | | - |
| 1323 | | - |
| 1324 | | - |
| 1325 | | - |
| 1326 | | - |
| 1327 | | - |
| 1328 | | - |
| 1329 | | - |
| 1330 | | - |
| 1331 | | - |
| 1332 | | - |
| 1333 | | - |
| 1334 | | - |
| 1335 | | - |
| 1336 | void QSplitter::moveSplitter(int pos, int index) | - |
| 1337 | { | - |
| 1338 | Q_D(QSplitter); | - |
| 1339 | QSplitterLayoutStruct *s = d->list.at(index); | - |
| 1340 | int farMin; | - |
| 1341 | int min; | - |
| 1342 | int max; | - |
| 1343 | int farMax; | - |
| 1344 | | - |
| 1345 | #ifdef QSPLITTER_DEBUG | - |
| 1346 | int debugp = pos; | - |
| 1347 | #endif | - |
| 1348 | | - |
| 1349 | pos = d->adjustPos(pos, index, &farMin, &min, &max, &farMax); | - |
| 1350 | int oldP = d->pick(s->rect.topLeft()); | - |
| 1351 | #ifdef QSPLITTER_DEBUG | - |
| 1352 | qDebug() << "QSplitter::moveSplitter" << debugp << index << "adjusted" << pos << "oldP" << oldP; | - |
| 1353 | #endif | - |
| 1354 | | - |
| 1355 | QVarLengthArray<int, 32> poss(d->list.count()); | - |
| 1356 | QVarLengthArray<int, 32> ws(d->list.count()); | - |
| 1357 | bool upLeft; | - |
| 1358 | | - |
| 1359 | d->doMove(false, pos, index, +1, (d->collapsible(s) && (pos > max)), poss.data(), ws.data()); | - |
| 1360 | d->doMove(true, pos, index - 1, +1, (d->collapsible(index - 1) && (pos < min)), poss.data(), ws.data()); | - |
| 1361 | upLeft = (pos < oldP); | - |
| 1362 | | - |
| 1363 | int wid, delta, count = d->list.count(); | - |
| 1364 | if (upLeft) { | - |
| 1365 | wid = 0; | - |
| 1366 | delta = 1; | - |
| 1367 | } else { | - |
| 1368 | wid = count - 1; | - |
| 1369 | delta = -1; | - |
| 1370 | } | - |
| 1371 | for (; wid >= 0 && wid < count; wid += delta) { | - |
| 1372 | QSplitterLayoutStruct *sls = d->list.at( wid ); | - |
| 1373 | if (!sls->widget->isHidden()) | - |
| 1374 | d->setGeo(sls, poss[wid], ws[wid], true); | - |
| 1375 | } | - |
| 1376 | d->storeSizes(); | - |
| 1377 | | - |
| 1378 | emit splitterMoved(pos, index); | - |
| 1379 | } | - |
| 1380 | | - |
| 1381 | | - |
| 1382 | | - |
| 1383 | | - |
| 1384 | | - |
| 1385 | | - |
| 1386 | | - |
| 1387 | void QSplitter::getRange(int index, int *min, int *max) const | - |
| 1388 | { | - |
| 1389 | Q_D(const QSplitter); | - |
| 1390 | d->getRange(index, min, 0, 0, max); | - |
| 1391 | } | - |
| 1392 | | - |
| 1393 | | - |
| 1394 | | - |
| 1395 | | - |
| 1396 | | - |
| 1397 | | - |
| 1398 | | - |
| 1399 | | - |
| 1400 | | - |
| 1401 | | - |
| 1402 | | - |
| 1403 | | - |
| 1404 | int QSplitter::closestLegalPosition(int pos, int index) | - |
| 1405 | { | - |
| 1406 | Q_D(QSplitter); | - |
| 1407 | int x, i, n, u; | - |
| 1408 | return d->adjustPos(pos, index, &u, &n, &i, &x); | - |
| 1409 | } | - |
| 1410 | | - |
| 1411 | | - |
| 1412 | | - |
| 1413 | | - |
| 1414 | | - |
| 1415 | | - |
| 1416 | | - |
| 1417 | | - |
| 1418 | | - |
| 1419 | | - |
| 1420 | | - |
| 1421 | | - |
| 1422 | bool QSplitter::opaqueResize() const | - |
| 1423 | { | - |
| 1424 | Q_D(const QSplitter); | - |
| 1425 | return d->opaqueResizeSet ? d->opaque : style()->styleHint(QStyle::SH_Splitter_OpaqueResize, 0, this); | - |
| 1426 | } | - |
| 1427 | | - |
| 1428 | | - |
| 1429 | void QSplitter::setOpaqueResize(bool on) | - |
| 1430 | { | - |
| 1431 | Q_D(QSplitter); | - |
| 1432 | d->opaqueResizeSet = true; | - |
| 1433 | d->opaque = on; | - |
| 1434 | } | - |
| 1435 | | - |
| 1436 | | - |
| 1437 | | - |
| 1438 | | - |
| 1439 | | - |
| 1440 | QSize QSplitter::sizeHint() const | - |
| 1441 | { | - |
| 1442 | Q_D(const QSplitter); | - |
| 1443 | ensurePolished(); | - |
| 1444 | int l = 0; | - |
| 1445 | int t = 0; | - |
| 1446 | for (int i = 0; i < d->list.size(); ++i) { | - |
| 1447 | QWidget *w = d->list.at(i)->widget; | - |
| 1448 | if (w->isHidden()) | - |
| 1449 | continue; | - |
| 1450 | QSize s = w->sizeHint(); | - |
| 1451 | if (s.isValid()) { | - |
| 1452 | l += d->pick(s); | - |
| 1453 | t = qMax(t, d->trans(s)); | - |
| 1454 | } | - |
| 1455 | } | - |
| 1456 | return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); | - |
| 1457 | } | - |
| 1458 | | - |
| 1459 | | - |
| 1460 | | - |
| 1461 | | - |
| 1462 | | - |
| 1463 | | - |
| 1464 | QSize QSplitter::minimumSizeHint() const | - |
| 1465 | { | - |
| 1466 | Q_D(const QSplitter); | - |
| 1467 | ensurePolished(); | - |
| 1468 | int l = 0; | - |
| 1469 | int t = 0; | - |
| 1470 | | - |
| 1471 | for (int i = 0; i < d->list.size(); ++i) { | - |
| 1472 | QSplitterLayoutStruct *s = d->list.at(i); | - |
| 1473 | if (!s || !s->widget) | - |
| 1474 | continue; | - |
| 1475 | if (s->widget->isHidden()) | - |
| 1476 | continue; | - |
| 1477 | QSize widgetSize = qSmartMinSize(s->widget); | - |
| 1478 | if (widgetSize.isValid()) { | - |
| 1479 | l += d->pick(widgetSize); | - |
| 1480 | t = qMax(t, d->trans(widgetSize)); | - |
| 1481 | } | - |
| 1482 | if (!s->handle || s->handle->isHidden()) | - |
| 1483 | continue; | - |
| 1484 | QSize splitterSize = s->handle->sizeHint(); | - |
| 1485 | if (splitterSize.isValid()) { | - |
| 1486 | l += d->pick(splitterSize); | - |
| 1487 | t = qMax(t, d->trans(splitterSize)); | - |
| 1488 | } | - |
| 1489 | } | - |
| 1490 | return orientation() == Qt::Horizontal ? QSize(l, t) : QSize(t, l); | - |
| 1491 | } | - |
| 1492 | | - |
| 1493 | | - |
| 1494 | | - |
| 1495 | | - |
| 1496 | | - |
| 1497 | | - |
| 1498 | | - |
| 1499 | | - |
| 1500 | | - |
| 1501 | | - |
| 1502 | | - |
| 1503 | | - |
| 1504 | | - |
| 1505 | | - |
| 1506 | | - |
| 1507 | | - |
| 1508 | | - |
| 1509 | | - |
| 1510 | QList<int> QSplitter::sizes() const | - |
| 1511 | { | - |
| 1512 | Q_D(const QSplitter); | - |
| 1513 | ensurePolished(); | - |
| 1514 | | - |
| 1515 | const int numSizes = d->list.size(); | - |
| 1516 | QList<int> list; | - |
| 1517 | list.reserve(numSizes); | - |
| 1518 | | - |
| 1519 | for (int i = 0; i < numSizes; ++i) { | - |
| 1520 | QSplitterLayoutStruct *s = d->list.at(i); | - |
| 1521 | list.append(d->pick(s->rect.size())); | - |
| 1522 | } | - |
| 1523 | return list; | - |
| 1524 | } | - |
| 1525 | | - |
| 1526 | | - |
| 1527 | | - |
| 1528 | | - |
| 1529 | | - |
| 1530 | | - |
| 1531 | | - |
| 1532 | | - |
| 1533 | | - |
| 1534 | | - |
| 1535 | | - |
| 1536 | | - |
| 1537 | | - |
| 1538 | | - |
| 1539 | | - |
| 1540 | | - |
| 1541 | | - |
| 1542 | | - |
| 1543 | | - |
| 1544 | | - |
| 1545 | | - |
| 1546 | | - |
| 1547 | void QSplitter::setSizes(const QList<int> &list) | - |
| 1548 | { | - |
| 1549 | Q_D(QSplitter); | - |
| 1550 | d->setSizes_helper(list, true); | - |
| 1551 | } | - |
| 1552 | | - |
| 1553 | | - |
| 1554 | | - |
| 1555 | | - |
| 1556 | | - |
| 1557 | | - |
| 1558 | | - |
| 1559 | | - |
| 1560 | | - |
| 1561 | | - |
| 1562 | | - |
| 1563 | | - |
| 1564 | int QSplitter::handleWidth() const | - |
| 1565 | { | - |
| 1566 | Q_D(const QSplitter); | - |
| 1567 | if (d->handleWidth >= 0) { | - |
| 1568 | return d->handleWidth; | - |
| 1569 | } else { | - |
| 1570 | return style()->pixelMetric(QStyle::PM_SplitterWidth, 0, this); | - |
| 1571 | } | - |
| 1572 | } | - |
| 1573 | | - |
| 1574 | void QSplitter::setHandleWidth(int width) | - |
| 1575 | { | - |
| 1576 | Q_D(QSplitter); | - |
| 1577 | d->handleWidth = width; | - |
| 1578 | d->updateHandles(); | - |
| 1579 | } | - |
| 1580 | | - |
| 1581 | | - |
| 1582 | | - |
| 1583 | | - |
| 1584 | void QSplitter::changeEvent(QEvent *ev) | - |
| 1585 | { | - |
| 1586 | Q_D(QSplitter); | - |
| 1587 | if(ev->type() == QEvent::StyleChange) | - |
| 1588 | d->updateHandles(); | - |
| 1589 | QFrame::changeEvent(ev); | - |
| 1590 | } | - |
| 1591 | | - |
| 1592 | static const qint32 SplitterMagic = 0xff; | - |
| 1593 | | - |
| 1594 | | - |
| 1595 | | - |
| 1596 | | - |
| 1597 | | - |
| 1598 | | - |
| 1599 | | - |
| 1600 | | - |
| 1601 | | - |
| 1602 | | - |
| 1603 | | - |
| 1604 | | - |
| 1605 | QByteArray QSplitter::saveState() const | - |
| 1606 | { | - |
| 1607 | Q_D(const QSplitter); | - |
| 1608 | int version = 1; | - |
| 1609 | QByteArray data; | - |
| 1610 | QDataStream stream(&data, QIODevice::WriteOnly); | - |
| 1611 | | - |
| 1612 | stream << qint32(SplitterMagic); | - |
| 1613 | stream << qint32(version); | - |
| 1614 | const int numSizes = d->list.size(); | - |
| 1615 | QList<int> list; | - |
| 1616 | list.reserve(numSizes); | - |
| 1617 | for (int i = 0; i < numSizes; ++i) { | - |
| 1618 | QSplitterLayoutStruct *s = d->list.at(i); | - |
| 1619 | list.append(s->sizer); | - |
| 1620 | } | - |
| 1621 | stream << list; | - |
| 1622 | stream << childrenCollapsible(); | - |
| 1623 | stream << qint32(d->handleWidth); | - |
| 1624 | stream << opaqueResize(); | - |
| 1625 | stream << qint32(orientation()); | - |
| 1626 | stream << d->opaqueResizeSet; | - |
| 1627 | return data; | - |
| 1628 | } | - |
| 1629 | | - |
| 1630 | | - |
| 1631 | | - |
| 1632 | | - |
| 1633 | | - |
| 1634 | | - |
| 1635 | | - |
| 1636 | | - |
| 1637 | | - |
| 1638 | | - |
| 1639 | | - |
| 1640 | | - |
| 1641 | | - |
| 1642 | | - |
| 1643 | | - |
| 1644 | | - |
| 1645 | | - |
| 1646 | bool QSplitter::restoreState(const QByteArray &state) | - |
| 1647 | { | - |
| 1648 | Q_D(QSplitter); | - |
| 1649 | int version = 1; | - |
| 1650 | QByteArray sd = state; | - |
| 1651 | QDataStream stream(&sd, QIODevice::ReadOnly); | - |
| 1652 | QList<int> list; | - |
| 1653 | bool b; | - |
| 1654 | qint32 i; | - |
| 1655 | qint32 marker; | - |
| 1656 | qint32 v; | - |
| 1657 | | - |
| 1658 | stream >> marker; | - |
| 1659 | stream >> v; | - |
| 1660 | if (marker != SplitterMagic || v > version) | - |
| 1661 | return false; | - |
| 1662 | | - |
| 1663 | stream >> list; | - |
| 1664 | d->setSizes_helper(list, false); | - |
| 1665 | | - |
| 1666 | stream >> b; | - |
| 1667 | setChildrenCollapsible(b); | - |
| 1668 | | - |
| 1669 | stream >> i; | - |
| 1670 | setHandleWidth(i); | - |
| 1671 | | - |
| 1672 | stream >> b; | - |
| 1673 | setOpaqueResize(b); | - |
| 1674 | | - |
| 1675 | stream >> i; | - |
| 1676 | setOrientation(Qt::Orientation(i)); | - |
| 1677 | d->doResize(); | - |
| 1678 | | - |
| 1679 | if (v >= 1) | - |
| 1680 | stream >> d->opaqueResizeSet; | - |
| 1681 | | - |
| 1682 | return true; | - |
| 1683 | } | - |
| 1684 | | - |
| 1685 | | - |
| 1686 | | - |
| 1687 | | - |
| 1688 | | - |
| 1689 | | - |
| 1690 | | - |
| 1691 | | - |
| 1692 | | - |
| 1693 | | - |
| 1694 | | - |
| 1695 | | - |
| 1696 | | - |
| 1697 | | - |
| 1698 | | - |
| 1699 | void QSplitter::setStretchFactor(int index, int stretch) | - |
| 1700 | { | - |
| 1701 | Q_D(QSplitter); | - |
| 1702 | if (index <= -1 || index >= d->list.count()) | - |
| 1703 | return; | - |
| 1704 | | - |
| 1705 | QWidget *widget = d->list.at(index)->widget; | - |
| 1706 | QSizePolicy sp = widget->sizePolicy(); | - |
| 1707 | sp.setHorizontalStretch(stretch); | - |
| 1708 | sp.setVerticalStretch(stretch); | - |
| 1709 | widget->setSizePolicy(sp); | - |
| 1710 | } | - |
| 1711 | | - |
| 1712 | | - |
| 1713 | | - |
| 1714 | | - |
| 1715 | | - |
| 1716 | | - |
| 1717 | | - |
| 1718 | | - |
| 1719 | | - |
| 1720 | QTextStream& operator<<(QTextStream& ts, const QSplitter& splitter) | - |
| 1721 | { | - |
| 1722 | ts << splitter.saveState() << endl; | - |
| 1723 | return ts; | - |
| 1724 | } | - |
| 1725 | | - |
| 1726 | | - |
| 1727 | | - |
| 1728 | | - |
| 1729 | | - |
| 1730 | | - |
| 1731 | | - |
| 1732 | | - |
| 1733 | QTextStream& operator>>(QTextStream& ts, QSplitter& splitter) | - |
| 1734 | { | - |
| 1735 | QString line = ts.readLine(); | - |
| 1736 | line = line.simplified(); | - |
| 1737 | line.replace(QLatin1Char(' '), QString()); | - |
| 1738 | line = line.toUpper(); | - |
| 1739 | | - |
| 1740 | splitter.restoreState(line.toLatin1()); | - |
| 1741 | return ts; | - |
| 1742 | } | - |
| 1743 | | - |
| 1744 | QT_END_NAMESPACE | - |
| 1745 | | - |
| 1746 | #include "moc_qsplitter.cpp" | - |
| 1747 | | - |
| 1748 | #endif // QT_NO_SPLITTER | - |
| | |