コード例 #1
0
ファイル: UFlowLayout.cpp プロジェクト: gauldoth/UniCore
int UFlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
    int left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
    int x = effectiveRect.x();
    int y = effectiveRect.y();
    int lineHeight = 0;

    QLayoutItem *item;
    foreach (item, itemList) {
        QWidget *wid = item->widget();
        int spaceX = horizontalSpacing();
        if (spaceX == -1)
            spaceX = wid->style()->layoutSpacing(
            QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal);
        int spaceY = verticalSpacing();
        if (spaceY == -1)
            spaceY = wid->style()->layoutSpacing(
            QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical);
        int nextX = x + item->sizeHint().width() + spaceX;
        if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) {
            x = effectiveRect.x();
            y = y + lineHeight + spaceY;
            nextX = x + item->sizeHint().width() + spaceX;
            lineHeight = 0;
        }

        if (!testOnly)
            item->setGeometry(QRect(QPoint(x, y), item->sizeHint()));

        x = nextX;
        lineHeight = qMax(lineHeight, item->sizeHint().height());
    }
コード例 #2
0
ファイル: ElidingButton.cpp プロジェクト: darthcodus/Amarok
void ElidingButton::elideText( const QSize &widgetSize )
{
    const int width = widgetSize.width();
    const int iconWidth = icon().isNull() ? 0 : iconSize().width();

    int left, top, right, bottom;
    getContentsMargins( &left, &top, &right, &bottom );
    int padding = left + right + 4;
    int textWidth = width - ( iconWidth + padding );

    QFontMetrics fm( font() );
    QString elidedText = fm.elidedText( m_fullText, Qt::ElideRight, textWidth );
    QPushButton::setText( elidedText );

    bool elided = ( elidedText != m_fullText );

    // If there is no tooltip set, then we set it to be the full text when elided,
    // and clear it if the button is no longer elided.
    const QString tip = toolTip();
    if( elided && tip.isEmpty() )
        setToolTip( m_fullText );
    else if( !elided && tip == m_fullText )
        setToolTip( QString() );

    if( elided )
        setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
    else
        setSizePolicy( QSizePolicy::Maximum, QSizePolicy::Fixed );

    if( m_isElided != elided )
    {
        m_isElided = elided;
        emit( sizePolicyChanged() );
    }
}
コード例 #3
0
ファイル: flowlayout.cpp プロジェクト: Andrsid/myagent-im
int FlowLayout::doLayout ( const QRect &rect, bool testOnly ) const
{
	int left, top, right, bottom;
	getContentsMargins ( &left, &top, &right, &bottom );

	int x = rect.x() + left;
	int y = rect.y() + top;
	int lineHeight = 0;

	QLayoutItem *item;
	Q_FOREACH ( item, itemList )
	{
		int nextX = x + item->sizeHint().width() + spacing();
		if ( nextX - spacing() > (rect.right() - right) && lineHeight > 0 )
		{
			x = rect.x() + left;
			y = y + lineHeight + spacing();
			nextX = x + item->sizeHint().width() + spacing();
			//lineHeight = 0;
		}

		if ( !testOnly )
			item->setGeometry ( QRect ( QPoint ( x, y ), item->sizeHint() ) );

		x = nextX;
		lineHeight = qMax ( lineHeight, item->sizeHint().height() );
	}
コード例 #4
0
ファイル: panner.cpp プロジェクト: jschwartzenberg/kicker
void Panner::updateScrollButtons()
{
    int l, t, r, b;
    getContentsMargins( &l, &t, &r, &b );

    if ((orientation() == Qt::Horizontal && contentsRect().width() - 1 > width()) ||
            (orientation() == Qt::Vertical && contentsRect().height() - 1 > height()))
    {
        createScrollButtons();

        // since they buttons may be visible but of the wrong size
        // we need to do this every single time
        d->luSB->show();
        d->rdSB->show();

        if (orientation() == Qt::Horizontal)
        {
            setContentsMargins(l, t, d->luSB->width() + d->rdSB->width(), b);
        }
        else
        {
            setContentsMargins(l, t, r, d->luSB->height() + d->rdSB->height());
        }
    }
    else if (d->luSB && d->luSB->isVisibleTo(this))
    {
        d->luSB->hide();
        d->rdSB->hide();
        setContentsMargins(l, t, l, t);
    }
}
コード例 #5
0
qreal FlowLayout::doLayout(const QRectF &geom, bool applyNewGeometry) const
{
    qreal left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    const qreal maxw = geom.width() - left - right;

    qreal x = 0;
    qreal y = 0;
    qreal maxRowHeight = 0;
    QSizeF pref;
    for (int i = 0; i < m_items.count(); ++i) {
        QGraphicsLayoutItem *item = m_items.at(i);
        pref = item->effectiveSizeHint(Qt::PreferredSize);
        maxRowHeight = qMax(maxRowHeight, pref.height());

        qreal next_x;
        next_x = x + pref.width();
        if (next_x > maxw) {
            if (x == 0) {
                pref.setWidth(maxw);
            } else {
                x = 0;
                next_x = pref.width();
            }
            y += maxRowHeight + spacing(Qt::Vertical);
            maxRowHeight = 0;
        }

        if (applyNewGeometry)
            item->setGeometry(QRectF(QPointF(left + x, top + y), pref));
        x = next_x + spacing(Qt::Horizontal);
    }
    maxRowHeight = qMax(maxRowHeight, pref.height());
    return top + y + maxRowHeight + bottom;
}
コード例 #6
0
ファイル: lflowlayout.cpp プロジェクト: Sheridan/HAcc
int LFlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
    int left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
    int x = effectiveRect.x();
    int y = effectiveRect.y();
    int lineHeight = 0;
    QSize itemSizeHint;
    int nextX   = 0;
    int tHeight = 0;
    int tWidth  = 0;
    foreach (QLayoutItem *item, itemList)
    {
        itemSizeHint = item->sizeHint();
        nextX = x + itemSizeHint.width() + m_hSpace;
        if (nextX - m_hSpace > effectiveRect.right() && lineHeight > 0)
        {
            x = effectiveRect.x();
            y = y + lineHeight + m_vSpace;
            nextX = x + itemSizeHint.width() + m_hSpace;
            lineHeight = 0;
            tWidth = qMax(tWidth, x);
        }
        if (!testOnly)
        {
            item->setGeometry(QRect(QPoint(x, y), itemSizeHint));
        }
        x = nextX;
        lineHeight = qMax(lineHeight, itemSizeHint.height());
    }
コード例 #7
0
ファイル: qgraphicslinearlayout.cpp プロジェクト: Afreeca/qt
/*!
    \reimp
*/
void QGraphicsLinearLayout::setGeometry(const QRectF &rect)
{
    Q_D(QGraphicsLinearLayout);
    QGraphicsLayout::setGeometry(rect);
    QRectF effectiveRect = geometry();
    qreal left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    Qt::LayoutDirection visualDir = d->visualDirection();
    d->engine.setVisualDirection(visualDir);
    if (visualDir == Qt::RightToLeft)
        qSwap(left, right);
    effectiveRect.adjust(+left, +top, -right, -bottom);
#ifdef QT_DEBUG
    if (qt_graphicsLayoutDebug()) {
        static int counter = 0;
        qDebug() << counter++ << "QGraphicsLinearLayout::setGeometry - " << rect;
        dump(1);
    }
#endif
    d->engine.setGeometries(d->styleInfo(), effectiveRect);
#ifdef QT_DEBUG
    if (qt_graphicsLayoutDebug()) {
        qDebug() << "post dump";
        dump(1);
    }
#endif
}
コード例 #8
0
/*!
    \reimp
*/
QSizeF QGraphicsAnchorLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
    Q_UNUSED(constraint);
    Q_D(const QGraphicsAnchorLayout);

    // Some setup calculations are delayed until the information is
    // actually needed, avoiding unnecessary recalculations when
    // adding multiple anchors.

    // sizeHint() / effectiveSizeHint() already have a cache
    // mechanism, using invalidate() to force recalculation. However
    // sizeHint() is called three times after invalidation (for max,
    // min and pref), but we just need do our setup once.

    const_cast<QGraphicsAnchorLayoutPrivate *>(d)->calculateGraphs();

    // ### apply constraint!
    QSizeF engineSizeHint(
        d->sizeHints[QGraphicsAnchorLayoutPrivate::Horizontal][which],
        d->sizeHints[QGraphicsAnchorLayoutPrivate::Vertical][which]);

    qreal left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);

    return engineSizeHint + QSizeF(left + right, top + bottom);
}
コード例 #9
0
/*!
    \reimp
*/
QSizeF QGraphicsGridLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
    Q_D(const QGraphicsGridLayout);
    qreal left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    return d->engine.sizeHint(d->styleInfo(), which , constraint) + QSizeF(left + right, top + bottom);
}
コード例 #10
0
ファイル: qwt_thermo.cpp プロジェクト: 151706061/sofa
/*!
  \return Minimum size hint
  \warning The return value depends on the font and the scale.
  \sa sizeHint()
*/
QSize QwtThermo::minimumSizeHint() const
{
    int w = 0, h = 0;

    if ( d_data->scalePosition != NoScale )
    {
        const int sdExtent = qCeil( scaleDraw()->extent( font() ) );
        const int sdLength = scaleDraw()->minLength( font() );

        w = sdLength;
        h = d_data->pipeWidth + sdExtent + d_data->spacing;

    }
    else // no scale
    {
        w = 200;
        h = d_data->pipeWidth;
    }

    if ( d_data->orientation == Qt::Vertical )
        qSwap( w, h );

    w += 2 * d_data->borderWidth;
    h += 2 * d_data->borderWidth;

    // finally add the margins
    int left, right, top, bottom;
    getContentsMargins( &left, &top, &right, &bottom );
    w += left + right;
    h += top + bottom;

    return QSize( w, h );
}
コード例 #11
0
/*!
  \return a minimum size hint
*/
QSize QwtScaleWidget::minimumSizeHint() const
{
    const Qt::Orientation o = d_data->scaleDraw->orientation();

    // Border Distance cannot be less than the scale borderDistHint
    // Note, the borderDistHint is already included in minHeight/minWidth
    int length = 0;
    int mbd1, mbd2;
    getBorderDistHint( mbd1, mbd2 );
    length += qMax( 0, d_data->borderDist[0] - mbd1 );
    length += qMax( 0, d_data->borderDist[1] - mbd2 );
    length += d_data->scaleDraw->minLength( font() );

    int dim = dimForLength( length, font() );
    if ( length < dim )
    {
        // compensate for long titles
        length = dim;
        dim = dimForLength( length, font() );
    }

    QSize size( length + 2, dim );
    if ( o == Qt::Vertical )
        size.transpose();

    int left, right, top, bottom;
    getContentsMargins( &left, &top, &right, &bottom );
    return size + QSize( left + right, top + bottom );
}
コード例 #12
0
void
AnimatedBarWidget::paintEvent( QPaintEvent* event )
{
    Q_UNUSED(event);

    QPainter painter(this);

    const int buttonHeight = height();
    int buttonWidth = width();

    drawHoverBackground(&painter);

    int left, top, right, bottom;
    getContentsMargins ( &left, &top, &right, &bottom );
    const int padding = 2;
    const int iconWidth = iconSize().width();
    const int iconHeight = iconSize().height();
    const int iconTop = ( (buttonHeight - top - bottom) - iconHeight ) / 2;

    if( !m_animating )
    {
        const QRect iconRect( left + padding, iconTop, iconWidth, iconHeight );
        painter.drawPixmap( iconRect, icon().pixmap( iconSize() ) );
    }
    else
        m_animatedWidget->move( left + padding, iconTop );

    const QRect textRect( left + (padding * 3) + iconWidth, top,
                          buttonWidth - (left + padding * 3 + iconWidth) - padding, buttonHeight);
    QFontMetrics fm( font() );
    painter.drawText( textRect, Qt::AlignVCenter | Qt::TextWordWrap, text() );
}
コード例 #13
0
void SmartVerticalFlowLayout::doLayout(const QRect &rect)
{
    if (!m_isLayoutModified)
        return;

    int left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
    int x = effectiveRect.x();

    // update structure (ordering line by lines)
    m_structure.clear();
    QLayoutItem* item = 0;
    QList<QLayoutItem*> rowItems;

    Q_FOREACH(item, m_items) {
        QSize itemSize = item->sizeHint();

        // if the item is over the line limit OR limit reach per row
        if (x + itemSize.width() > effectiveRect.right()+1 ||
                (m_maxRowCount > 0 && rowItems.count() >= m_maxRowCount)) {
            // if the line isn't empty => we add to the structure
            // and reset the row
            if (!rowItems.isEmpty()) {
                m_structure.append(rowItems);
                x = effectiveRect.x();
            }
            rowItems.clear();
        }

        rowItems.append(item);
        x += itemSize.width() + horizontalSpacing();
    }
コード例 #14
0
/*!
    \reimp
*/
QSizeF QGraphicsLinearLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
{
    Q_D(const QGraphicsLinearLayout);
    qreal left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    const QSizeF extraMargins(left + right, top + bottom);
    return d->engine.sizeHint(which , constraint - extraMargins, d->styleInfo()) + extraMargins;
}
コード例 #15
0
void QAnimatedGridLayout::setGeometry(const QRect &rect)
{
    if (m_private->dirty || rect != geometry()) {
        int lm, tm, rm, bm;
        getContentsMargins(&lm, &tm, &rm, &bm);
        m_private->setGeometry(rect.adjusted(lm, tm, -rm, -bm));
        QLayout::setGeometry(rect);
    }
}
コード例 #16
0
ファイル: dynamiclayout.cpp プロジェクト: KDE/digikam
int DynamicLayout::reLayout(const QRect& rect, bool testOnly) const
{
    int left   = 0;
    int top    = 0;
    int right  = 0;
    int bottom = 0;
    getContentsMargins(&left, &top, &right, &bottom);

    QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
    int x               = effectiveRect.x();
    int y               = effectiveRect.y();
    int lineHeight      = 0;

    // --------------------------------------------------------

    int buttonWidth     = d->minItemWidth + d->spaceX;
    buttonWidth         = (buttonWidth == 0) ? 1 : buttonWidth;

    int maxButtonsInRow = (effectiveRect.width() - d->spaceX) / buttonWidth;

    if (maxButtonsInRow < d->minColumns)
    {
        maxButtonsInRow = d->minColumns;
    }

    maxButtonsInRow     = (maxButtonsInRow == 0) ? d->minColumns : maxButtonsInRow;
    int maxButtonWidth  = d->minItemWidth + ((effectiveRect.width() - (maxButtonsInRow * buttonWidth)) / maxButtonsInRow);

    int currentBtnWidth = (maxButtonsInRow >= d->itemList.count()) ? buttonWidth : maxButtonWidth;

    // --------------------------------------------------------

    foreach(QLayoutItem* const item, d->itemList)
    {
        int nextX = x + currentBtnWidth + d->spaceX;

        if ((nextX - d->spaceX) > effectiveRect.right() && (lineHeight > 0))
        {
            x          = effectiveRect.x();
            y          = y + lineHeight + d->spaceY;
            nextX      = x + currentBtnWidth  + d->spaceX;
            lineHeight = 0;
        }

        if (!testOnly)
        {
            QSize s = item->sizeHint();
            s.setWidth(currentBtnWidth);
            item->setGeometry(QRect(QPoint(x, y), s));
        }

        x          = nextX;
        lineHeight = qMax(lineHeight, item->sizeHint().height());
    }

    return y + lineHeight - rect.y() + bottom;
}
コード例 #17
0
ファイル: tooltip.cpp プロジェクト: bookdraft/QPeerCastYP
QSize ToolTip::sizeHint(const QPoint &pos, QWidget *widget)
{
    QPoint p = widget ? widget->mapFromGlobal(pos) : pos;
    int l, t, r, b;
    getContentsMargins(&l, &t, &r, &b);
    QRect screen = widget ? widget->rect() : QApplication::desktop()->screenGeometry();
    QRect rect(0, 0, screen.width() - p.x(), screen.height() - p.y());
    rect = fontMetrics().boundingRect(rect, Qt::TextWordWrap, text());
    return QSize(rect.width() + l + r, rect.height() + t + b);
}
コード例 #18
0
QSize SmallPokeTextEdit::sizeHint() const
{
    /* padding */
    int top, bottom;
    getContentsMargins(0, &top, 0, &bottom);

    QSize s = document()->size().toSize();
    s.setHeight(s.height() + top + bottom);
    return s;
}
コード例 #19
0
ファイル: phonelauncherview.cpp プロジェクト: Camelek/qtmoko
/*!
  \internal
  \fn void PhoneLauncherView::itemDimensions(int *itemWidth,int *itemHeight) const
  Retrieves the appropriate width and height for each GridItem object, according to the
  current dimensions of the view.
*/
void PhoneLauncherView::itemDimensions(int *itemWidth,int *itemHeight) const
{
    // Get the pixel size of the view's margins.
    int left,top,right,bottom;
    getContentsMargins(&left,&top,&right,&bottom);

    int viewWidth = size().width() - left - right - 1;
    int viewHeight = size().height() - top - bottom - 1;
    if (itemWidth)  *itemWidth  = viewWidth/m_columns;
    if (itemHeight) *itemHeight = viewHeight/m_rows;
}
コード例 #20
0
ファイル: flowlayout.cpp プロジェクト: Andrsid/myagent-im
QSize FlowLayout::minimumSize() const
{
	QSize size;
	QLayoutItem *item;
	Q_FOREACH ( item, itemList )
	size = size.expandedTo ( item->minimumSize() );

	int left, top, right, bottom;
	getContentsMargins ( &left, &top, &right, &bottom );
	size += QSize ( left + right, top + bottom );
	return size;
}
コード例 #21
0
int ElidedCheckBox::currentWidth() const
{
    int width = 0;
    if (isVisible()) {
        width = contentsRect().width() - (2 * iconSize().width());
    } else {
        int l, t, r, b;
        getContentsMargins(&l, &t, &r, &b);
        width = sizeHint().width() - l - r - (2 * iconSize().width());
    }
    return width;
}
コード例 #22
0
void 
GridImageLayout::setGeometry(
        const QRectF &r)
{
    qreal left, top, right, bottom;

    QGraphicsLayout::setGeometry(r);

    getContentsMargins (&left, &top, &right, &bottom);

    if (m_Image)
        m_Image->setGeometry (r);

    if (m_ProgressBar) {
        QSizeF progressSize;
        QRectF progressGeometry;
        
        if (progressType == MProgressIndicator::barType) {
            progressSize = m_ProgressBar->preferredSize ();
            progressGeometry = QRectF (
                    left, 
                    r.y() + r.height () - progressSize.height () - bottom, 
                    r.width () - left - right, 
                    progressSize.height ());
        } else {
            qreal HRem, VRem;
            progressSize = m_ProgressBar->minimumSize ();
            qreal progrWidth = progressSize.width();
            qreal progrHeight = progressSize.height();

            HRem = (r.width() - left - right - progrWidth) / 2;
            VRem = (r.height() - top - bottom - progrHeight) / 2;

            progressGeometry = QRectF (
                    left + HRem, 
                    top + VRem, 
                    progrWidth, 
                    progrHeight);
        }

        SYS_DEBUG ("*** progressSize = %gx%g", 
                progressSize.width(), 
                progressSize.height());

        SYS_DEBUG ("*** progressGeometry = %g, %g (%gx%g)", 
                progressGeometry.x(), 
                progressGeometry.y(), 
                progressGeometry.width(), 
                progressGeometry.height());
        m_ProgressBar->setGeometry (progressGeometry);
     }
}
コード例 #23
0
NewsLabel::NewsLabel(const QString &htmlTitle,
                   const QString &htmlText,
                   QWidget *parent) :
    QLabel(parent),
    m_title(htmlTitle),
    m_text(htmlText),
    m_minWidth(100),
    m_lastWidth(-1)
{
    int dummy, left, right;
    getContentsMargins(&left, &dummy, &right, &dummy);
    m_contentsMargin = left + right;
}
コード例 #24
0
ファイル: flowlayout.cpp プロジェクト: roandbox/profimax
int FlowLayout::doLayout(const QRect &rect, bool testOnly) const
{
	int left, top, right, bottom;
	getContentsMargins(&left, &top, &right, &bottom);

	QLayoutItem *item;
	int lsize = 0;
	foreach (item, itemList) {
		QWidget *wid = item->widget();
		if ((rect.width()-left-right)<lsize+wid->geometry().width())
			break;
		lsize=lsize+wid->geometry().width();
	}
コード例 #25
0
ファイル: qwt_slider.cpp プロジェクト: Aconex/pcp
/*!
  \brief Return a minimum size hint
  \warning The return value of QwtSlider::minimumSizeHint() depends on
           the font and the scale.
*/
QSize QwtSlider::minimumSizeHint() const
{
    if ( !d_data->sizeHintCache.isEmpty() )
        return d_data->sizeHintCache;

    const int minLength = 84; // from QSlider

    int handleLength = d_data->handleSize.width();
    int handleThickness = d_data->handleSize.height();

    if ( orientation() == Qt::Vertical )
        qSwap( handleLength, handleThickness );

    int w = minLength; 
    int h = handleThickness;

    if ( d_data->scalePos != QwtSlider::NoScale )
    {
        int d1, d2;
        scaleDraw()->getBorderDistHint( font(), d1, d2 );

        const int sdBorderDist = 2 * qMax( d1, d2 );
        const int sdExtent = qCeil( scaleDraw()->extent( font() ) );
        const int sdLength = scaleDraw()->minLength( font() );

        int l = sdLength;
        if ( handleLength > sdBorderDist )
        {
            // We need additional space for the overlapping handle
            l += handleLength - sdBorderDist;
        }

        w = qMax( l, w );
        h += sdExtent + d_data->spacing;
    }

    if ( d_data->bgStyle & QwtSlider::Trough )
        h += 2 * d_data->borderWidth;

    if ( orientation() == Qt::Vertical )
        qSwap( w, h );

    int left, right, top, bottom;
    getContentsMargins( &left, &top, &right, &bottom );

    w += left + right;
    h += top + bottom;

    d_data->sizeHintCache = QSize( w, h );
    return d_data->sizeHintCache;
}
コード例 #26
0
ファイル: qwt_legend.cpp プロジェクト: 151706061/sofa
/*!
  Render the legend into a given rectangle.

  \param painter Painter
  \param rect Bounding rectangle
  \param fillBackground When true, fill rect with the widget background 

  \sa renderLegend() is used by QwtPlotRenderer - not by QwtLegend itself
*/
void QwtLegend::renderLegend( QPainter *painter, 
    const QRectF &rect, bool fillBackground ) const
{
    if ( d_data->itemMap.isEmpty() )
        return;

    if ( fillBackground )
    {
        if ( autoFillBackground() ||
            testAttribute( Qt::WA_StyledBackground ) )
        {
            QwtPainter::drawBackgound( painter, rect, this );
        }
    }

    const QwtDynGridLayout *legendLayout = 
        qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
    if ( legendLayout == NULL )
        return;

    int left, right, top, bottom;
    getContentsMargins( &left, &top, &right, &bottom );

    QRect layoutRect; 
    layoutRect.setLeft( qCeil( rect.left() ) + left );
    layoutRect.setTop( qCeil( rect.top() ) + top );
    layoutRect.setRight( qFloor( rect.right() ) - right );
    layoutRect.setBottom( qFloor( rect.bottom() ) - bottom );

    uint numCols = legendLayout->columnsForWidth( layoutRect.width() );
    QList<QRect> itemRects =
        legendLayout->layoutItems( layoutRect, numCols );

    int index = 0;

    for ( int i = 0; i < legendLayout->count(); i++ )
    {
        QLayoutItem *item = legendLayout->itemAt( i );
        QWidget *w = item->widget();
        if ( w )
        {
            painter->save();

            painter->setClipRect( itemRects[index], Qt::IntersectClip );
            renderItem( painter, w, itemRects[index], fillBackground );

            index++;
            painter->restore();
        }
    }
}
コード例 #27
0
// void getContentsMargins(qreal * left, qreal * top, qreal * right, qreal * bottom)
int QGraphicsLayoutItem_getContentsMargins(lua_State* const state)
{
    auto self = lua::get<QGraphicsLayoutItem*>(state, 1);
    if (lua_gettop(state) > 1) {
        self->getContentsMargins(
            lua::get<qreal*>(state, 2),
            lua::get<qreal*>(state, 3),
            lua::get<qreal*>(state, 4),
            lua::get<qreal*>(state, 5)
        );
        return 0;
    }

    qreal left, top, right, bottom;
    self->getContentsMargins(&left, &top, &right, &bottom);
    lua::push(state,
        left,
        top,
        right,
        bottom
    );
    return 4;
}
コード例 #28
0
ファイル: flowlayout.cpp プロジェクト: Antidote1911/Kryvos
QSize FlowLayout::minimumSize() const
{
    QSize size;
    QLayoutItem *item;
    foreach (item, itemList)
        size = size.expandedTo(item->minimumSize());

    int left, top, right, bottom;
    getContentsMargins(&left, &top, &right, &bottom);
    const int margin = left;

    size += QSize(2*margin, 2*margin);
    return size;
}
コード例 #29
0
void MToolBarLayoutPolicy::updateContentsMargins()
{
    qreal offset = effectiveCenterOffset();

    if (offset != 0.0f) {
        qreal margin = qAbs(offset*2);
        setContentsMargins(offset < 0.0f ? margin : -1, -1,
                           offset > 0.0f ? margin : -1, -1);
    } else {
        qreal left(-1), right(-1);
        getContentsMargins(&left, 0, &right, 0);
        if (left != -1 || right != -1)
            setContentsMargins(-1, -1, -1, -1);
    }
}
コード例 #30
0
ファイル: qitemeditorfactory.cpp プロジェクト: husninazer/qt
void QExpandingLineEdit::updateMinimumWidth()
{
    int left, right;
    getTextMargins(&left, 0, &right, 0);
    int width = left + right + 4 /*horizontalMargin in qlineedit.cpp*/;
    getContentsMargins(&left, 0, &right, 0);
    width += left + right;

    QStyleOptionFrameV2 opt;
    initStyleOption(&opt);

    int minWidth = style()->sizeFromContents(QStyle::CT_LineEdit, &opt, QSize(width, 0).
                   expandedTo(QApplication::globalStrut()), this).width();
    setMinimumWidth(minWidth);
}