/*!
    Calculates the smallest item height by taking the minimum of all items preferred heights.
*/
qreal HbListLayoutPrivate::calculateSmallestItemHeight() const
{
    qreal smallestHeight(0);
    if (uniformSizedItems()) {
        QGraphicsLayoutItem *firstItem = mItems.value(0);
        if (firstItem) {
            smallestHeight = firstItem->preferredHeight();  
        } 
    } else {  
        int itemCount = mItems.count();
        if (itemCount > 0) {
            smallestHeight = mItems.first()->preferredHeight();
        }
        for (int i = 1; i < itemCount; ++i) {       
            smallestHeight = qMin(smallestHeight, mItems.at(i)->preferredHeight());
        }
    }
    return smallestHeight;
}
/*!
    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;
    }
}