Esempio n. 1
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());
	}
void PeopleGroupedView::scrollTo(const QString& name)
{
    Q_UNUSED(name);
    int i;
    for (i=0; i<m_numSections; i++) {
        if (!name.compare(m_headings[i], Qt::CaseInsensitive))
            break;
    }

    int section=0;
    //if Other section exists shift increase i by 1
    if(m_sectionCounts[1] > 0)
     section = (i == m_numSections) ? 1 : i + 2;
    else //account for mecard +1
     section = (i == m_numSections) ? 0 : i + 1;
    m_mainLayout->rowCount();

    // prevent looking in non-existent rows in the grid layout
    int numSections = m_numSections;
    if (m_mainLayout->rowCount() < m_numSections)
        numSections = m_mainLayout->rowCount() - 1;

    QGraphicsLayoutItem *item = NULL;
    int diff = 1;
    while (section <= numSections || (section - diff) >= 0) {
        // first check this section for an item
        if (section <= numSections) {
            item = m_mainLayout->itemAt(section, 0);
            if (item)
                break;
        }

        int alternate = section - diff;
        if (alternate >= 0 && alternate <= numSections) {
            item = m_mainLayout->itemAt(alternate, 0);
            if (item)
                break;
        }

        section++;
        diff += 2;
    }

    if (item)
        m_controller->scrollTo(item->geometry().top());
}