Fixed message text cutting in userinfo and modified updatelocationdialog
authorKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Tue, 24 Aug 2010 11:39:21 +0000 (14:39 +0300)
committerKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Tue, 24 Aug 2010 11:39:21 +0000 (14:39 +0300)
src/ui/updatelocation/updatelocationdialog.cpp
src/ui/updatelocation/updatelocationdialog.h
src/ui/userinfo.cpp

index b047149..abff25e 100644 (file)
    USA.\r
 */\r
 \r
+#include <Qt/qapplication.h>\r
+\r
 #include <QCheckBox>\r
 #include <QDebug>\r
 #include <QDialogButtonBox>\r
 #include <QGridLayout>\r
+#include <QKeyEvent>\r
 #include <QLabel>\r
 #include <QPushButton>\r
 #include <QScrollArea>\r
@@ -174,7 +177,7 @@ void UpdateLocationDialog::textChanged()
         m_textEdit->setTextCursor(textCursor);\r
     }\r
 \r
-    m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().length());\r
+    m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().toUtf8().length());\r
 }\r
 \r
 void UpdateLocationDialog::textSelectionChanged()\r
@@ -188,3 +191,5 @@ void UpdateLocationDialog::textSelectionChanged()
     disconnect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged()));\r
 }\r
 \r
+\r
+\r
index e6d932b..ece1139 100644 (file)
@@ -67,7 +67,6 @@ public:
  ******************************************************************************/\r
 \r
 public slots:\r
-\r
     /**\r
     * @brief Public slot, which is used to set the street address to location label\r
     *\r
@@ -76,7 +75,6 @@ public slots:
     void setAddress(const QString &address);\r
 \r
 private slots:\r
-\r
     /**\r
     * @brief Private slot, which is used to connect send button\r
     *\r
index a775b02..96df7a3 100644 (file)
 
 #include "userinfo.h"
 
-const int BACKGROUND_WIDTH = 368;           ///< Width for item
-const int BACKGROUND_TOP_HEIGHT = 20;       ///< 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 = 27;                 ///< 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
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = BACKGROUND_WIDTH - 3 * MARGIN - ICON_WIDTH + 130;
+const int BACKGROUND_WIDTH = 368;
+const int BACKGROUND_TOP_HEIGHT = 20;
+const int BACKGROUND_BOTTOM_HEIGHT = 15;
+const int ICON_HEIGHT = 24;
+const int ICON_WIDTH = 24;
+const int MARGIN = 5;
+const int LABEL_MAX_WIDTH = 300;
 
 UserInfo::UserInfo(QWidget *parent)
     : QWidget(parent),
@@ -181,7 +172,7 @@ void UserInfo::setMessageText(const QString &text)
     m_expandedMessageText.clear();
     QString temp = "";
     for(int i=0;i < text.length();i++) {
-        if(fontMetrics().width(temp.append(text.at(i))) > 170) {
+        if(fontMetrics().width(temp.append(text.at(i))) > LABEL_MAX_WIDTH) {
             temp.append("\n");
             if(temp.startsWith(QString(" ")))
                 temp.remove(0, 1);
@@ -191,6 +182,8 @@ void UserInfo::setMessageText(const QString &text)
         }
     }
     m_expandedMessageText.append(temp);
+    m_statusTextLabel->setText(m_expandedMessageText);
+
     setText(false);
 }
 
@@ -221,13 +214,15 @@ void UserInfo::setText(bool expanded)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    const int EXTRA_WIDTH_FOR_LABEL = 545;
+
     if (expanded) {
         m_statusTextLabel->setText(m_expandedMessageText);
     }
     else {
         m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
         m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
-                                               LABEL_MAX_WIDTH));
+                                               LABEL_MAX_WIDTH + EXTRA_WIDTH_FOR_LABEL));
     }
 }
 
@@ -258,6 +253,10 @@ void UserInfo::mouseReleaseEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
 
+
+    const int MOUSE_PRESS_AREA_WIDTH = 20;
+    const int MOUSE_PRESS_AREA_HEIGHT = 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 (m_expanded) {
@@ -336,17 +335,21 @@ QString UserInfo::shortenText(const QLabel *label, const QString &text, int text
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    const int LINE_LENGTH = 42;
+
     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 (textWidth > 250) ///< @todo magic number
-                textParam.insert(LINE_LENGTH, QString("\n"));
+
+        if (textWidth > LABEL_MAX_WIDTH)
+            textParam.insert(LINE_LENGTH, QString("\n"));
 
    return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
 }