Modified text rect calculation.
[situare] / src / ui / extendedlistitem.cpp
index 868857f..ed2f912 100644 (file)
@@ -76,40 +76,37 @@ void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
 
 QRect ExtendedListItem::boundingRect(const QString &text)
 {
-    qWarning() << __PRETTY_FUNCTION__ << 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;
     textRect.setSize(QSize(m_subItemTextWidth, textMetrics.height()));
 
-    QStringList rows = text.split('\n');
-
-    for (int i = 1; i < rows.count(); ++i) {
-        qWarning() << "jep";
-        QRect textRowRect = textMetrics.boundingRect(rows.at(i));
-        textRect.setHeight(textRect.height() + textRowRect.height());
+    QStringList lines = text.split("\n");
+    for (int i = 1; i  < lines.count(); ++i) {
+        textRect.setHeight(textRect.height() + textMetrics.height());
     }
 
     QStringList words = text.split(" ");
-    QString rowText;
+    QString textLine;
     for (int i = 0; i < words.count(); ++i) {
-        if (i == words.count() -1)
-            rowText.append(words.at(i));
+
+        if (i == 0)
+            textLine.append(words.at(i));
         else
-            rowText.append(words.at(i) + " ");
-        if (textMetrics.width(rowText) > m_subItemTextWidth) {
+            textLine.append(" " + words.at(i));
+
+        if ((textMetrics.width(textLine) > m_subItemTextWidth) && !textLine.contains("\n")) {
             textRect.setHeight(textRect.height() + textMetrics.height());
-            rowText = words.at(i);
-            qWarning() << "hep";
+            textLine.clear();
+            textLine.append(words.at(i));
         }
     }
 
-    //textRect.setHeight(textRect.height() + 5);
-//    qWarning() << textRect.width() << textRect.height();
     return textRect;
 }
 
@@ -121,11 +118,6 @@ QRect ExtendedListItem::calculateExpandedTextRect(const QString &text)
 
     QRect textRect = boundingRect(text);
     QRect expandedTextRect = textRect;
-//    int textRectFactor = textRect.width() / m_subItemTextWidth;
-//    textRectFactor += textRect.height() / SUBITEM_TEXT_ROW_HEIGHT;
-
-//    QRect expandedTextRect = QRect(0, 0, m_subItemTextWidth, SUBITEM_TEXT_ROW_HEIGHT
-//                                   * qMax(textRectFactor, 1));
 
     m_normalHeight += SUBITEM_TEXT_ROW_HEIGHT + TEXT_BOTTOM_MARGIN;
     m_expandedHeight += expandedTextRect.height() + TEXT_BOTTOM_MARGIN;