Merge branch 'master' of https://vcs.maemo.org/git/situare
[situare] / src / ui / userinfo.cpp
index 400904d..d52780b 100644 (file)
 #include "../user/user.h"
 #include "userinfo.h"
 
-const int BACKGROUND_WIDTH = 240; ///< Width for item
-const int BACKGROUND_TOP_HEIGHT = 16; ///< Height for item top
-const int BACKGROUND_BOTTOM_HEIGHT = 15; ///< Height for item bottom
-const int ICON_HEIGHT = 24; ///< Icon height
-const int ICON_WIDTH = 24;  ///< Icon width
-const int MARGIN = 5; ///< Icon margin
-const int MOUSE_PRESS_AREA_WIDTH = 20;  ///< Area width for item height toggling
-const int MOUSE_PRESS_AREA_HEIGHT = 20; ///< Area height for item height toggling
+const int BACKGROUND_WIDTH = 240;           ///< Width for item
+const int BACKGROUND_TOP_HEIGHT = 16;       ///< Height for item top
+const int BACKGROUND_BOTTOM_HEIGHT = 15;    ///< Height for item bottom
+const int ICON_HEIGHT = 24;                 ///< Icon height
+const int ICON_WIDTH = 24;                  ///< Icon width
+const int MARGIN = 5;                       ///< Icon margin
+const int LINE_LENGTH = 17;                 ///< Line length
+const int MOUSE_PRESS_AREA_WIDTH = 20;      ///< Area width for item height toggling
+const int MOUSE_PRESS_AREA_HEIGHT = 20;     ///< Area height for item height toggling
 
 /**
 * @var LABEL_MAX_WIDTH
@@ -168,6 +169,23 @@ void UserInfo::setMessageText(const QString &text)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_messageText = text;
+    m_expandedMessageText = text;
+    int textWidth = fontMetrics().width(m_expandedMessageText);
+
+    if (textWidth > 150){
+        QStringList words = m_expandedMessageText.split(" ");
+
+        for (int i = 0; i < words.count();i++){
+            QString temp = words.at(i);
+
+            if(temp.length() >= LINE_LENGTH) {
+                temp.insert(LINE_LENGTH,QString("\n"));
+                words.replace(i,temp);
+            }
+        }
+        m_expandedMessageText = words.join(" ");
+    }
+
     setText(false);
 }
 
@@ -198,8 +216,7 @@ void UserInfo::setText(bool expanded)
     qDebug() << __PRETTY_FUNCTION__;
 
     if (expanded) {
-        m_nameLabel->setText(m_userName);
-        m_statusTextLabel->setText(m_messageText);
+        m_statusTextLabel->setText(m_expandedMessageText);
     }
     else {
         m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
@@ -314,14 +331,16 @@ QString UserInfo::shortenText(const QLabel *label, const QString &text, int text
     qDebug() << __PRETTY_FUNCTION__;
 
     QFontMetrics labelMetrics = label->fontMetrics();
-
     QString textParam = text;
     int index = textParam.indexOf('\n');
+    int textWidth = fontMetrics().width(textParam);
 
-    if (index > 0) {
-        textParam.truncate(index);
-        textParam.append("...");
-    }
+        if (index > 0) {
+            textParam.truncate(index);
+            textParam.append("...");
+        }
+            if (textWidth > 150)
+                textParam.insert(LINE_LENGTH, QString("\n"));
 
    return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
 }