Fixed expanded message text
authorKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Tue, 22 Jun 2010 13:17:50 +0000 (16:17 +0300)
committerKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Tue, 22 Jun 2010 13:17:50 +0000 (16:17 +0300)
Reviewed by Henri Lampela

src/ui/updatelocation/updatelocationdialog.cpp
src/ui/userinfo.cpp
src/ui/userinfo.h

index d7a73c4..f0aa4bb 100644 (file)
@@ -42,6 +42,7 @@ UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publ
     {\r
         m_textEdit->setText(tr("Message:"));\r
         m_textEdit->selectAll();\r
+        m_charCountLabel->setNum(MESSAGE_MAX_LENGTH);\r
 \r
         connect(m_textEdit, SIGNAL(selectionChanged()),\r
                 this, SLOT(textSelectionChanged()));\r
@@ -78,8 +79,6 @@ UpdateLocationDialog::UpdateLocationDialog(const QString &userMessage, bool publ
     QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);\r
     sendButton->setText(tr("Send"));\r
 \r
-    m_charCountLabel->setNum(MESSAGE_MAX_LENGTH);\r
-\r
     gridLayout->addWidget(new QLabel(tr("Location:")), 0, 0, 1, 1, Qt::AlignTop | Qt::AlignLeft);\r
     gridLayout->addWidget(m_locationLabel, 0, 1, 1, 3);\r
     gridLayout->addWidget(scrollArea,      1, 0, 1, 4);\r
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);
 }
index 7455089..1646a46 100644 (file)
@@ -237,6 +237,7 @@ signals:
     * @param publish Publish on Facebook
     */
     void statusUpdate(const QString &status, const bool &publish);
+
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
@@ -255,6 +256,7 @@ private:
     QPointF m_coordinates;              ///< User current coordinates
     QString m_address;                  ///< Address from where the new message was sent
     QString m_backupMessage;            ///< Backup of users message
+    QString m_expandedMessageText;      ///< Expanded message text
     QString m_messageText;              ///< User's message
     QString m_time;                     ///< Time when the new message was sent
     QString m_userName;                 ///< User's name