Merge branch 'master' into userinfo_collapse
authorKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Fri, 27 Aug 2010 12:41:19 +0000 (15:41 +0300)
committerKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Fri, 27 Aug 2010 12:41:19 +0000 (15:41 +0300)
src/ui/mainwindow.cpp
src/ui/updatelocation/updatelocationdialog.cpp
src/ui/updatelocation/updatelocationdialog.h
src/ui/userinfo.cpp
src/ui/userinfo.h
src/ui/userinfopanel.cpp
src/ui/userinfopanel.h

index b8b5093..b59bd2c 100644 (file)
@@ -349,6 +349,12 @@ void MainWindow::buildPanels()
 
     connect(m_tabbedPanel, SIGNAL(panelOpened()),
             m_mapView, SLOT(enableCenterShift()));
+
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_userInfoPanel, SIGNAL(collapse()));
+
+    connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
+            m_userInfoPanel, SIGNAL(collapse()));
 }
 
 void MainWindow::buildRoutingPanel()
index b047149..20e78ad 100644 (file)
    USA.\r
 */\r
 \r
+#include <QApplication>\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
@@ -157,24 +159,14 @@ void UpdateLocationDialog::textChanged()
 {\r
     qDebug() << __PRETTY_FUNCTION__;\r
 \r
-    QString msgText = m_textEdit->toPlainText();\r
+    QString msgText = m_textEdit->toPlainText().toUtf8();\r
 \r
-    if (msgText.length() > MESSAGE_MAX_LENGTH)\r
-    {\r
-        int cursorPos = m_textEdit->textCursor().position();\r
-\r
-        QTextCursor textCursor = m_textEdit->textCursor();\r
-        int removedChars = msgText.length() - MESSAGE_MAX_LENGTH;\r
-        m_textEdit->blockSignals(true);\r
-\r
-        m_textEdit->setText( msgText.left(cursorPos - removedChars) + msgText.mid(cursorPos));\r
-        m_textEdit->blockSignals(false);\r
-\r
-        textCursor.setPosition(cursorPos - removedChars);\r
-        m_textEdit->setTextCursor(textCursor);\r
+    if (msgText.length() > MESSAGE_MAX_LENGTH) {\r
+        QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);\r
+        QApplication::sendEvent(m_textEdit, &event);\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
@@ -187,4 +179,3 @@ void UpdateLocationDialog::textSelectionChanged()
     }\r
     disconnect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged()));\r
 }\r
-\r
index e6d932b..2731061 100644 (file)
 #define UPDATELOCATIONDIALOG_H\r
 \r
 #include <QDialog>\r
+\r
 #ifdef Q_WS_MAEMO_5\r
 #include <QAbstractKineticScroller>\r
 #endif // Q_WS_MAEMO_5\r
+\r
 #include "texteditautoresizer.h"\r
 \r
 class QCheckBox;\r
@@ -42,8 +44,6 @@ class QTextEdit;
 * @brief Update Location UI\r
 *\r
 * UI for update location functionality.\r
-*\r
-* @class UpdateLocationDialog\r
 */\r
 class UpdateLocationDialog : public QDialog\r
 {\r
@@ -65,32 +65,29 @@ public:
 /*******************************************************************************\r
  * MEMBER FUNCTIONS AND SLOTS\r
  ******************************************************************************/\r
-\r
 public slots:\r
-\r
     /**\r
-    * @brief Public slot, which is used to set the street address to location label\r
+    * @brief Used to set the street address to location label\r
     *\r
     * @param address Street address, result from SituareService's reverseGeo\r
     */\r
     void setAddress(const QString &address);\r
 \r
 private slots:\r
-\r
     /**\r
-    * @brief Private slot, which is used to connect send button\r
+    * @brief Used to connect send button\r
     *\r
     */\r
     void sendUpdate();\r
 \r
     /**\r
-    * @brief Private slot, which is used to get changes in messagetext\r
+    * @brief Used to get changes in messagetext\r
     *\r
     */\r
     void textChanged();\r
 \r
     /**\r
-    * @brief Private slot, which is used to clear default messagetext\r
+    * @brief Used to clear default messagetext\r
     *\r
     */\r
     void textSelectionChanged();\r
@@ -98,11 +95,9 @@ private slots:
 /*******************************************************************************\r
  * SIGNALS\r
  ******************************************************************************/\r
-\r
 signals:\r
-\r
     /**\r
-    * @brief Signal Signal for requestLocationUpdate from SituareEngine via MainWindow class\r
+    * @brief Routing signal for requestLocationUpdate to SituareEngine via MainWindow class\r
     *\r
     * @param status Status message\r
     * @param publish Publish on Facebook\r
@@ -112,13 +107,11 @@ signals:
 /*******************************************************************************\r
  * DATA MEMBERS\r
  ******************************************************************************/\r
-\r
 private:\r
-\r
-    QCheckBox *m_checkBox; ///< Pointer to CheckBox\r
-    QLabel *m_locationLabel; ///< Pointer to locationLabel\r
-    QLabel *m_charCountLabel; ///< Pointer to locationLabel\r
-    QTextEdit *m_textEdit; ///< Pointer to TextEdit\r
+    QCheckBox *m_checkBox;          ///< Pointer to CheckBox\r
+    QLabel *m_charCountLabel;       ///< Pointer to character counter label\r
+    QLabel *m_locationLabel;        ///< Pointer to locationLabel\r
+    QTextEdit *m_textEdit;          ///< Pointer to TextEdit\r
 };\r
 \r
 #endif // UPDATELOCATIONDIALOG_H\r
index a775b02..244041e 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_BOTTOM_HEIGHT = 15;
+const int BACKGROUND_TOP_HEIGHT = 20;
+const int BACKGROUND_WIDTH = 368;
+const int ICON_HEIGHT = 24;
+const int ICON_WIDTH = 24;
+const int LABEL_MAX_WIDTH = 300;
+const int MARGIN = 5;
 
 UserInfo::UserInfo(QWidget *parent)
     : QWidget(parent),
@@ -159,177 +150,179 @@ UserInfo::~UserInfo()
     }
 }
 
-void UserInfo::setAddress(const QString &address)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_locationLabel->setText(address);
-}
-
-void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
+void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_coordinates = coordinates;
+    m_backupMessage = status;
+    m_backupFacebookPublishPolicity = publish;
 }
 
-void UserInfo::setMessageText(const QString &text)
+void UserInfo::clearUpdateLocationDialogData()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_messageText = text;
-    m_expandedMessageText.clear();
-    QString temp = "";
-    for(int i=0;i < text.length();i++) {
-        if(fontMetrics().width(temp.append(text.at(i))) > 170) {
-            temp.append("\n");
-            if(temp.startsWith(QString(" ")))
-                temp.remove(0, 1);
-
-            m_expandedMessageText.append(temp);
-            temp.clear();
-        }
-    }
-    m_expandedMessageText.append(temp);
-    setText(false);
+    m_backupMessage.clear();
+    m_backupFacebookPublishPolicity = false;
 }
 
-void UserInfo::setProfileImage(const QPixmap &image)
+void UserInfo::collapse()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if(!image.isNull())
-        m_findButton->setButtonIcon(image);
+    setExpanded(false);
 }
 
-void UserInfo::setTime(const QString &time)
+void UserInfo::findButtonClicked()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_updatedLabel->setText(time);
+    emit findUser(m_coordinates);
 }
 
-void UserInfo::setUserName(const QString &name)
+void UserInfo::messageUpdate()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_userName = name;
-    setText(false);
-}
+    delete m_updateLocation;
+    m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
+                                                this);
 
-void UserInfo::setText(bool expanded)
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    connect(this, SIGNAL(reverseGeoReady(QString)),
+            m_updateLocation, SLOT(setAddress(QString)));
 
-    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));
-    }
-}
+    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
+            this, SIGNAL(statusUpdate(QString, bool)));
 
-void UserInfo::backupUpdateLocationDialogData(const QString &status, bool publish)
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
+            this, SLOT(backupUpdateLocationDialogData(QString, bool)));
 
-    m_backupMessage = status;
-    m_backupFacebookPublishPolicity = publish;
-}
+    connect(m_updateLocation, SIGNAL(finished(int)),
+            this, SLOT(updateLocationDialogFinished(int)));
 
-void UserInfo::clearUpdateLocationDialogData()
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    m_updateLocation->show();
 
-    m_backupMessage.clear();
-    m_backupFacebookPublishPolicity = false;
+    emit requestReverseGeo();
 }
 
-void UserInfo::findButtonClicked()
+void UserInfo::mousePressEvent(QMouseEvent *event)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
 
-    emit findUser(m_coordinates);
+    m_mousePosition = event->pos();
 }
 
 void UserInfo::mouseReleaseEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
 
-    if ((abs(m_mousePosition.y() - event->pos().y()) <= MOUSE_PRESS_AREA_WIDTH) &&
-        (abs(m_mousePosition.x() - event->pos().x()) <= MOUSE_PRESS_AREA_HEIGHT)) {
+    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 (m_expanded) {
-            setText(false);
+            setExpanded(false);
             m_expanded = false;
         }
         else {
-            setText(true);
+            setExpanded(true);
             m_expanded = true;
         }
     }
 }
 
-void UserInfo::mousePressEvent(QMouseEvent *event)
+void UserInfo::paintEvent(QPaintEvent *event)
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
+    qDebug() << __PRETTY_FUNCTION__ << " " << event->rect();
 
-    m_mousePosition = event->pos();
+    QPainter painter(this);
+
+    QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
+
+    QRect middleRect = QRect(topRect.left(), topRect.bottom() + 1, BACKGROUND_WIDTH,
+                             this->height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
+
+    QRect bottomRect = QRect(topRect.left(), middleRect.bottom() + 1, BACKGROUND_WIDTH,
+                             BACKGROUND_BOTTOM_HEIGHT);
+
+    painter.drawPixmap(topRect, m_backgroundTopImage);
+    painter.drawPixmap(middleRect, m_backgroundMiddleImage);
+    painter.drawPixmap(bottomRect, m_backgroundBottomImage);
 }
 
-void UserInfo::messageUpdate()
+void UserInfo::restoreUnsendMessage()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    delete m_updateLocation;
-    m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
-                                                this);
+    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
+    m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
+}
 
-    connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_updateLocation, SLOT(setAddress(QString)));
+void UserInfo::setAddress(const QString &address)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_locationLabel->setText(address);
+}
 
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-            this, SIGNAL(statusUpdate(QString,bool)));
+void UserInfo::setCoordinates(const GeoCoordinate &coordinates)
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-            this, SLOT(backupUpdateLocationDialogData(QString,bool)));
+    m_coordinates = coordinates;
+}
 
-    connect(m_updateLocation, SIGNAL(finished(int)),
-            this, SLOT(updateLocationDialogFinished(int)));
+void UserInfo::setMessageText(const QString &text)
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    m_updateLocation->show();
+    QStringList list;
+    list = text.split(' ');
 
-    emit requestReverseGeo();
+    for (int i = 0; i < list.count(); i++) {
+        if (fontMetrics().width(list.at(i)) > LABEL_MAX_WIDTH)
+            list.replace(i, splitWord(list.at(i)));
+    }
+
+    m_messageText = list.join(" ");
+
+    setExpanded(false);
+}
+
+void UserInfo::setProfileImage(const QPixmap &image)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(!image.isNull())
+        m_findButton->setButtonIcon(image);
 }
 
-void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
+void UserInfo::setExpanded(bool expanded)
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
+    qDebug() << __PRETTY_FUNCTION__;
 
-    QPainter painter(this);
+    if (expanded)
+        m_statusTextLabel->setText(m_messageText);
+    else
+        m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText, LABEL_MAX_WIDTH));
+}
 
-    QRect topRect = QRect(0, MARGIN, BACKGROUND_WIDTH, BACKGROUND_TOP_HEIGHT);
-///< @todo Overlaps with topRect?
-    QRect middleRect = QRect(0, topRect.bottom(), BACKGROUND_WIDTH,
-                             this->height() - BACKGROUND_TOP_HEIGHT - BACKGROUND_BOTTOM_HEIGHT);
-///< @todo Overlaps with middleRect
-    QRect bottomRect = QRect(topRect.left(), middleRect.bottom(), BACKGROUND_WIDTH,
-                             BACKGROUND_BOTTOM_HEIGHT);
+void UserInfo::setTime(const QString &time)
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    painter.drawPixmap(topRect, m_backgroundTopImage);
-    painter.drawPixmap(middleRect, m_backgroundMiddleImage);
-    painter.drawPixmap(bottomRect, m_backgroundBottomImage);
+    m_updatedLabel->setText(time);
 }
 
-void UserInfo::restoreUnsendMessage()
+void UserInfo::setUserName(const QString &name)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    m_backupMessage = settings.value(USER_UNSEND_MESSAGE, EMPTY).toString();
-    m_backupFacebookPublishPolicity =
-            settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
+    m_userName = name;
+
+    m_nameLabel->setText(shortenText(m_nameLabel, m_userName, LABEL_MAX_WIDTH));
 }
 
 QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
@@ -337,18 +330,35 @@ 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);
+    QString copiedText = text;
+    int index = copiedText.indexOf('\n');
+
+    if (index >= 0) {
+        copiedText.truncate(index);
+        copiedText.append("...");
+    }
+
+    return labelMetrics.elidedText(copiedText, Qt::ElideRight, textMaxWidth);
+}
 
-        if (index > 0) {
-            textParam.truncate(index);
-            textParam.append("...");
+QString UserInfo::splitWord(const QString &word) const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString result;
+    QString temp;
+
+    for (int i = 0; i < word.length(); i++) {
+        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);
         }
-            if (textWidth > 250) ///< @todo magic number
-                textParam.insert(LINE_LENGTH, QString("\n"));
+    }
+
+    result.append(temp);
 
-   return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
+    return result;
 }
 
 void UserInfo::updateLocationDialogFinished(int reason)
index de62847..ac51ac9 100644 (file)
@@ -77,9 +77,9 @@ protected:
     /**
      * @brief This function is called when the widget is drawn
      *
-     * @param aPaintEvent Pointer to paint event
+     * @param event Pointer to paint event
      */
-    void paintEvent(QPaintEvent *aPaintEvent);
+    void paintEvent(QPaintEvent *event);
 
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
@@ -121,12 +121,6 @@ public:
     void setUserName(const QString &name);
 
 public slots:
-
-    /**
-     * @brief Clears backups of message and publish on Facebook setting
-     */
-    void clearUpdateLocationDialogData();
-
     /**
      * @brief Saves status message and Facebook publish setting
      *
@@ -137,6 +131,11 @@ public slots:
     void backupUpdateLocationDialogData(const QString &status, bool publish);
 
     /**
+     * @brief Clears backups of message and publish on Facebook setting
+     */
+    void clearUpdateLocationDialogData();
+
+    /**
      * @brief Sets the message text
      *
      * @param text Reference to user message
@@ -144,7 +143,6 @@ public slots:
     void setMessageText(const QString &text);
 
 private:
-
     /**
      * @brief reads Unsend message from settings at startup
      */
@@ -155,17 +153,35 @@ private:
      *
      * @param expanded true if full-length text is set, false otherwise
      */
-    void setText(bool expanded);
+    void setExpanded(bool expanded);
 
     /**
-     * @brief Set shortened texts from User data.
+     * @brief Elides long text
      *
-     * Text length is defined by MAXIMUM_CHARS.
+     * @param label get the fontmetrics from the label
+     * @param text long text to be shortened
+     * @param textMaxWidth label width
+     * @returns shortened text
      */
     QString shortenText(const QLabel *label, const QString &text, int textMaxWidth);
 
+    /**
+     * @brief Split too long words.
+     *
+     * Splits long word to several by adding extra spaces
+     *
+     * @param word long word to be splitted
+     * @returns splitted word
+     */
+    QString splitWord(const QString &word) const;
+
 private slots:
     /**
+     * @brief Slot for collapse user info
+     */
+    void collapse();
+
+    /**
      * @brief Slot for find button click
      */
     void findButtonClicked();
@@ -245,7 +261,6 @@ private:
 
     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
index e68f390..e4e022c 100644 (file)
@@ -79,7 +79,10 @@ UserInfoPanel::UserInfoPanel(QWidget *parent)
             m_userInfo, SLOT(clearUpdateLocationDialogData()));
 
     connect(m_userInfo, SIGNAL(notificateUpdateFailing(QString, bool)),
-             this, SIGNAL(notificateUpdateFailing(QString, bool)));
+            this, SIGNAL(notificateUpdateFailing(QString, bool)));
+
+    connect(this, SIGNAL(collapse()),
+            m_userInfo, SLOT(collapse()));
 }
 
 void UserInfoPanel::userDataReceived(User *user)
index df38811..c575dc1 100644 (file)
@@ -72,6 +72,11 @@ signals:
     void findUser(const GeoCoordinate &coordinates);
 
     /**
+     * @brief Signal for collapse user info
+     */
+    void collapse();
+
+    /**
      * @brief Signal that used to inform user that his message/location update tp Situare server
      *        was failed.
      *        This signal is originally sended from UserInfo