Updated userinfo and userinfopanel classes. Added corresponding signals.
authorKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Mon, 17 May 2010 13:34:07 +0000 (16:34 +0300)
committerKatri Kaikkonen <katri.kaikkonen@ixonos.com>
Mon, 17 May 2010 13:34:07 +0000 (16:34 +0300)
Reviewed by: Marko Niemelä

src/ui/mapviewscreen.h
src/ui/updatelocation/updatelocationdialog.cpp
src/ui/updatelocation/updatelocationdialog.h
src/ui/userinfo.cpp
src/ui/userinfo.h
src/ui/userpanel.cpp
src/ui/userpanel.h

index 40c2103..5e36604 100644 (file)
@@ -98,22 +98,15 @@ signals:
     void mapLocationChanged();  
 
     /**
-    * @brief Signal when user location is fetched
+    * @brief Signal for refreshing user data.
     *
-    * @param user User data
     */
-    void userLocationReady(User *user);  
-
-    /**
-      * @brief Signal for HW increase button
-      */
-    void zoomInKeyPressed();
+    void refreshUserData();
 
     /**
-      * @brief Signal for HW decrease button
-      */
-    void zoomOutKeyPressed();
-
+    * @brief Signal for requesting reverseGeo from SituareEngine
+    *
+    */
     void requestReverseGeo();
 
     /**
@@ -131,7 +124,22 @@ signals:
     */
     void statusUpdate(const QString &status, const bool &publish);
 
-    void refreshUserData();
+    /**
+    * @brief Signal when user location is fetched
+    *
+    * @param user User data
+    */
+    void userLocationReady(User *user);
+
+    /**
+      * @brief Signal for HW increase button
+      */
+    void zoomInKeyPressed();
+
+    /**
+      * @brief Signal for HW decrease button
+      */
+    void zoomOutKeyPressed();
 
 /*******************************************************************************
  * DATA MEMBERS
index a7faf15..676033f 100755 (executable)
@@ -62,6 +62,11 @@ UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
     scrollArea->show();
 }
 
+UpdateLocationDialog::~UpdateLocationDialog()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+}
+
 void UpdateLocationDialog::setAddress(const QString &address)
 {
     qDebug() << __PRETTY_FUNCTION__;
index d584ad7..1464886 100755 (executable)
@@ -56,6 +56,7 @@ public:
     * @param parent
     */
     UpdateLocationDialog(QWidget *parent = 0);
+    ~UpdateLocationDialog();
 
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
index 113bba0..e8c8614 100644 (file)
@@ -5,6 +5,7 @@
        Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
        Jussi Laitinen - jussi.laitinen@ixonos.com
        Katri Kaikkonen - katri.kaikkonen@ixonos.com
+       Henri Lampela - henri.lampela@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    USA.
 */
 
-#include <QVBoxLayout>
-#include <QPushButton>
-#include <QPainter>
-#include <QDebug>
-#include <QPaintEvent>
-#include <QLabel>
-#include <QPixmap>
-#include <QFormLayout>
-#include <QSpacerItem>
-#include <QStylePainter>
-#include <math.h>
-
 #include "imagebutton.h"
-#include "avatarimage.h"
 #include "../user/user.h"
 #include "userinfo.h"
 
+const int BACKGROUND_TOP_HEIGHT = 20;
+const int BACKGROUND_BOTTOM_HEIGHT = 15;
+const QColor COLOR_GRAY = QColor(152, 152, 152);    ///< Gray color
+const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
+const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);     ///< Small font
+const int ICON_HEIGHT = 24;     ///< Icon height
+const int ICON_WIDTH = 24;       ///< Icon width
+const int IMAGE_HEIGHT = 60; ///< Friend image height
+const int IMAGE_WIDTH = 60;  ///< Friend image width
+const int ITEM_MIN_WIDTH = 250;  ///< Minimum width for item
+const int MARGIN = 5;   ///< Icon margin
+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 = ITEM_MIN_WIDTH - 3*MARGIN - ICON_WIDTH;
+
+const int NAME_LABEL_MAX_WIDTH = LABEL_MAX_WIDTH + 30;
+
 UserInfo::UserInfo(QWidget *parent)
     : QWidget(parent)
         , m_expanded(false)
@@ -47,14 +58,6 @@ UserInfo::UserInfo(QWidget *parent)
     verticalLayout->setSpacing(0);
     setLayout(verticalLayout);
 
-    QGridLayout *gridLayout = new QGridLayout(this);
-    gridLayout->setMargin(0);
-    gridLayout->setSpacing(0);
-
-    QHBoxLayout *topLayout = new QHBoxLayout(this);
-    topLayout->setMargin(0);
-    topLayout->setSpacing(0);
-
     QFormLayout *infoLayout = new QFormLayout(this);
     infoLayout->setMargin(0);
     infoLayout->setSpacing(0);
@@ -99,19 +102,15 @@ UserInfo::UserInfo(QWidget *parent)
     buttonLayout->addWidget(updateFriendsButton);
     buttonLayout->addWidget(updateStatusMessageButton);
 
-
     infoLayout->addRow(compassLabel, m_locationLabel);
     infoLayout->addRow(envelopeLabel, m_statusTextLabel);
     infoLayout->addRow(clockLabel, m_updatedLabel);
 
-    topLayout->addWidget(m_nameLabel);
+    verticalLayout->addWidget(m_imageLabel, 0, Qt::AlignHCenter);
 
-    gridLayout->addWidget(m_imageLabel);
-
-    verticalLayout->addLayout(gridLayout, 0);
-    verticalLayout->addLayout(topLayout, 1);
+    verticalLayout->addWidget(m_nameLabel, 1);
     verticalLayout->addLayout(infoLayout);
-    verticalLayout->addLayout(buttonLayout, 2 );
+    verticalLayout->addLayout(buttonLayout, 2);
 
     connect(updateStatusMessageButton,SIGNAL(clicked()),
             this,SLOT(messageUpdate()));
@@ -127,98 +126,65 @@ UserInfo::UserInfo(QWidget *parent)
     namePalette.setColor(QPalette::Foreground, Qt::white);
     m_nameLabel->setPalette(namePalette);
 
-    this->setMinimumHeight(300);
-
     m_backgroundTopImage.load(":/res/images/list_item_top.png");
     m_backgroundMiddleImage.load(":/res/images/list_item_middle.png");
     m_backgroundBottomImage.load(":/res/images/list_item_bottom.png");
+
+    this->setMinimumWidth(ITEM_MIN_WIDTH);
 }
 
 void UserInfo::setUserName(const QString &name)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    qDebug() << name;
-
-//    m_nameLabel->setText(name);
 
-//     shortenTexts();
+    m_userName = name;
+    setText(false);
 }
 
 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);
-}
+    qDebug() << __PRETTY_FUNCTION__;
 
+    m_imageLabel->setPixmap(image);
+}
 
 void UserInfo::setMessageText(const QString &text)
 {
-    if(m_messageText == text)
-      return;
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_messageText = text;
-//    m_statusTextLabel->setText(m_messageText);
-//    shortenTexts();
+    setText(false);
 }
 
 void UserInfo::setAddress(const QString &addr)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-//    m_locationLabel->setText(addr);
-//    shortenTexts();
+    m_locationLabel->setText(addr);
 }
 
 void UserInfo::setTime(const QString &tim)
 {
-    if(m_time == tim)
-      return;
-    m_time = tim;
-//    m_updatedLabel->setText(m_time);
-    shortenTexts();
-    setText(false);
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_updatedLabel->setText(tim);
 }
 
-void UserInfo::shortenTexts()
+QString UserInfo::shortenText(const QLabel *label, const QString &text, int textMaxWidth)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QFontMetrics nameLabelMetrics = m_nameLabel->fontMetrics();
-    QFontMetrics otherLabelsMetrics = m_locationLabel->fontMetrics();
+    QFontMetrics labelMetrics = label->fontMetrics();
 
-    QString name = m_userName;
-    QString updated = m_time;
-    QString statusText = m_messageText;
-    QString location = m_address;
+    QString textParam = text;
+    int index = textParam.indexOf('\n');
 
-    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("...");
+    if (index > 0) {
+        textParam.truncate(index);
+        textParam.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);
+   return labelMetrics.elidedText(textParam, Qt::ElideRight, textMaxWidth);
 }
 
 void UserInfo::setText(bool expanded)
@@ -227,15 +193,12 @@ void UserInfo::setText(bool expanded)
 
     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);
+        m_nameLabel->setText(shortenText(m_nameLabel, m_userName, NAME_LABEL_MAX_WIDTH));
+        m_statusTextLabel->setText(shortenText(m_statusTextLabel, m_messageText,
+                                               LABEL_MAX_WIDTH));
     }
 }
 
@@ -245,30 +208,18 @@ void UserInfo::mouseReleaseEvent(QMouseEvent *event)
 
     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;
-//        }
+        if (m_expanded) {
+            setText(false);
+            m_expanded = false;
+        }
+        else {
+            setText(true);
+            m_expanded = true;
+        }
     }
 }
 void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
 {
-//    Q_UNUSED(aPaintEvent);
-//
-//    QStyleOption option;
-//    option.init(this);
-//    QStylePainter painter(this);
-//
-//   // Temporary border
-//    painter.setPen(Qt::red);
-//    painter.drawRect(this->rect().x(), this->rect().y(), this->rect().width() - 1, this->rect().height() - 1);
-//
-//    style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
-//
     qDebug() << __PRETTY_FUNCTION__ << " " << aPaintEvent->rect();
 
     QPainter painter(this);
@@ -284,7 +235,6 @@ void UserInfo::paintEvent(QPaintEvent *aPaintEvent)
     painter.drawPixmap(bottomRect, m_backgroundBottomImage);
 }
 
-
 void UserInfo::mousePressEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__ << " " << event->pos();
@@ -296,19 +246,15 @@ void UserInfo::messageUpdate()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_locationDialog = new UpdateLocationDialog(this);
+    UpdateLocationDialog updateLocationDialog(this);
+
     emit requestReverseGeo();
 
     connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_locationDialog, SLOT(setAddress(QString)));
-    connect(m_locationDialog, SIGNAL(statusUpdate(QString, bool)),
+            &updateLocationDialog, SLOT(setAddress(QString)));
+    connect(&updateLocationDialog, SIGNAL(statusUpdate(QString, bool)),
             this, SIGNAL(statusUpdate(QString, bool)));
 
-    m_locationDialog->show();
+    updateLocationDialog.exec();
 }
 
-//void UserInfo::updateFriendsStatus()
-//{
-//    qDebug() << __PRETTY_FUNCTION__;
-//    //emit launchUpdateFriendsStatus();
-//}
index a1fb578..06c2494 100644 (file)
@@ -2,7 +2,10 @@
    Situare - A location system for Facebook
    Copyright (C) 2010  Ixonos Plc. Authors:
 
+       Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
        Jussi Laitinen - jussi.laitinen@ixonos.com
+       Katri Kaikkonen - katri.kaikkonen@ixonos.com
+       Henri Lampela - henri.lampela@ixonos.com
 
    Situare is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
 #define USERINFO_H
 
 #include <QWidget>
-#include <QTreeWidgetItem>
-#include <QListWidgetItem>
 #include "updatelocation/updatelocationdialog.h"
 
-#include "../user/user.h"
-
-class QLabel;
-
 class UserInfo : public QWidget
 {
     Q_OBJECT
@@ -47,12 +44,6 @@ public:
 *******************************************************************************/
 protected:
     /**
-    * @brief This function is called when the widget is drawn
-    *
-    * @param aPaintEvent Pointer to paint event
-    */
-    void paintEvent(QPaintEvent *aPaintEvent);
-    /**
     * @brief Set current mouse position to mouse event position.
     *
     * @param event QMouseEvent mouse press event
@@ -65,79 +56,88 @@ protected:
     * @param event QMouseEvent mouse release event
     */
     void mouseReleaseEvent(QMouseEvent *event);
+    /**
+    * @brief This function is called when the widget is drawn
+    *
+    * @param aPaintEvent Pointer to paint event
+    */
+    void paintEvent(QPaintEvent *aPaintEvent);
 
 /******************************************************************************
 * MEMBER FUNCTIONS AND SLOTS
 ******************************************************************************/
-public slots:
-
-
+public:
     /**
     * @brief Sets the users current address
     *
     * @param addr Reference to users current address
     */
     void setAddress(const QString &addr);
+
     /**
     * @brief Sets the user picture
     *
     * @param avat Reference to user picture
     */
     void setAvatar(const QPixmap &image);
+
     /**
     * @brief Sets the message text
     *
     * @param text Reference to user message
     */
     void setMessageText(const QString &text);
+
     /**
     * @brief Sets the time of updated message
     *
     * @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
     */
     void setUserName(const QString &name);
-private slots:
-    /**
-    * @brief Slot function to forward messageUpdate launch signal
-    *
-    */
-    void messageUpdate();
+
+private:
     /**
     * @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
-//    *
-//    */
-//    void updateFriendsStatus();
+    QString shortenText(const QLabel *label, const QString &text, int textMaxWidth);
 
-signals:
+private slots:
     /**
-    * @brief Signal to launch manual message update dialog
+    * @brief Slot function to forward messageUpdate launch signal
     *
     */
-    void launchMessageUpdate();
+    void messageUpdate();
+
+/******************************************************************************
+* SIGNALS
+******************************************************************************/
+signals:
     /**
-    * @brief Signal to refresh friends statuses
-    * @todo: Connect to friends lists when ready
+    * @brief Signal for refreshing user data.
+    *
     */
-    void launchUpdateFriendsStatus();
+    void refreshUserData();
 
+    /**
+    * @brief Signal for requesting reverseGeo from SituareEngine
+    *
+    */
     void requestReverseGeo();
 
     /**
@@ -148,70 +148,32 @@ signals:
     void reverseGeoReady(const QString &address);
 
     /**
-    * @brief Signal Signal for requestLocationUpdate from SituareEngine via MainWindow class
+    * @brief Signal for requestLocationUpdate from SituareEngine via MainWindow class
     *
     * @param status Status message
     * @param publish Publish on Facebook
     */
     void statusUpdate(const QString &status, const bool &publish);
 
-    void refreshUserData();
-
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    QPixmap m_backgroundTopImage;   ///< Top background image
-    QPixmap m_backgroundMiddleImage;   ///< Middle background image
-    QPixmap m_backgroundBottomImage;   ///< Bottom background image
-    bool m_expanded;                ///< Item expanded state
-    QLabel *m_distanceLabel;        ///< Distance to friend label
-    QLabel *m_imageLabel;           ///< Image label
-    QLabel *m_locationLabel;        ///< Location label
-    QPoint m_mousePosition;         ///< Current mouse press position
-    QLabel *m_nameLabel;            ///< Name label
-    QString m_address;
-    QString m_time;
-    QString m_messageText;
-    QPixmap m_avatar;
-    QString m_shortenedLocation;    ///< Shortened location text
-    QString m_shortenedName;        ///< Shortened name text
-    QString m_shortenedStatusText;  ///< Shortened status text
-    QString m_shortenedUpdated;     ///< Shortened updated text
-    QString m_userName;
-    QLabel *m_statusTextLabel;      ///< Status text label
-    QLabel *m_updatedLabel;         ///< Updated label
-    UpdateLocationDialog *m_locationDialog; ///< Message dialog
+    bool m_expanded;                    ///< Item expanded state
+    QLabel *m_imageLabel;               ///< Image label
+    QLabel *m_locationLabel;            ///< Location label
+    QLabel *m_nameLabel;                ///< Name label
+    QLabel *m_statusTextLabel;          ///< Status text label
+    QLabel *m_updatedLabel;             ///< Updated label
+    QPixmap m_backgroundBottomImage;    ///< Bottom background image
+    QPixmap m_backgroundMiddleImage;    ///< Middle background image
+    QPixmap m_backgroundTopImage;       ///< Top background image
+    QPoint m_mousePosition;             ///< Current mouse press position
+    QString m_address;                  ///< Address from where the new message was sent.
+    QString m_messageText;              ///< User's message
+    QString m_time;                     ///< Time when the new message was sent
+    QString m_userName;                 ///< User's name
 
 };
 
-const int BACKGROUND_TOP_HEIGHT = 20;
-const int BACKGROUND_BOTTOM_HEIGHT = 15;
-const QColor COLOR_GRAY = QColor(152, 152, 152);    ///< Gray color
-const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal);    ///< Normal font
-const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal);     ///< Small font
-const int ICON_HEIGHT = 24;     ///< Icon height
-const int ICON_WIDTH = 24;       ///< Icon width
-const int IMAGE_HEIGHT = 60; ///< Friend image height
-const int IMAGE_WIDTH = 60;  ///< Friend image width
-const int ITEM_MAX_HEIGHT = 1240; ///< Maximum height for item
-const int ITEM_MAX_WIDTH = 250;  ///< Maximum width for item
-const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
-const int ITEM_MIN_WIDTH = 250;  ///< Minimum width for item
-const int MARGIN = 5;   ///< Icon margin
-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 NAME_LABEL_MAX_WIDTH
-*
-* @brief Name label's maximum width
-*/
-const int NAME_LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH;
-/**
-* @var LABEL_MAX_WIDTH
-*
-* @brief All label's maximum width
-*/
-const int LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
-
 #endif // USERINFO_H
index b5297ac..d33634f 100644 (file)
@@ -35,7 +35,7 @@ UserInfoPanel::UserInfoPanel(QWidget *parent)
     setLayout(m_userPanelVBox);
 
     m_userInfo = new UserInfo(this);
-    m_userPanelVBox->addWidget(m_userInfo);
+    m_userPanelVBox->addWidget(m_userInfo, 0, Qt::AlignCenter);
 
     setAutoFillBackground(true);
     QPalette pal = palette();
index 7e12200..f5705cd 100644 (file)
@@ -52,7 +52,6 @@ public:
  ******************************************************************************/
 public slots:
 
-    void userDataReceived(User *user);
     /**
     * @brief Slot to redraw the panel after window resize event
     *
@@ -61,8 +60,24 @@ public slots:
     */
     void reDrawUserPanel(int width, int height);
 
+    /**
+    * @brief Slot to capture returning user data from situareService
+    *
+    * @param user
+    */
+    void userDataReceived(User *user);
+
 signals:
+    /**
+    * @brief Signal for refreshing user data.
+    *
+    */
+    void refreshUserData();
 
+    /**
+    * @brief Signal for requesting reverseGeo from SituareEngine
+    *
+    */
     void requestReverseGeo();
 
     /**
@@ -80,7 +95,6 @@ signals:
     */
     void statusUpdate(const QString &status, const bool &publish);
 
-    void refreshUserData();
 
 /*******************************************************************************
  * DATA MEMBERS