예제 #1
0
QT_BEGIN_NAMESPACE

/*!
    \internal

    \a mw is the new parent. all items in the layout will be a child of \a mw.
 */
void QGraphicsLayoutPrivate::reparentChildItems(QGraphicsItem *newParent)
{
    Q_Q(QGraphicsLayout);
    int n =  q->count();
    //bool mwVisible = mw && mw->isVisible();
    for (int i = 0; i < n; ++i) {
        QGraphicsLayoutItem *layoutChild = q->itemAt(i);
        if (!layoutChild) {
            // Skip stretch items
            continue;
        }
        if (layoutChild->isLayout()) {
            QGraphicsLayout *l = static_cast<QGraphicsLayout*>(layoutChild);
            l->d_func()->reparentChildItems(newParent);
        } else if (QGraphicsItem *itemChild = layoutChild->graphicsItem()){
            QGraphicsItem *childParent = itemChild->parentItem();
#ifdef QT_DEBUG
            if (childParent && childParent != newParent && itemChild->isWidget() && qt_graphicsLayoutDebug()) {
                QGraphicsWidget *w = static_cast<QGraphicsWidget*>(layoutChild);
                qWarning("QGraphicsLayout::addChildLayout: widget %s \"%s\" in wrong parent; moved to correct parent",
                         w->metaObject()->className(), w->objectName().toLocal8Bit().constData());
            }
#endif
            if (childParent != newParent)
                itemChild->setParentItem(newParent);
        }
    }
}
예제 #2
0
/*!
    From QGraphicsLayout.
 */
void HbListLayout::setGeometry( const QRectF &rect )
{
    QGraphicsLayout::setGeometry(rect);
    QRectF effectiveRect = geometry();

    // TODO: Apply margins?
    //qreal left, top, right, bottom;
    //getContentsMargins(&left, &top, &right, &bottom);
    //effectiveRect.adjust(+left, +top, -right, -bottom);

    qreal y = effectiveRect.y();
    int itemCount = count();
    for ( int i = 0; i < itemCount; i++ ) {
        QGraphicsLayoutItem *item = itemAt( i );
        qreal itemHeight = item->preferredHeight();
        if (item->graphicsItem()->transform().isScaling()) {
            itemHeight *= item->graphicsItem()->transform().m22();
        }

        QRectF itemRect(effectiveRect.x(), y, effectiveRect.width(), itemHeight);
        item->setGeometry(itemRect);
        y += itemHeight;
    }
}
예제 #3
0
qreal QGraphicsFlowLayout::doLayout(const QRectF &rect, bool testOnly) const
{
	qreal left, top, right, bottom;
	getContentsMargins(&left, &top, &right, &bottom);
	QRectF effectiveRect = rect.adjusted(+left, +top, -right, -bottom);
	qreal x = effectiveRect.x();
	qreal y = effectiveRect.y();
	qreal lineHeight = 0;
	//! [9]

	//! [10]
	QGraphicsLayoutItem *item;
	foreach (item, m_itemList)
	{
		QGraphicsItem *wid = item->graphicsItem();
		qreal spaceX = spacing(false);
		if (spaceX == -1)
		{

		}

		qreal spaceY = spacing(true);
		if (spaceY == -1)
		{

		}
		//! [10]
		//! [11]
		int nextX = x + item->geometry().width() + spaceX;
		if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) 
		{
			x = effectiveRect.x();
			y = y + lineHeight + spaceY;
			nextX = x + item->geometry().width() + spaceX;
			lineHeight = 0;
		}

		if (!testOnly)
			item->setGeometry(QRectF(QPointF(x, y), item->geometry().size()));

		x = nextX;
		lineHeight = qMax(lineHeight, item->geometry().height());
	}
예제 #4
0
bool 
MTester::isLayoutContains (
        QGraphicsLayout     *layout,
        QGraphicsLayoutItem *item)
{
    bool found = false;

    #if 0
    SYS_DEBUG ("*** layout = %p", layout);
    SYS_DEBUG ("*** item   = %p", item);
    SYS_DEBUG ("*** count  = %d", layout->count());
    #endif
    for (int n = 0; n < layout->count(); ++n) {
        QGraphicsLayoutItem *child = layout->itemAt (n);

        if (item == child)
            found = true;

        #if 0
        QGraphicsWidget* widget    = (QGraphicsWidget*) child; 
        SYS_DEBUG ("**********************************************");
        SYS_DEBUG ("*** child   = %p", child);
        SYS_DEBUG ("*** widget  = %p", child->graphicsItem ());
        SYS_DEBUG ("*** name    = %s", SYS_STR(widget->objectName()));
        #endif
    }

    if (!found) {
        QGraphicsWidget* widget = (QGraphicsWidget*) item;
        SYS_WARNING ("Layout at %p should contain widget %p/%s.",
                layout, 
                item,   
                SYS_STR(widget->objectName()));
    }

    return found;
}