Review and fixes
[situare] / src / ui / userinfo.cpp
index d5e59af..0465bf7 100644 (file)
@@ -184,11 +184,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)));
@@ -209,12 +209,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) {
             setText(false);
             m_expanded = false;
@@ -226,9 +225,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);
 
@@ -281,7 +280,6 @@ void UserInfo::setMessageText(const QString &text)
     }
 
     m_messageText = list.join(" ");
-    m_statusTextLabel->setText(m_messageText);
     setText(false);
 }
 
@@ -297,14 +295,10 @@ void UserInfo::setText(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)
@@ -319,7 +313,7 @@ void UserInfo::setUserName(const QString &name)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_userName = name;
-    setText(false);
+    m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
 }
 
 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
@@ -327,15 +321,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
@@ -346,11 +340,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);
         }
     }