Added new userinfo implementation
authorKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Fri, 14 May 2010 12:09:18 +0000 (15:09 +0300)
committerKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Fri, 14 May 2010 12:09:18 +0000 (15:09 +0300)
src/src.pro
src/ui/mapviewscreen.cpp
src/ui/mapviewscreen.h
src/ui/userinfo.cpp
src/ui/userinfo.h
src/ui/userpanel.cpp

index 5183ea6..38a0d82 100644 (file)
@@ -83,7 +83,8 @@ HEADERS += ui/mainwindow.h \
     ui/userinfo.h
 QT += network \
     webkit
-#DEFINES += QT_NO_DEBUG_OUTPUT
+
+# DEFINES += QT_NO_DEBUG_OUTPUT
 !maemo5 { 
     message(QJson built in)
     message(Make sure you have QJson development headers installed)
index 45de35f..2b9a477 100644 (file)
@@ -36,8 +36,8 @@ MapViewScreen::MapViewScreen(QWidget *parent)
     mapView->setScene(mapEngine->scene());
 
     FriendListPanel *friendsListPanel = new FriendListPanel(this);
-    UserInfoPanel *userPanel = new UserInfoPanel(this);
-    PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
+    userPanel = new UserInfoPanel(this);
+    PanelSideBar *m_userPanelSidebar = new PanelSideBar(this, LEFT);
     PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
 
     connect(mapView, SIGNAL(viewScrolled(QPoint)),
@@ -84,8 +84,8 @@ MapViewScreen::MapViewScreen(QWidget *parent)
                        osmLicense->fontMetrics().height());
 
     friendsListPanel->stackUnder(friendsListPanelSidebar);
-    userPanelSidebar->stackUnder(friendsListPanel);
-    userPanel->stackUnder(userPanelSidebar);
+    m_userPanelSidebar->stackUnder(friendsListPanel);
+    userPanel->stackUnder(m_userPanelSidebar);
     osmLicense->stackUnder(userPanel);
     mapView->stackUnder(osmLicense);
 
index ecfdd66..dfa770f 100644 (file)
@@ -29,6 +29,8 @@
 #include "friendlistpanel.h"
 #include "userpanel.h"
 
+#include "panelsidebar.h"
+
 /**
 * @brief Map View class. Used to display Map
 *
@@ -90,6 +92,7 @@ private:
     MapEngine *mapEngine; ///< MapEngine
     QLabel *osmLicense; ///< Label for Open Street Map license
     UserInfoPanel *userPanel; ///< Instance of the user information panel
+    PanelSideBar *m_userPanelSidebar;
 };
 
 #endif // MAPVIEWTAB_H
index afb28fb..4c82e8f 100644 (file)
@@ -83,8 +83,6 @@ UserInfo::UserInfo(QWidget *parent)
     m_nameLabel = new QLabel();
     m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
 
-
-
     m_updatedLabel = new QLabel();
     m_updatedLabel->setWordWrap(true);
     m_statusTextLabel = new QLabel();
@@ -151,10 +149,10 @@ void UserInfo::setUserName(const QString &name)
 
 void UserInfo::setAvatar(const QPixmap &image)
 {
-//    m_avatar = image;
-//   // m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
-//    //m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
-//    m_imageLabel->setPixmap(m_avatar);
+    m_avatar = image;
+   // m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
+    //m_imageLabel->setPixmap(AvatarImage::create(m_avatar.profileImage()));
+    m_imageLabel->setPixmap(m_avatar);
 }
 
 
@@ -169,10 +167,9 @@ void UserInfo::setMessageText(const QString &text)
 
 void UserInfo::setAddress(const QString &addr)
 {
-    if(m_address == addr)
-      return;
-    m_address = addr;
-    m_locationLabel->setText(m_address);
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_locationLabel->setText(addr);
 //    shortenTexts();
 }
 
@@ -182,84 +179,84 @@ void UserInfo::setTime(const QString &tim)
       return;
     m_time = tim;
     m_updatedLabel->setText(m_time);
-//    shortenTexts();
+    shortenTexts();
 }
 
-//void UserInfo::shortenTexts()
-//{
-//    qDebug() << __PRETTY_FUNCTION__;
-//
-//    QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
-//    QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
-//
-//    QString name = m_userName;
-//    QString updated = m_time;
-//    QString statusText = m_messageText;
-//    QString location = m_address;
-//
-//    int nameIndex = name.indexOf('\n');
-//    int updatedIndex = updated.indexOf('\n');
-//    int statusTextIndex = statusText.indexOf('\n');
-//    int locationIndex = location.indexOf('\n');
-//
-//    if (nameIndex > 0) {
-//        name.truncate(nameIndex);
-//        name.append("...");
-//    }
-//    if (updatedIndex > 0) {
-//        updated.truncate(updatedIndex);
-//        updated.append("...");
-//    }
-//    if (statusTextIndex > 0) {
-//        statusText.truncate(statusTextIndex);
-//        statusText.append("...");
-//    }
-//    if (locationIndex > 0) {
-//        location.truncate(locationIndex);
-//        location.append("...");
-//    }
-//
-//    m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, LABEL_MAX_WIDTH + 30);
-//    m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
-//    m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
-//                                                          LABEL_MAX_WIDTH);
-//    m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
-//}
-//
-//void UserInfo::setText(bool expanded)
-//{
-//    qDebug() << __PRETTY_FUNCTION__;
-//
-//    if (expanded) {
-//        m_nameLabel->setText(m_userName);
-//        m_updatedLabel->setText(m_time);
-//        m_statusTextLabel->setText(m_messageText);
-//        m_locationLabel->setText(m_address);
-//    }
-//    else {
-//        m_nameLabel->setText(m_shortenedName);
-//        m_updatedLabel->setText(m_shortenedUpdated);
-//        m_statusTextLabel->setText(m_shortenedStatusText);
-//        m_locationLabel->setText(m_shortenedLocation);
-//    }
-//}
-
-//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)) {
-//        if (m_expanded) {
-//            setText(false);
-//            m_expanded = false;
-//        }
-//        else {
-//            setText(true);
-//            m_expanded = true;
-//        }
-//    }
-//}
+void UserInfo::shortenTexts()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
+    QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
+
+    QString name = m_userName;
+    QString updated = m_time;
+    QString statusText = m_messageText;
+    QString location = m_address;
+
+    int nameIndex = name.indexOf('\n');
+    int updatedIndex = updated.indexOf('\n');
+    int statusTextIndex = statusText.indexOf('\n');
+    int locationIndex = location.indexOf('\n');
+
+    if (nameIndex > 0) {
+        name.truncate(nameIndex);
+        name.append("...");
+    }
+    if (updatedIndex > 0) {
+        updated.truncate(updatedIndex);
+        updated.append("...");
+    }
+    if (statusTextIndex > 0) {
+        statusText.truncate(statusTextIndex);
+        statusText.append("...");
+    }
+    if (locationIndex > 0) {
+        location.truncate(locationIndex);
+        location.append("...");
+    }
+
+    m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, LABEL_MAX_WIDTH + 30);
+    m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
+    m_shortenedStatusText = otherLabelsMetrics.elidedText(statusText, Qt::ElideRight,
+                                                          LABEL_MAX_WIDTH);
+    m_shortenedLocation = otherLabelsMetrics.elidedText(location, Qt::ElideRight, LABEL_MAX_WIDTH);
+}
+
+void UserInfo::setText(bool expanded)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (expanded) {
+        m_nameLabel->setText(m_userName);
+        m_updatedLabel->setText(m_time);
+        m_statusTextLabel->setText(m_messageText);
+        m_locationLabel->setText(m_address);
+    }
+    else {
+        m_nameLabel->setText(m_shortenedName);
+        m_updatedLabel->setText(m_shortenedUpdated);
+        m_statusTextLabel->setText(m_shortenedStatusText);
+        m_locationLabel->setText(m_shortenedLocation);
+    }
+}
+
+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)) {
+        if (m_expanded) {
+            setText(false);
+            m_expanded = false;
+        }
+        else {
+            setText(true);
+            m_expanded = true;
+        }
+    }
+}
 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
 {
 //    Q_UNUSED(aPaintEvent);
index e9507ce..ef5b8cf 100644 (file)
@@ -58,13 +58,13 @@ protected:
     * @param event QMouseEvent mouse press event
     */
     void mousePressEvent(QMouseEvent *event);
-//    /**
-//    * @brief Call toggleHeight if mouse position is unchanged.
-//    *
-//    * Check if current mouse position is same as mouse release position.
-//    * @param event QMouseEvent mouse release event
-//    */
-//    void mouseReleaseEvent(QMouseEvent *event);
+    /**
+    * @brief Call toggleHeight if mouse position is unchanged.
+    *
+    * Check if current mouse position is same as mouse release position.
+    * @param event QMouseEvent mouse release event
+    */
+    void mouseReleaseEvent(QMouseEvent *event);
 
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
@@ -96,7 +96,7 @@ public slots:
     * @param tim Reference to time when message was sent.
     */
     void setTime(const QString &tim);
-    /**
+   /**
     * @brief Sets the user name
     *
     * @param usernam Reference to user name
@@ -108,18 +108,18 @@ private slots:
     *
     */
     void messageUpdate();
-//    /**
-//    * @brief Set shortened or full-length text to labels.
-//    *
-//    * @param expanded true if full-length text is set, false otherwise
-//    */
-//    void setText(bool expanded);
-//    /**
-//    * @brief Set shortened texts from User data.
-//    *
-//    * Text length is defined by MAXIMUM_CHARS.
-//    */
-//    void shortenTexts();
+    /**
+    * @brief Set shortened or full-length text to labels.
+    *
+    * @param expanded true if full-length text is set, false otherwise
+    */
+    void setText(bool expanded);
+    /**
+    * @brief Set shortened texts from User data.
+    *
+    * Text length is defined by MAXIMUM_CHARS.
+    */
+    void shortenTexts();
     /**
     * @brief Slot function to forward friends status update signal
     *
@@ -154,7 +154,7 @@ private:
     QString m_address;
     QString m_time;
     QString m_messageText;
-    QString m_avatar;
+    QPixmap m_avatar;
     QString m_shortenedLocation;    ///< Shortened location text
     QString m_shortenedName;        ///< Shortened name text
     QString m_shortenedStatusText;  ///< Shortened status text
index a88a890..99eeaa8 100644 (file)
@@ -71,11 +71,11 @@ void UserInfoPanel::userDataReceived(User *user)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << user->name();
 
-    //m_userInfo->setUserName(user->name());
-//    m_userInfo->setAvatar(user->profileImage());
-//    m_userInfo->setMessageText(user->note());
-//    m_userInfo->setAddress(user->address());
-//    m_userInfo->setTime(user->timestamp());
+    m_userInfo->setUserName(user->name());
+    m_userInfo->setAvatar(user->profileImage());
+    m_userInfo->setMessageText(user->note());
+    m_userInfo->setAddress(user->address());
+    m_userInfo->setTime(user->timestamp());
 }
 
 void UserInfoPanel::reDrawUserPanel(int width, int height)