Modified friendlistitem and friendlistview after review.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 3 May 2010 11:43:57 +0000 (14:43 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Mon, 3 May 2010 11:43:57 +0000 (14:43 +0300)
src/engine/engine.cpp
src/src.pro
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistview.cpp
src/ui/infotab.cpp
src/ui/listviewscreen.cpp
src/ui/situareuser.cpp

index d09683c..c3e0132 100644 (file)
@@ -49,7 +49,7 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)), m_ui,
             SIGNAL(userDataChanged(User*,QList<User*>&)));
 
-    connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)), m_ui,
+    connect(m_situareService, SIGNAL(userDataChanged(User*,QList<User*>&)), this,
             SLOT(userDataReceived(User*,QList<User*>&)));
 
     connect(m_ui, SIGNAL(refreshUserData()), this, SLOT(refreshUserData()));
index 0d8012e..e72cb3d 100644 (file)
@@ -67,8 +67,6 @@ HEADERS += ui/mainwindow.h \
 QT += network \
     webkit
 
-DEFINES += QT_NO_DEBUG_OUTPUT
-
 !maemo5 { 
     message(QJson built in)
     message(Make sure you have QJson development headers installed)
index 4efa61d..cac8d4c 100644 (file)
 #include "friendlistitem.h"
 #include "../user/user.h"
 
+const QString BACKGROUND_PATH = ":/res/images/list_item.png";   ///< Background image path
+const QString CLOCK_PATH = ":/res/images/clock.png";        ///< Clock image path
+const QString COMPASS_PATH = ":/res/images/compass.png";    ///< Compass image path
+const QString ENVELOPE_PATH = ":/res/images/envelope.png";  ///< Envelope image path
+
+const int ICON_MARGIN = 5;   ///< Icon margin
+const int IMAGE_HEIGHT = 60; ///< Friend image height
+const int IMAGE_WIDTH = 60;  ///< Friend image width
+
+const int ITEM_MAX_HEIGHT = 240; ///< Maximum height for item
+const int ITEM_MAX_WIDTH = 368;  ///< Maximum width for item
+const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
+const int ITEM_MIN_WIDTH = 368;  ///< Minimum width for item
+const int LABEL_MAX_WIDTH = 350;   ///< Label maximum width
+
 FriendListItem::FriendListItem(QWidget *parent)
     : QWidget(parent)
     , m_expanded(false)
+    , m_user(0)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     QVBoxLayout *layout = new QVBoxLayout(this);
     this->setLayout(layout);
 
@@ -46,32 +64,30 @@ FriendListItem::FriendListItem(QWidget *parent)
     QHBoxLayout *bottomLayout = new QHBoxLayout();
     bottomLayout->setMargin(0);
     bottomLayout->setSpacing(0);
-    m_infoWidget = new QWidget(this);
 
     QFormLayout *infoLayout = new QFormLayout();
     infoLayout->setMargin(0);
     infoLayout->setSpacing(0);
-    m_infoWidget->setLayout(infoLayout);
 
-    QLabel *clockLabel = new QLabel(this);
+    QLabel *clockLabel = new QLabel();
     clockLabel->setPixmap(QPixmap(CLOCK_PATH));
     clockLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
-    QLabel *envelopeLabel = new QLabel(this);
+    QLabel *envelopeLabel = new QLabel();
     envelopeLabel->setPixmap(QPixmap(ENVELOPE_PATH));
     envelopeLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
-    QLabel *compassLabel = new QLabel(this);
+    QLabel *compassLabel = new QLabel();
     compassLabel->setPixmap(QPixmap(COMPASS_PATH));
     compassLabel->setContentsMargins(0, 0, ICON_MARGIN, 0);
 
-    m_imageLabel = new QLabel(this);
+    m_imageLabel = new QLabel();
     m_imageLabel->setFixedSize(IMAGE_WIDTH, IMAGE_HEIGHT);
-    m_nameLabel = new QLabel("", this);
+    m_nameLabel = new QLabel();
     m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
-    m_updatedLabel = new QLabel("", this);
+    m_updatedLabel = new QLabel();
     m_updatedLabel->setWordWrap(true);
-    m_statusTextLabel = new QLabel("", this);
+    m_statusTextLabel = new QLabel();
     m_statusTextLabel->setWordWrap(true);
-    m_locationLabel = new QLabel("", this);
+    m_locationLabel = new QLabel();
     m_locationLabel->setWordWrap(true);
 
     infoLayout->addRow(clockLabel, m_updatedLabel);
@@ -81,88 +97,73 @@ FriendListItem::FriendListItem(QWidget *parent)
     topLayout->addWidget(m_imageLabel);
     topLayout->addWidget(m_nameLabel);
 
-    bottomLayout->addSpacerItem(new QSpacerItem(IMAGE_WIDTH, IMAGE_HEIGHT));
-    bottomLayout->addWidget(m_infoWidget, 1);
+    bottomLayout->addSpacing(IMAGE_WIDTH);
+    bottomLayout->addLayout(infoLayout, 1);
 
     layout->addLayout(topLayout, 0);
     layout->addLayout(bottomLayout, 1);
 
-    this->setObjectName("listItem");
-    m_infoWidget->setObjectName("infoWidget");
+    setObjectName("listItem");
     m_nameLabel->setObjectName("nameLabel");
 
-    this->setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
+    setStyleSheet("#listItem { border-image: url(:/res/images/list_item.png) 20%; " \
                         "border-width: 20px 14px 16px 14px; } " \
                         "QLabel { font-size: 13pt; color: #989898; }" \
                         "#nameLabel { font-size: 18pt; color: #ffffff }");
 
-    this->setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
-    this->setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
+    setMinimumSize(ITEM_MIN_WIDTH, ITEM_MIN_HEIGHT);
+    setMaximumSize(ITEM_MAX_WIDTH, ITEM_MAX_HEIGHT);
 }
 
-void FriendListItem::setData(const User &user)
+void FriendListItem::setData(User *user)
 {
-    m_user = user;
-
-    shortenTexts();
+    qDebug() << __PRETTY_FUNCTION__;
 
-    m_imageLabel->setPixmap(m_user.profileImage());
-    m_nameLabel->setText(m_shortenedName);
-    m_updatedLabel->setText(m_shortenedUpdated);
-    m_statusTextLabel->setText(m_shortenedStatusText);
-    m_locationLabel->setText(m_shortenedLocation);
+    if (user) {
+        m_user = user;
+        shortenTexts();
 
+        m_imageLabel->setPixmap(m_user->profileImage());
+        setText(false);
+    }
 }
 
 void FriendListItem::shortenTexts()
 {
-    if (m_user.name().length() > MAXIMUM_CHARS) {
-        m_shortenedName = m_user.name().left(MAXIMUM_CHARS-3).append("...");
-    }
-    else {
-         m_shortenedName = m_user.name();
-    }
-    if (m_user.timestamp().length() > MAXIMUM_CHARS) {
-        m_shortenedUpdated = m_user.timestamp().left(MAXIMUM_CHARS-3).append("...");
-    }
-    else {
-        m_shortenedUpdated = m_user.timestamp();
-    }
-    if (m_user.note().length() > MAXIMUM_CHARS) {
-        m_shortenedStatusText = m_user.note().left(MAXIMUM_CHARS-3).append("...");
-    }
-    else {
-        m_shortenedStatusText = m_user.note();
-    }
-    if (m_user.address().length() > MAXIMUM_CHARS) {
-        m_shortenedLocation = m_user.address().left(MAXIMUM_CHARS-3).append("...");
-    }
-    else {
-        m_shortenedLocation = m_user.address();
-    }
+    qDebug() << __PRETTY_FUNCTION__ << m_user->address().length();
+
+    m_shortenedName = m_nameLabel->fontMetrics()
+                      .elidedText(m_user->name(), Qt::ElideRight, LABEL_MAX_WIDTH);
+    m_shortenedUpdated = m_updatedLabel->fontMetrics()
+                         .elidedText(m_user->timestamp(), Qt::ElideRight, LABEL_MAX_WIDTH);
+    m_shortenedStatusText = m_statusTextLabel->fontMetrics()
+                            .elidedText(m_user->note(), Qt::ElideRight, LABEL_MAX_WIDTH);
+    m_shortenedLocation = m_locationLabel->fontMetrics()
+                          .elidedText(m_user->address(), Qt::ElideRight, LABEL_MAX_WIDTH);
 }
 
-void FriendListItem::toggleHeight()
+void FriendListItem::setText(bool expanded)
 {
-    if (m_expanded) {
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (expanded) {
+        m_nameLabel->setText(m_user->name());
+        m_updatedLabel->setText(m_user->timestamp());
+        m_statusTextLabel->setText(m_user->note());
+        m_locationLabel->setText(m_user->address());
+    }
+    else {
         m_nameLabel->setText(m_shortenedName);
         m_updatedLabel->setText(m_shortenedUpdated);
         m_statusTextLabel->setText(m_shortenedStatusText);
         m_locationLabel->setText(m_shortenedLocation);
-        m_expanded = false;
-
-    }
-    else {
-        m_nameLabel->setText(m_user.name());
-        m_updatedLabel->setText(m_user.timestamp());
-        m_statusTextLabel->setText(m_user.note());
-        m_locationLabel->setText(m_user.address());
-        m_expanded = true;
     }
 }
 
 void FriendListItem::mousePressEvent(QMouseEvent *event)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_mousePosition = event->pos();
 }
 
@@ -170,12 +171,22 @@ void FriendListItem::mouseReleaseEvent(QMouseEvent *event)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (event->pos() == m_mousePosition)
-        toggleHeight();
+    if (event->pos() == m_mousePosition) {
+        if (m_expanded) {
+            setText(false);
+            m_expanded = false;
+        }
+        else {
+            setText(true);
+            m_expanded = true;
+        }
+    }
 }
 
 void FriendListItem::paintEvent(QPaintEvent *)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     QStyleOption option;
     option.init(this);
 
index 404fa4f..8019d3a 100644 (file)
@@ -27,6 +27,7 @@
 #include <QListWidgetItem>
 
 #include "../user/user.h"
+#include "situareuser.h"
 
 class QLabel;
 
@@ -82,9 +83,9 @@ public:
     /**
     * @brief Set data for this item.
     *
-    * @param user User object
+    * @param user User pointer
     */
-    void setData(const User &user);
+    void setData(User *user);
 
 private:
     /**
@@ -95,28 +96,18 @@ private:
     void shortenTexts();
 
     /**
-    * @brief Toggle item height.
+    * @brief Set shortened or full-length text to labels.
+    *
+    * @param expanded true if full-length text is set, false otherwise
     */
-    void toggleHeight();
+    void setText(bool expanded);
 
 /******************************************************************************
 * DATA MEMBERS
 ******************************************************************************/
 private:
-    static const int ICON_MARGIN = 5;   ///< Icon margin
-    static const int IMAGE_HEIGHT = 60; ///< Friend image height
-    static const int IMAGE_WIDTH = 60;  ///< Friend image width
-
-    static const int ITEM_MAX_HEIGHT = 240; ///< Maximum height for item
-    static const int ITEM_MAX_WIDTH = 368;  ///< Maximum width for item
-    static const int ITEM_MIN_HEIGHT = 141; ///< Minimum height for item
-    static const int ITEM_MIN_WIDTH = 368;  ///< Minimum width for item
-
-    static const int MAXIMUM_CHARS = 32;    ///< Maximum character count for labels
-
     bool m_expanded;                ///< Item expanded state
     QLabel *m_imageLabel;           ///< Image label
-    QWidget *m_infoWidget;          ///< Info widget: updated, status text, location
     QLabel *m_locationLabel;        ///< Location label
     QPoint m_mousePosition;         ///< Current mouse press position
     QLabel *m_nameLabel;            ///< Name label
@@ -127,12 +118,7 @@ private:
     QLabel *m_statusTextLabel;      ///< Status text label
     QLabel *m_updatedLabel;         ///< Updated label
 
-    User m_user;                    ///< User data
+    User *m_user;                    ///< User data
 };
 
-const QString BACKGROUND_PATH = ":/res/images/list_item.png";   ///< Background image path
-const QString CLOCK_PATH = ":/res/images/clock.png";        ///< Clock image path
-const QString ENVELOPE_PATH = ":/res/images/envelope.png";  ///< Envelope image path
-const QString COMPASS_PATH = ":/res/images/compass.png";    ///< Compass image path
-
 #endif // FRIENDLISTITEM_H
index 5338848..cf57111 100644 (file)
@@ -28,6 +28,8 @@
 FriendListView::FriendListView(QWidget *parent)
     : QWidget(parent)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_friendListLayout = new QVBoxLayout(this);
     m_friendListLayout->setMargin(0);
     m_friendListLayout->setSpacing(0);
index 7391ef5..dba51b5 100644 (file)
@@ -34,7 +34,7 @@ const int GRADIENT_STOP_R = 82;
 const int GRADIENT_STOP_G = 73;
 const int GRADIENT_STOP_B = 74;
 const int ROUNDNESS = 9;
-const int SIZE_X = 280;
+const int SIZE_X = 320;
 const int SIZE_Y = 280;
 const int BIG_FONT = 18;
 const int SMALL_FONT = 13;
@@ -49,8 +49,6 @@ InfoTab::InfoTab(QWidget *parent)
     horizontalLayout = new QHBoxLayout(widget);
     m_layout = new QGridLayout(widget);
     situUser = new SituareUser(widget);
-    situUser->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
-    situUser->setMargin(1);
 
     //Tex color settings
     QPalette textPalette;
@@ -104,42 +102,52 @@ InfoTab::InfoTab(QWidget *parent)
 
     connect(updateStatusMessageButton,SIGNAL(clicked()),this,SLOT(messageUpdate()));
     connect(updateFriendsButton,SIGNAL(clicked()),this,SLOT(updateFriendsStatus()));
+
+    widget->setObjectName("infoTab");
+    widget->setStyleSheet(QString("#infoTab { border-image: url(:/res/images/list_item.png) 20%; " \
+                                  "border-width: 20px 14px 16px 14px; }"));
 }
 
 void InfoTab::paintEvent(QPaintEvent *aPaintEvent)
 {
     Q_UNUSED(aPaintEvent);
 
-    QRect widgetRect = this->rect();
-
-    //Gradient
-    QLinearGradient linearGrad(QPointF(widgetRect.height(), widgetRect.width()/2),
-                               QPointF(widgetRect.width()/2,0));
-    linearGrad.setColorAt(0, QColor::fromRgb(GRADIENT_START_R,GRADIENT_START_G,GRADIENT_START_B));
-    linearGrad.setColorAt(1, QColor::fromRgb(GRADIENT_STOP_R,GRADIENT_STOP_G,GRADIENT_STOP_B));
-
-    //Look and feel settings
-    QPalette qpalette;
-    QBrush brush(linearGrad);
-    qpalette.setBrush(QPalette::Window,brush);
-    setPalette(qpalette);
+//    QRect widgetRect = this->rect();
+//
+//    //Gradient
+//    QLinearGradient linearGrad(QPointF(widgetRect.height(), widgetRect.width()/2),
+//                               QPointF(widgetRect.width()/2,0));
+//    linearGrad.setColorAt(0, QColor::fromRgb(GRADIENT_START_R,GRADIENT_START_G,GRADIENT_START_B));
+//    linearGrad.setColorAt(1, QColor::fromRgb(GRADIENT_STOP_R,GRADIENT_STOP_G,GRADIENT_STOP_B));
+//
+//    //Look and feel settings
+//    QPalette qpalette;
+//    QBrush brush(linearGrad);
+//    qpalette.setBrush(QPalette::Window,brush);
+//    setPalette(qpalette);
+//
+//    QPainter painter(this);
+//
+//    painter.save();
+//
+//    painter.setRenderHint(QPainter::Antialiasing);
+//    QPainterPath roundedRect;
+//    roundedRect.addRoundedRect(1,1,widgetRect.width()-RECT_WIDTH_OFFSET,
+//                               widgetRect.height()-RECT_HEIGHT_OFFSET,ROUNDNESS,ROUNDNESS);
+//
+//    painter.setClipPath(roundedRect);
+//    QRegion maskRegion = painter.clipRegion();
+//
+//    setMask(maskRegion);
+//
+//    painter.fillPath(roundedRect,QBrush(brush));
+//    painter.restore();
+
+    QStyleOption option;
+    option.init(this);
 
     QPainter painter(this);
-
-    painter.save();
-
-    painter.setRenderHint(QPainter::Antialiasing);
-    QPainterPath roundedRect;
-    roundedRect.addRoundedRect(1,1,widgetRect.width()-RECT_WIDTH_OFFSET,
-                               widgetRect.height()-RECT_HEIGHT_OFFSET,ROUNDNESS,ROUNDNESS);
-
-    painter.setClipPath(roundedRect);
-    QRegion maskRegion = painter.clipRegion();
-
-    setMask(maskRegion);
-
-    painter.fillPath(roundedRect,QBrush(brush));
-    painter.restore();
+    style()->drawPrimitive(QStyle::PE_Widget, &option, &painter, this);
 }
 
 QSize InfoTab::sizeHint() const
index 193abbf..f8ef85f 100644 (file)
@@ -246,7 +246,7 @@ void ListViewScreen::userDataChanged(User *user, QList<User *> &friends)
 
     foreach (User *user, friends) {
         FriendListItem *item = new FriendListItem(m_friendListView);
-        item->setData(*user);
+        item->setData(user);
         m_friendListView->addWidget(item);
     }
 }
index 38d8ea2..830f879 100644 (file)
 #include <QPainter>
 #include <QDebug>
 
-const int BORDER_X_OFFSET = 6;
-const int BORDER_Y_OFFSET = 6;
-const int RECT_WIDTH_OFFSET = 2;
-const int RECT_HEIGHT_OFFSET = 2;
+const int BORDER_X_OFFSET = 7;
+const int BORDER_Y_OFFSET = 7;
+const int RECT_WIDTH_OFFSET = 1;
+const int RECT_HEIGHT_OFFSET = 1;
 const int ROUNDNESS = 9;
 const int PIC_SIZE_X = 50;
 const int PIC_SIZE_Y = 50;
@@ -34,6 +34,8 @@ const int PIC_SIZE_Y = 50;
 SituareUser::SituareUser(QWidget *parent)
     : QLabel(parent)
 {
+    this->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
+    this->setMargin(1);
 }
 
 
@@ -41,7 +43,7 @@ void SituareUser::paintEvent(QPaintEvent *aPaintEvent)
 {
     Q_UNUSED(aPaintEvent);
 
-    int roundness(9);
+    int roundness(ROUNDNESS);
 
     QRect widgetRect = QRect(0,0,this->pixmap()->width(),this->pixmap()->height());
 
@@ -57,14 +59,16 @@ void SituareUser::paintEvent(QPaintEvent *aPaintEvent)
 
     setMask(maskRegion);
 
-    painter.drawPixmap(QPointF(0,0),(*(this->pixmap())));
+    painter.drawPixmap(QPointF(0, 0), (*(this->pixmap())));
     clearMask();
+
     painter.drawPixmap(QPointF(-BORDER_X_OFFSET,-BORDER_Y_OFFSET),
                        (QPixmap(":/res/images/profile_pic_border.png")));
+
     painter.restore();
 }
 
 QSize SituareUser::sizeHint() const
 {
-    return QSize(PIC_SIZE_X,PIC_SIZE_Y);
+    return QSize(PIC_SIZE_X, PIC_SIZE_Y);
 }