Merge branch 'fix_userinfo' into userinfo_collapse, review and fixes
[situare] / src / ui / userinfo.cpp
index adb89ee..244041e 100644 (file)
@@ -191,11 +191,11 @@ void UserInfo::messageUpdate()
     connect(this, SIGNAL(reverseGeoReady(QString)),
             m_updateLocation, SLOT(setAddress(QString)));
 
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-            this, SIGNAL(statusUpdate(QString,bool)));
+    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
+            this, SIGNAL(statusUpdate(QString, bool)));
 
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-            this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
+            this, SLOT(backupUpdateLocationDialogData(QString, bool)));
 
     connect(m_updateLocation, SIGNAL(finished(int)),
             this, SLOT(updateLocationDialogFinished(int)));
@@ -216,12 +216,11 @@ void UserInfo::mouseReleaseEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
 
-
-    const int MOUSE_PRESS_AREA_WIDTH = 20;
     const int MOUSE_PRESS_AREA_HEIGHT = 20;
+    const int MOUSE_PRESS_AREA_WIDTH = 20;
 
-    if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
-        (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
+    if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH)
+        && (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
         if (m_expanded) {
             setExpanded(false);
             m_expanded = false;
@@ -233,9 +232,9 @@ void UserInfo::mouseReleaseEvent(QMouseEvent *event)
     }
 }
 
-void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
+void UserInfo::paintEvent(QPaintEvent *event)
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
+    qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
 
     QPainter painter(this);
 
@@ -288,7 +287,7 @@ void UserInfo::setMessageText(const QString &text)
     }
 
     m_messageText = list.join(" ");
-    m_statusTextLabel->setText(m_messageText);
+
     setExpanded(false);
 }
 
@@ -304,14 +303,10 @@ void UserInfo::setExpanded(bool expanded)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (expanded) {
+    if (expanded)
         m_statusTextLabel->setText(m_messageText);
-    }
-    else {
-        m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
-        m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
-                                               LABEL_MAX_WIDTH));
-    }
+    else
+        m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText, LABEL_MAX_WIDTH));
 }
 
 void UserInfo::setTime(const QString &time)
@@ -326,7 +321,8 @@ void UserInfo::setUserName(const QString &name)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_userName = name;
-    setExpanded(false);
+
+    m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
 }
 
 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
@@ -334,15 +330,15 @@ 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');
+    QString copiedText = text;
+    int index = copiedText.indexOf('\n');
 
-        if (index > 0) {
-            textParam.truncate(index);
-            textParam.append("...");
-        }
+    if (index >= 0) {
+        copiedText.truncate(index);
+        copiedText.append("...");
+    }
 
-   return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
+    return labelMetrics.elidedText(copiedText, Qt::ElideRight, textMaxWidth);
 }
 
 QString UserInfo::splitWord(const QString &word) const
@@ -353,11 +349,10 @@ QString UserInfo::splitWord(const QString &word) const
     QString temp;
 
     for (int i = 0; i < word.length(); i++) {
-        if (fontMetrics().width(temp.append(word.at(i))) > LABEL_MAX_WIDTH)
-        {
-            temp.append(" ");
-            result.append(temp);
-            temp.clear();
+        if (fontMetrics().width(temp.append(word.at(i))) > LABEL_MAX_WIDTH) {
+            result.append(temp.left(temp.length() - 1));
+            result.append(" ");
+            temp.remove(0, temp.length() - 1);
         }
     }