QSplitterLayoutStruct *QSplitter::addWidget( QWidget *w, bool first ) { QSplitterLayoutStruct *s; QSplitterHandle *newHandle = 0; if ( data->list.count() > 0 ) { s = new QSplitterLayoutStruct; s->mode = KeepSize; newHandle = new QSplitterHandle( orientation(), this ); s->wid = newHandle; newHandle->setId(data->list.count()); s->isSplitter = TRUE; s->sizer = pick( newHandle->sizeHint() ); if ( first ) data->list.insert( 0, s ); else data->list.append( s ); } s = new QSplitterLayoutStruct; s->mode = Stretch; s->wid = w; if ( !testWState( WState_Resized ) && w->sizeHint().isValid() ) s->sizer = pick( w->sizeHint() ); else s->sizer = pick( w->size() ); s->isSplitter = FALSE; if ( first ) data->list.insert( 0, s ); else data->list.append( s ); if ( newHandle && isVisible() ) newHandle->show(); //will trigger sending of post events return s; }
void QSplitterPrivate::setGeo(QSplitterLayoutStruct *sls, int p, int s, bool allowCollapse) { Q_Q(QSplitter); QWidget *w = sls->widget; QRect r; QRect contents = q->contentsRect(); if (orient == Qt::Horizontal) { r.setRect(p, contents.y(), s, contents.height()); } else { r.setRect(contents.x(), p, contents.width(), s); } sls->rect = r; int minSize = pick(qSmartMinSize(w)); if (orient == Qt::Horizontal && q->isRightToLeft()) r.moveRight(contents.width() - r.left()); if (allowCollapse) sls->collapsed = s <= 0 && minSize > 0 && !w->isHidden(); // Hide the child widget, but without calling hide() so that // the splitter handle is still shown. if (sls->collapsed) r.moveTopLeft(QPoint(-r.width()-1, -r.height()-1)); w->setGeometry(r); if (!sls->handle->isHidden()) { QSplitterHandle *h = sls->handle; QSize hs = h->sizeHint(); int left, top, right, bottom; h->getContentsMargins(&left, &top, &right, &bottom); if (orient==Qt::Horizontal) { if (q->isRightToLeft()) p = contents.width() - p + hs.width(); h->setGeometry(p-hs.width() - left, contents.y(), hs.width() + left + right, contents.height()); } else { h->setGeometry(contents.x(), p-hs.height() - top, contents.width(), hs.height() + top + bottom); } } }