Modified text rect calculation. text_cutting_bug
authorJupe <jupe@jupe-desktop.(none)>
Mon, 30 Aug 2010 17:34:28 +0000 (20:34 +0300)
committerJupe <jupe@jupe-desktop.(none)>
Mon, 30 Aug 2010 17:34:28 +0000 (20:34 +0300)
src/ui/extendedlistitem.cpp
src/ui/friendlistitem.cpp
src/ui/friendlistpanel.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;
index 6693246..395b9c1 100644 (file)
@@ -104,8 +104,7 @@ void FriendListItem::setUserData(User *user)
     QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
 
     setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
-    QString nameTemp = QString("Pitka nimi pitka nimi pitka nimi");
-    setTitle(shortenText(nameTemp, NAME_TEXT_MAX_WIDTH - distanceRect.width() - MARGIN * 2,
+    setTitle(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() - MARGIN * 2,
                         ListItem::TEXT_SIZE_NORMAL));
     setCoordinates(user->coordinates());
 
@@ -114,27 +113,7 @@ void FriendListItem::setUserData(User *user)
 
     clearSubItems();
 
-    QString noteTemp = QString("Joillakin lehdillä on tosi tarkat rajat painon kanssa, ja emme "
-                               "menneet Playboyn pyytämiin koekuvauksiinkaan, kun he sanoivat, "
-                               "että se on ainoa mahdollisuus. Jos on esim. liian ruskettunut, "
-                               "niin he karsivat saman tien pois. Nain jälkikäteen ajatellen minua "
-                               "on jäänyt harmittamaan, ettemme menneet koekuvaukseen kun kerran "
-                               "pyydettiin! Kun Julia pääsi kyseisen lehden Grapevine-sivulle "
-                               "vuonna 2003, meille molemmille jäi kytemään ajatus jatkosta. "
-                               "Olemme ihmetelleet, miksi Suomen lehdistö sivuutti asian vain "
-                               "nopeasti. Vaikka kyseessä ei ollutkaan monen kuvan kuvasarja "
-                               "Juliasta, hän silti poseerasi varsinaisessa Playboy-lehdessä.");
-    QString noteTemp2 = QString("hei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\n"
-                                "hei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei");
-
-    static int index = 0;
-
-//    if (index % 2)
-        addSubItem(noteTemp, QPixmap(":/res/images/envelope.png"));
-//    else
-//        addSubItem(noteTemp2, QPixmap(":/res/images/envelope.png"));
+    addSubItem(user->note(), QPixmap(":/res/images/envelope.png"));
     addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
     addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));
-
-    index++;
 }
index 2becab2..9c1b6c9 100644 (file)
@@ -202,7 +202,6 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
     qDebug() << __PRETTY_FUNCTION__;
 
     QStringList newUserIDs;
-    static int count = 0;
 
     foreach (User *user, friendList) {
         FriendListItem *item = 0;
@@ -221,10 +220,6 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
         }
 
         newUserIDs.append(user->userId());
-
-        count++;
-        if (count >= 1)
-            break;
     }
 
     m_friendListView->clearUnused(newUserIDs);