#include "extendedlistitem.h"
-const int SUBITEM_TEXT_ROW_HEIGHT = ICON_HEIGHT; ///< Sub item text row height
-
ExtendedListItem::ExtendedListItem()
: m_selected(false),
m_expandedHeight(ITEM_MIN_HEIGHT),
m_subItemStoreList->append(itemStore);
}
+QRect ExtendedListItem::boundingRect(const QString &text)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
+ QPainter painter(&p);
+ painter.setFont(NOKIA_FONT_SMALL);
+
+ QFontMetrics textMetrics = painter.fontMetrics();
+ QRect textRect;
+ QStringList rows = text.split('\n');
+
+ foreach (QString row, rows) {
+
+ QRect textRowRect = textMetrics.boundingRect(row);
+
+ if (textRowRect.width() > textRect.width())
+ textRect.setWidth(textRowRect.width());
+
+ textRect.setHeight(textRect.height() + textRowRect.height());
+ }
+
+ return textRect;
+}
+
void ExtendedListItem::clearSubItems()
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
- QPainter painter(&p);
- painter.setFont(NOKIA_FONT_SMALL);
- QFontMetrics textMetrics = painter.fontMetrics();
+ const int TEXT_BOTTOM_MARGIN = 2;
+
+ QRect textRect = boundingRect(text);
- QRect textRect = textMetrics.boundingRect(text);
int textRectFactor = textRect.width() / m_subItemTextWidth;
- textRectFactor++;
+ textRectFactor += textRect.height() / SUBITEM_TEXT_ROW_HEIGHT;
+
QRect expandedTextRect = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
* textRectFactor);
- m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT;
- m_expandedHeight += expandedTextRect.height();
+ m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT + TEXT_BOTTOM_MARGIN;
+ m_expandedHeight += expandedTextRect.height() + TEXT_BOTTOM_MARGIN;
setSize(QSize(ITEM_WIDTH, m_normalHeight));
return expandedTextRect;
private:
/**
+ * @brief Returns text's bounding rect.
+ *
+ * Takes into account line breaks in text.
+ *
+ * @param text text which rect is calculated
+ */
+ QRect boundingRect(const QString &text);
+
+ /**
* @brief Calculates text rects.
*
* Rect width is defined by sub item text width.
text = itemStore->text();
}
else {
- subItemTextRect.setHeight(ICON_HEIGHT);
+ subItemTextRect.setHeight(SUBITEM_TEXT_ROW_HEIGHT);
text = itemStore->shortenedText();
}
painter->drawPixmap(iconRect, itemStore->icon());
painter->drawText(subItemTextRect, Qt::TextWrapAnywhere, text);
- previousSubItemTextRectBottom = subItemTextRect.bottom();
+ previousSubItemTextRectBottom = subItemTextRect.bottom() + ICON_MARGIN;
}
}
}
const int SUBITEM_TEXT_MAX_WIDTH = ITEM_WIDTH - 3 * MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH
- MARGIN * 2;
+const int SUBITEM_TEXT_ROW_HEIGHT = 22; ///< Subitems text row height
+
const int TITLE_DISPLAY_INDEX = Qt::DisplayRole;
const int AVATAR_IMAGE_INDEX = Qt::DecorationRole;
QVERIFY(subItems);
QCOMPARE(subItems->count(), 3);
- QCOMPARE(subItems->at(0)->textRect(), QRect(0, 0, 250, 72));
- QCOMPARE(subItems->at(1)->textRect(), QRect(0, 0, 250, 24));
- QCOMPARE(subItems->at(2)->textRect(), QRect(0, 0, 250, 48));
+ QCOMPARE(subItems->at(0)->textRect(), QRect(0, 0, 250, 66));
+ QCOMPARE(subItems->at(1)->textRect(), QRect(0, 0, 250, 22));
+ QCOMPARE(subItems->at(2)->textRect(), QRect(0, 0, 250, 44));
friendListItem->toggleSelection();
- QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142 + 3 * 24));
+ QCOMPARE(friendListItem->data(ITEM_SIZE_HINT_INDEX).toSize(), QSize(368, 142 + 3 * 22));
QCOMPARE(friendListItem->data(ITEM_EXPANDED_INDEX).toBool(), true);
friendListItem->toggleSelection();