⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qboxlayout.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*!    Constructs a new QBoxLayout called \a name, with direction \a dir.    If \a spacing is -1, the layout will inherit its parent's    spacing(); otherwise \a spacing is used.    You must insert this box into another layout.*/QBoxLayout::QBoxLayout(Direction dir, int spacing, const char *name)    : QLayout(*new QBoxLayoutPrivate,0, 0){    Q_D(QBoxLayout);    d->dir = dir;    setObjectName(QString::fromAscii(name));    setSpacing(spacing);}#endif // QT3_SUPPORT/*!    Destroys this box layout.    The layout's widgets aren't destroyed.*/QBoxLayout::~QBoxLayout(){    Q_D(QBoxLayout);    d->deleteAll(); // must do it before QObject deletes children, so can't be in ~QBoxLayoutPrivate}/*!    \reimp*/QSize QBoxLayout::sizeHint() const{    Q_D(const QBoxLayout);    if (d->dirty)        const_cast<QBoxLayout*>(this)->d_func()->setupGeom();    int m = margin();    return d->sizeHint + QSize(2 * m, 2 * m);}/*!    \reimp*/QSize QBoxLayout::minimumSize() const{    Q_D(const QBoxLayout);    if (d->dirty)        const_cast<QBoxLayout*>(this)->d_func()->setupGeom();    int m = margin();    return d->minSize + QSize(2 * m, 2 * m);}/*!    \reimp*/QSize QBoxLayout::maximumSize() const{    Q_D(const QBoxLayout);    if (d->dirty)        const_cast<QBoxLayout*>(this)->d_func()->setupGeom();    int m = margin();    QSize s = (d->maxSize + QSize(2 * m, 2 * m))              .boundedTo(QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX));    if (alignment() & Qt::AlignHorizontal_Mask)        s.setWidth(QLAYOUTSIZE_MAX);    if (alignment() & Qt::AlignVertical_Mask)        s.setHeight(QLAYOUTSIZE_MAX);    return s;}/*!    \reimp*/bool QBoxLayout::hasHeightForWidth() const{    Q_D(const QBoxLayout);    if (d->dirty)        const_cast<QBoxLayout*>(this)->d_func()->setupGeom();    return d->hasHfw;}/*!    \reimp*/int QBoxLayout::heightForWidth(int w) const{    Q_D(const QBoxLayout);    if (!hasHeightForWidth())        return -1;    int m = margin();    w -= 2 * m;    if (w != d->hfwWidth)        const_cast<QBoxLayout*>(this)->d_func()->calcHfw(w);    return d->hfwHeight + 2 * m;}/*!    \reimp*/int QBoxLayout::minimumHeightForWidth(int w) const{    Q_D(const QBoxLayout);    (void) heightForWidth(w);    return d->hasHfw ? (d->hfwMinHeight + 2 * margin()) : -1;}/*!    Resets cached information.*/void QBoxLayout::invalidate(){    Q_D(QBoxLayout);    d->setDirty();    QLayout::invalidate();}/*!    \reimp*/int QBoxLayout::count() const{    Q_D(const QBoxLayout);    return d->list.count();}/*!    \reimp*/QLayoutItem *QBoxLayout::itemAt(int index) const{    Q_D(const QBoxLayout);    return index >= 0 && index < d->list.count() ? d->list.at(index)->item : 0;}/*!    \reimp*/QLayoutItem *QBoxLayout::takeAt(int index){    Q_D(QBoxLayout);    if (index < 0 || index >= d->list.count())        return 0;    QBoxLayoutItem *b = d->list.takeAt(index);    QLayoutItem *item = b->item;    b->item = 0;    delete b;    invalidate();    return item;}/*!    \reimp*/Qt::Orientations QBoxLayout::expandingDirections() const{    Q_D(const QBoxLayout);    if (d->dirty)        const_cast<QBoxLayout*>(this)->d_func()->setupGeom();    return d->expanding;}/*!    \reimp*/void QBoxLayout::setGeometry(const QRect &r){    Q_D(QBoxLayout);    if (d->dirty || r != geometry()) {        QRect rect = geometry();        QLayout::setGeometry(r);        if (d->dirty)            d->setupGeom();        QRect cr = alignment() ? alignmentRect(r) : r;        int m = margin();        QRect s(cr.x() + m, cr.y() + m,                 cr.width() - 2 * m, cr.height() - 2 * m);        QVector<QLayoutStruct> a = d->geomArray;        int pos = horz(d->dir) ? s.x() : s.y();        int space = horz(d->dir) ? s.width() : s.height();        int n = a.count();        if (d->hasHfw && !horz(d->dir)) {            for (int i = 0; i < n; i++) {                QBoxLayoutItem *box = d->list.at(i);                if (box->item->hasHeightForWidth())                    a[i].sizeHint = a[i].minimumSize =                                    box->item->heightForWidth(s.width());            }        }        Direction visualDir = d->dir;        QWidget *parent = parentWidget();        if (parent && parent->isRightToLeft()) {            if (d->dir == LeftToRight)                visualDir = RightToLeft;            else if (d->dir == RightToLeft)                visualDir = LeftToRight;        }        qGeomCalc(a, 0, n, pos, space, spacing());        bool reverse = (horz(visualDir)                        ? ((r.right() > rect.right()) != (visualDir == RightToLeft))                        : r.bottom() > rect.bottom());        for (int j = 0; j < n; j++) {            int i = reverse ? n-j-1 : j;            QBoxLayoutItem *box = d->list.at(i);            switch (visualDir) {            case LeftToRight:                box->item->setGeometry(QRect(a[i].pos, s.y(),                                              a[i].size, s.height()));                break;            case RightToLeft:                box->item->setGeometry(QRect(s.left() + s.right()                                              - a[i].pos - a[i].size + 1, s.y(),                                              a[i].size, s.height()));                break;            case TopToBottom:                box->item->setGeometry(QRect(s.x(), a[i].pos,                                              s.width(), a[i].size));                break;            case BottomToTop:                box->item->setGeometry(QRect(s.x(), s.top() + s.bottom()                                              - a[i].pos - a[i].size + 1,                                              s.width(), a[i].size));            }        }    }}/*!    \reimp*/void QBoxLayout::addItem(QLayoutItem *item){    Q_D(QBoxLayout);    QBoxLayoutItem *it = new QBoxLayoutItem(item);    d->list.append(it);    invalidate();}/*!    Inserts \a item into this box layout at position \a index. If \a    index is negative, the item is added at the end.    \warning Do not call QLayout::insertChildLayout() if \a item is    a QLayout.    \sa addItem(), insertWidget(), insertLayout(), insertStretch(),        insertSpacing()*/void QBoxLayout::insertItem(int index, QLayoutItem *item){    Q_D(QBoxLayout);    if (index < 0)                                // append        index = d->list.count();    QBoxLayoutItem *it = new QBoxLayoutItem(item);    d->list.insert(index, it);    invalidate();}/*!    Inserts a non-stretchable space at position \a index, with size \a    size. If \a index is negative the space is added at the end.    The box layout has default margin and spacing. This function adds    additional space.    \sa addSpacing(), insertItem()*/void QBoxLayout::insertSpacing(int index, int size){    Q_D(QBoxLayout);    if (index < 0)                                // append        index = d->list.count();    QLayoutItem *b;    if (horz(d->dir))        b = new QSpacerItem(size, 0, QSizePolicy::Fixed,                             QSizePolicy::Minimum);    else        b = new QSpacerItem(0, size, QSizePolicy::Minimum,                             QSizePolicy::Fixed);    QBoxLayoutItem *it = new QBoxLayoutItem(b);    it->magic = true;    d->list.insert(index, it);    invalidate();}/*!    Inserts a stretchable space at position \a index, with zero    minimum size and stretch factor \a stretch. If \a index is    negative the space is added at the end.    \sa addStretch(), insertItem()*/void QBoxLayout::insertStretch(int index, int stretch){    Q_D(QBoxLayout);    if (index < 0)                                // append        index = d->list.count();    QLayoutItem *b;    if (horz(d->dir))        b = new QSpacerItem(0, 0, QSizePolicy::Expanding,                             QSizePolicy::Minimum);    else        b = new QSpacerItem(0, 0, QSizePolicy::Minimum,                             QSizePolicy::Expanding);    QBoxLayoutItem *it = new QBoxLayoutItem(b, stretch);    it->magic = true;    d->list.insert(index, it);    invalidate();}/*!    Inserts \a layout at position \a index, with stretch factor \a    stretch. If \a index is negative, the layout is added at the end.    \a layout becomes a child of the box layout.    \sa addLayout(), insertItem()*/void QBoxLayout::insertLayout(int index, QLayout *layout, int stretch){    Q_D(QBoxLayout);    addChildLayout(layout);    if (index < 0)                                // append        index = d->list.count();    QBoxLayoutItem *it = new QBoxLayoutItem(layout, stretch);    d->list.insert(index, it);    invalidate();}/*!    Inserts \a widget at position \a index, with stretch factor \a    stretch and alignment \a alignment. If \a index is negative, the    widget is added at the end.    The stretch factor applies only in the \l{direction()}{direction}    of the QBoxLayout, and is relative to the other boxes and widgets    in this QBoxLayout. Widgets and boxes with higher stretch factors    grow more.    If the stretch factor is 0 and nothing else in the QBoxLayout has    a stretch factor greater than zero, the space is distributed    according to the QWidget:sizePolicy() of each widget that's    involved.    The alignment is specified by \a alignment. The default alignment    is 0, which means that the widget fills the entire cell.    \sa addWidget(), insertItem()*/void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch,                              Qt::Alignment alignment){    Q_D(QBoxLayout);    if (!checkWidget(this, widget))         return;    addChildWidget(widget);    if (index < 0)                                // append        index = d->list.count();    QWidgetItem *b = new QWidgetItem(widget);    b->setAlignment(alignment);    QBoxLayoutItem *it = new QBoxLayoutItem(b, stretch);    d->list.insert(index, it);    invalidate();}/*!    Adds a non-stretchable space with size \a size to the end of this    box layout. QBoxLayout provides default margin and spacing. This    function adds additional space.    \sa insertSpacing(), addItem()*/void QBoxLayout::addSpacing(int size){    insertSpacing(-1, size);}/*!    Adds a stretchable space with zero minimum size and stretch factor    \a stretch to the end of this box layout.    \sa insertStretch(), addItem()*/void QBoxLayout::addStretch(int stretch){    insertStretch(-1, stretch);}/*!    Adds \a widget to the end of this box layout, with a stretch    factor of \a stretch and alignment \a alignment.    The stretch factor applies only in the \l{direction()}{direction}    of the QBoxLayout, and is relative to the other boxes and widgets    in this QBoxLayout. Widgets and boxes with higher stretch factors    grow more.    If the stretch factor is 0 and nothing else in the QBoxLayout has    a stretch factor greater than zero, the space is distributed    according to the QWidget:sizePolicy() of each widget that's    involved.    The alignment is specified by \a alignment. The default

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -