Ejemplo n.º 1
0
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() );
	}
Ejemplo n.º 2
0
int FlowLayout::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());
    }
Ejemplo n.º 3
0
int MonitorLayout::doLayout(const QRect& rect, bool testOnly) const
{
    int x = rect.x();
    int y = rect.y();
    int lineHeight = 0;
    QLayoutItem* item;

    foreach (item, m_items)
    {
        int nextX = x + item->sizeHint().width() + spacing();
        if (nextX - spacing() > rect.right() && lineHeight > 0)
        {
            x = rect.x();
            y = y + lineHeight + spacing();
            nextX = x + item->sizeHint().width() + spacing();
            lineHeight = 0;
        }

        if (testOnly == false)
        {
            item->setGeometry(QRect(QPoint(x, y),
                                    item->sizeHint()));
        }

        x = nextX;
        lineHeight = qMax(lineHeight, item->sizeHint().height());
    }
Ejemplo n.º 4
0
QSize QLayoutItemProto::sizeHint() const
{
  QLayoutItem *item = qscriptvalue_cast<QLayoutItem*>(thisObject());
  if (item)
    return item->sizeHint();
  return QSize();
}
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();
    }
Ejemplo n.º 6
0
QSize StatusBarLayout::sizeHint() const
{
    QSize s(0, 0);
    for (int i = 0; i < m_items.size(); ++i) {
        QLayoutItem* item = m_items.at(i);
        s = s.expandedTo(item->sizeHint());
    }
    return s;
}
Ejemplo n.º 7
0
void FlagLayout::setGeometry(const QRect &rect)
{
    int topHeight = 0;
    int bottomHeight = 0;

    QLayout::setGeometry(rect);

    // left side
    for (int i = 0; i < list.size(); ++i) {
        ItemWrapper *wrapper = list.at(i);
        QLayoutItem *item = wrapper->item;
        Position position = wrapper->position;

        if (position == TopLeft) {
            topHeight += spacing();
            item->setGeometry(QRect(rect.x() + spacing(), topHeight, 
                                    item->sizeHint().width(), item->sizeHint().height()));

            topHeight += item->geometry().height();
        } else if (position == BottomLeft) {
            bottomHeight += item->geometry().height() + spacing();
            item->setGeometry(QRect(rect.x() + spacing(), rect.height() - bottomHeight, 
                                    item->sizeHint().width(), item->sizeHint().height()));
        }
    }

    // right side
    topHeight = 0;
    bottomHeight = 0;
    for (int i = 0; i < list.size(); ++i) {
        ItemWrapper *wrapper = list.at(i);
        QLayoutItem *item = wrapper->item;
        Position position = wrapper->position;

        int rightpos = item->sizeHint().width() + spacing();
        if (position == TopRight) {
            topHeight += spacing();
            item->setGeometry(QRect(rect.x() + rect.width() - rightpos, topHeight, 
                                    item->sizeHint().width(), item->sizeHint().height()));

            topHeight += item->geometry().height();
        } else if (position == BottomRight) {
            bottomHeight += item->geometry().height() + spacing();
            item->setGeometry(QRect(rect.x() + rect.width() - rightpos, rect.height() - bottomHeight, 
                                    item->sizeHint().width(), item->sizeHint().height()));
        }
    }
}
Ejemplo n.º 8
0
void FreeLayout::setGeometry(const QRect &r)
{
	QList<QLayoutItem *>::const_iterator it, iEnd = m_items.end();
	for (it = m_items.begin(); it != iEnd; ++it) {
		QLayoutItem *item = *it;

		const QRect &geom = item->geometry();
		const QSize &sizeHint = item->sizeHint();

		if (geom.size() != sizeHint)
			item->setGeometry(QRect(geom.topLeft(), sizeHint));
	}
}
Ejemplo n.º 9
0
QSize FlowLayout::sizeHint() const
{
	QSize s(0,0);
	QPtrListIterator<QLayoutItem> it(_list);
	QLayoutItem *o;

	while ( (o=it.current()) != 0 )
	{
		++it;
		s = s.expandedTo( o->sizeHint() );
	}

	return s;
}
Ejemplo n.º 10
0
int SimpleFlow::doLayout( const QRect &r, bool testonly )
{
    int x = r.x();
    int y = r.y();
    int h = 0;		//height of this line so far.
    QPtrListIterator<QLayoutItem> it(list);
    QLayoutItem *o;
    while ( (o=it.current()) != 0 ) {
	++it;
	int nextX = x + o->sizeHint().width() + spacing();
	if ( nextX - spacing() > r.right() && h > 0 ) {
	    x = r.x();
	    y = y + h + spacing();
	    nextX = x + o->sizeHint().width() + spacing();
	    h = 0;
	}
	if ( !testonly )
	    o->setGeometry( QRect( QPoint( x, y ), o->sizeHint() ) );
	x = nextX;
	h = QMAX( h,  o->sizeHint().height() );
    }
    return y + h - r.y();
}
Ejemplo n.º 11
0
//! [7]
QSize CardLayout::sizeHint() const
{
    QSize s(0,0);
    int n = list.count();
    if (n > 0)
        s = QSize(100,70); //start with a nice default size
    int i = 0;
    while (i < n) {
        QLayoutItem *o = list.at(i);
        s = s.expandedTo(o->sizeHint());
        ++i;
    }
    return s + n*QSize(spacing(), spacing());
}
Ejemplo n.º 12
0
int FlowLayout::doLayoutHorizontal( const QRect &r, bool testonly )
{
	int x = r.x();
	int y = r.y();
	int w = 0;
	QPtrListIterator<QLayoutItem> it(_list);
	QLayoutItem *o;

	while ( (o=it.current()) != 0 )
	{
		++it;
		int nextY = y + o->sizeHint().height() + spacing();

		if ( nextY - spacing() > r.bottom() && w > 0 )
		{
			y = r.y();
			x = x + w + spacing();
			nextY = y + o->sizeHint().height() + spacing();
			w = 0;
		}

		if ( !testonly )
		{
			QRect oR(QPoint( x, y ), o->sizeHint());

			if (oR.bottom() > r.bottom() )
				oR.setBottom(r.bottom());

			o->setGeometry( oR );
		}

		y = nextY;
		w = QMAX( w,  o->sizeHint().width() );
	}

	return x + w - r.x();
}
Ejemplo n.º 13
0
int FlowLayout::doLayoutVertical( const QRect &r, bool testonly )
{
	int x = r.x();
	int y = r.y();
	int h = 0;
	QPtrListIterator<QLayoutItem> it(_list);
	QLayoutItem *o;

	while ( (o=it.current()) != 0 )
	{
		++it;
		int nextX = x + o->sizeHint().width() + spacing();
		if ( nextX - spacing() > r.right() && h > 0 )
		{
			x = r.x();
			y = y + h + spacing();
			nextX = x + o->sizeHint().width() + spacing();
			h = 0;
		}

		if ( !testonly )
		{
			QRect oR(QPoint( x, y ), o->sizeHint());

			if (oR.right() > r.right() )
				oR.setRight(r.right());

			o->setGeometry( oR );
		}

		x = nextX;
		h = QMAX( h,  o->sizeHint().height() );
	}

	return y + h - r.y();
}
Ejemplo n.º 14
0
QSize DummyLayout::sizeHint() const
{
	QRect geom, result;

	QList<QLayoutItem *>::const_iterator it, iEnd = m_items.end();
	for (it = m_items.begin(); it != iEnd; ++it) {
		QLayoutItem *item = *it;

		geom = item->geometry();
		geom.setSize(item->sizeHint());

		result |= geom;
	}

	return result.size();
}
Ejemplo n.º 15
0
void OverlayLayout::setGeometry(const QRect &rect)
{
    QLayout::setGeometry(rect);

    if (list.size() == 0)
        return;

    int i = 0;
    while (i < list.size())
    {
        QLayoutItem *o = list.at(i);
        if (i == 0)
        {
            o->setGeometry(rect);
        }
        else
        {
            auto size = o->sizeHint();
            QRect geom(rect.x() + rect.width() - size.width(), rect.y(), size.width(), size.height());
            o->setGeometry(geom);
        }
        ++i;
    }
}
Ejemplo n.º 16
0
int FlowLayout::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;

    auto spacingX = [this]( QLayoutItem *item ) {
        int spaceX = horizontalSpacing();
        if( spaceX == -1 ) {
            QWidget *widget = item->widget();
            if( widget ) {
                return widget->style()->layoutSpacing(
                           QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Horizontal
                       );
            }
            return 0;
        }
        return spaceX;
    };
    auto spacingY = [this]( QLayoutItem *item ) {
        int spaceY = verticalSpacing();
        if( spaceY == -1 ) {
            QWidget *widget = item->widget();
            if( widget ) {
                return widget->style()->layoutSpacing(
                           QSizePolicy::PushButton, QSizePolicy::PushButton, Qt::Vertical
                       );
            }
            return 0;
        }
        return spaceY;
    };

    for( auto iter = itemList.begin(), endLine = iter; iter != itemList.end(); ) {
        if( iter == endLine ) {
            x = effectiveRect.x();

            int lineWidth = 0;
            for( ; endLine != itemList.end(); ++endLine ) {
                QLayoutItem *item = *endLine;
                int itemWidth = spacingX( item ) + item->sizeHint().width();
                if( itemWidth+lineWidth > effectiveRect.width() && lineWidth > 0 ) {
                    break;
                }
                lineWidth += itemWidth;
            }

            x += qMax( (effectiveRect.width()-lineWidth) / 2, 0 );
            y += lineHeight;
            lineHeight = 0;
        }


        for( ; iter != endLine; ++iter ) {
            QLayoutItem *item = *iter;
            int spaceX = spacingX( item );
            int spaceY = spacingY( item );

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

            x += spaceX + item->sizeHint().width();
            lineHeight = qMax( lineHeight, item->sizeHint().height()+spaceY );

        }
    }

    return y + lineHeight - rect.y() + bottom;
}
Ejemplo n.º 17
0
void XKPPlacementLayout::setGeometry(const QRect &rect)
{
#ifdef DEBUG_XKPPLACEMENT
    qDebug() << "setGeometry:: rect(" << rect.x() << "," << rect.y() <<
            "," << rect.width() << "," << rect.height() << ")";
#endif
    // prevent recursively calls between setGeometry & evenFilter
    inSetGeometry = true;

    ItemWrapper *center = 0;
    int eastWidth = 0;
    int westWidth = 0;
    int northHeight = 0;
    int southHeight = 0;
    int centerHeight = 0;
    int i;

    QLayout::setGeometry(rect);

    // update lastRect for updateGeometry method
    lastRect = rect;

    for(i = 0; i < list.size(); ++i) {
        ItemWrapper *wrapper = list.at(i);
        QLayoutItem *item = wrapper->item;
        Placement position = wrapper->position;
        QSize placementSize = wrapper->widget->property(placementSizeName).toSize();
        QRect itemRect;

#if defined(DEBUG_XKPPLACEMENT) && defined(DEBUG_XKPPLACEMENT_EXHAUSTIVE)
        qDebug() << "setGeometry::Vertical object->" << wrapper->widget->objectName();
        qDebug() << "setGeometry::Vertical placementSize(" << placementSize.width() <<
                "," << placementSize.height() << ")";
#endif

        // to prevent object without assign size
        if(!placementSize.isValid()) {
            if(wrapper->widget->size().isValid()) {
                wrapper->widget->setProperty(placementSizeName, wrapper->widget->size());
            } else {
                wrapper->widget->resize(item->sizeHint());
                wrapper->widget->setProperty(placementSizeName, item->sizeHint());
            }
        }

        if(position == None) {
            continue;
        } else
        if(position == Top) {
            itemRect = QRect(rect.x(), northHeight, rect.width(),
                             placementSize.height());
#if defined(DEBUG_XKPPLACEMENT) && defined(DEBUG_XKPPLACEMENT_EXHAUSTIVE)
            qDebug() << "setGeometry::TOP itemRect(" << itemRect.x() << "," << itemRect.y() <<
                    "," << itemRect.width() << "," << itemRect.height() << ")";
#endif
            wrapper->widget->setGeometry(itemRect);

            northHeight += itemRect.height() + spacing();
        } else
        if(position == Bottom) {
            itemRect = QRect(wrapper->widget->geometry().x(),
                            wrapper->widget->geometry().y(), rect.width(),
                            placementSize.height());
            wrapper->widget->setGeometry(itemRect);

            southHeight += wrapper->widget->geometry().height() + spacing();
            itemRect = QRect(rect.x(),
                            rect.y() + rect.height() - southHeight + spacing(),
                            wrapper->widget->geometry().width(),
                            placementSize.height());
#if defined(DEBUG_XKPPLACEMENT) && defined(DEBUG_XKPPLACEMENT_EXHAUSTIVE)
            qDebug() << "setGeometry::BOTTOM itemRect(" << itemRect.x() << "," << itemRect.y() <<
                    "," << itemRect.width() << "," << itemRect.height() << ")";
#endif
            wrapper->widget->setGeometry(itemRect);
        } else
        if(position == Center) {
            center = wrapper;
        }
    }

    centerHeight = rect.height() - northHeight - southHeight;

    for(i = 0; i < list.size(); ++i) {
        ItemWrapper *wrapper = list.at(i);
        QLayoutItem *item = wrapper->item;
        Placement position = wrapper->position;
        QSize placementSize = wrapper->widget->property(placementSizeName).toSize();
        QRect itemRect;

#if defined(DEBUG_XKPPLACEMENT) && defined(DEBUG_XKPPLACEMENT_EXHAUSTIVE)
        qDebug() << "setGeometry::Horizontal object->" << wrapper->widget->objectName();
        qDebug() << "setGeometry::Horizontal placementSize(" << placementSize.width() <<
                "," << placementSize.height() << ")";
#endif

        // to prevent object without assign size
        if(!placementSize.isValid()) {
            if(wrapper->widget->size().isValid()) {
                wrapper->widget->setProperty(placementSizeName, wrapper->widget->size());
            } else {
                wrapper->widget->resize(item->sizeHint());
                wrapper->widget->setProperty(placementSizeName, item->sizeHint());
            }
        }

        if(position == None) {
            continue;
        } else
        if(position == Left) {
            itemRect = QRect(rect.x() + westWidth, northHeight,
                             placementSize.width(), centerHeight);
#if defined(DEBUG_XKPPLACEMENT) && defined(DEBUG_XKPPLACEMENT_EXHAUSTIVE)
            qDebug() << "setGeometry::LEFT itemRect(" << itemRect.x() << "," << itemRect.y() <<
                    "," << itemRect.width() << "," << itemRect.height() << ")";
#endif
            wrapper->widget->setGeometry(itemRect);

            westWidth += itemRect.width() + spacing();
        } else
        if(position == Right) {
            itemRect = QRect(wrapper->widget->geometry().x(),
                             wrapper->widget->geometry().y(),
                             wrapper->widget->geometry().width(), centerHeight);
            wrapper->widget->setGeometry(itemRect);

            eastWidth += wrapper->widget->geometry().width() + spacing();
            itemRect = QRect(rect.x() + rect.width() - eastWidth + spacing(),
                             northHeight, wrapper->widget->geometry().width(),
                             wrapper->widget->geometry().height());
#if defined(DEBUG_XKPPLACEMENT) && defined(DEBUG_XKPPLACEMENT_EXHAUSTIVE)
            qDebug() << "setGeometry::RIGHT itemRect(" << itemRect.x() << "," << itemRect.y() <<
                    "," << itemRect.width() << "," << itemRect.height() << ")";
#endif
            wrapper->widget->setGeometry(itemRect);
        }
    }

    if(center)
        center->item->setGeometry(QRect(westWidth, northHeight,
                                        rect.width() - eastWidth - westWidth,
                                        centerHeight));
    inSetGeometry = false;
}
Ejemplo n.º 18
0
void ZBorderLayout::setGeometry(const QRect &rect)
{
    ItemWrapper *center = 0;
    int eastWidth = 0;
    int westWidth = 0;
    int northHeight = 0;
    int southHeight = 0;
    int centerHeight = 0;
    int i;

    QLayout::setGeometry(rect);

    for (i = 0; i < list.size(); ++i) {
        ItemWrapper *wrapper = list.at(i);
        QLayoutItem *item = wrapper->item;
        Position position = wrapper->position;

        if (position == North) {
            item->setGeometry(QRect(rect.x(), northHeight, rect.width(),
                                    item->sizeHint().height()));

            northHeight += item->geometry().height() + spacing();
        } else if (position == South) {
            item->setGeometry(QRect(item->geometry().x(),
                                    item->geometry().y(), rect.width(),
                                    item->sizeHint().height()));

            southHeight += item->geometry().height() + spacing();

            item->setGeometry(QRect(rect.x(),
                              rect.y() + rect.height() - southHeight + spacing(),
                              item->geometry().width(),
                              item->geometry().height()));
        } else if (position == Center) {
            center = wrapper;
        }
    }

    centerHeight = rect.height() - northHeight - southHeight;

    for (i = 0; i < list.size(); ++i) {
        ItemWrapper *wrapper = list.at(i);
        QLayoutItem *item = wrapper->item;
        Position position = wrapper->position;

        if (position == West) {
            item->setGeometry(QRect(rect.x() + westWidth, northHeight,
                                    item->sizeHint().width(), centerHeight));

            westWidth += item->geometry().width() + spacing();
        } else if (position == East) {
            item->setGeometry(QRect(item->geometry().x(), item->geometry().y(),
                                    item->sizeHint().width(), centerHeight));

            eastWidth += item->geometry().width() + spacing();

            item->setGeometry(QRect(
                              rect.x() + rect.width() - eastWidth + spacing(),
                              northHeight, item->geometry().width(),
                              item->geometry().height()));
        }
    }

    if (center)
        center->item->setGeometry(QRect(westWidth, northHeight,
                                        rect.width() - eastWidth - westWidth,
                                        centerHeight));
}
Ejemplo n.º 19
0
// Arranges widgets and returns height required.
int PackedLayout::arrange(const QRect& rect, bool set) const
{
    int x = rect.x();
    int y = rect.y();
    int yrow = 0;
    QList<QRect> posn;
    int end = mItems.count();
    QList<QLayoutItem*> items;
    for (int i = 0;  i < end;  ++i)
    {
        QLayoutItem* item = mItems[i];
        if (item->isEmpty())
            continue;
        QSize size = item->sizeHint();
        int right = x + size.width();
        if (right > rect.right()  &&  x > rect.x())
        {
            x = rect.x();
            y = y + yrow + spacing();
            right = x + size.width();
            yrow = size.height();
        }
        else
            yrow = qMax(yrow, size.height());
        items.append(item);
        posn.append(QRect(QPoint(x, y), size));
        x = right + spacing();
    }
    if (set)
    {
        int count = items.count();
        if (mAlignment == Qt::AlignLeft)
        {
            // Left aligned: no position adjustment needed
            // Set the positions of all the layout items
            for (int i = 0;  i < count;  ++i)
                items[i]->setGeometry(posn[i]);
        }
        else
        {
            // Set the positions of all the layout items
            for (int i = 0;  i < count; )
            {
                // Adjust item positions a row at a time
                y = posn[i].y();
                int last;   // after last item in this row
                for (last = i + 1;  last < count && posn[last].y() == y;  ++last) ;
                int n = last - i;   // number of items in this row
                int free = rect.right() - posn[last - 1].right();
                switch (mAlignment)
                {
                    case Qt::AlignJustify:
                        if (n == 1)
                        {
                            items[i]->setGeometry(posn[i]);
                            ++i;
                        }
                        else if (n > 1)
                        {
                            for (int j = 0;  i < last;  ++j, ++i)
                                items[i]->setGeometry(QRect(QPoint(posn[i].x() + (free * j)/(n - 1), y), posn[i].size()));
                        }
                        break;
                    case Qt::AlignHCenter:
                        free /= 2;
                        // fall through to AlignRight
                    case Qt::AlignRight:
                        for ( ;  i < last;  ++i)
                            items[i]->setGeometry(QRect(QPoint(posn[i].x() + free, y), posn[i].size()));
                        break;
                    default:
                        break;
                }
            }
        }
    }
    return y + yrow - rect.y();
}