Added distance icons to FriendListItem.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 20 May 2010 11:34:01 +0000 (14:34 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 20 May 2010 11:34:01 +0000 (14:34 +0300)
images.qrc
src/map/frienditemshandler.cpp
src/ui/friendlistitem.cpp
src/ui/friendlistitem.h
src/ui/friendlistpanel.cpp
src/ui/friendlistview.cpp
src/ui/friendlistview.h

index 1c97969..701bd37 100644 (file)
         <file>res/images/gps_pos_accurate.png</file>
         <file>res/images/gps_pos_coarse.png</file>
         <file>res/images/friend_group.png</file>
-               <file>res/images/sight.png</file>
+        <file>res/images/sight.png</file>
+        <file>res/images/aeroplane_icon_gray.png</file>
+        <file>res/images/car_icon_gray.png</file>
+        <file>res/images/rocket_icon_gray.png</file>
+        <file>res/images/walk_icon_gray.png</file>
     </qresource>
 </RCC>
index 29b5854..d5aa9bb 100644 (file)
@@ -172,9 +172,6 @@ void FriendItemsHandler::deleteFriendItem(FriendLocationItem *item)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    disconnect(item, SIGNAL(friendItemClicked(QString)),
-            this, SIGNAL(friendItemClicked(QString)));
-
     dropFriendFromAllGroups(item);
     m_mapScene->removeItem(item);
     delete item;
index 60c82e2..ff3255b 100644 (file)
@@ -62,6 +62,10 @@ const int NAME_LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH;
 */
 const int LABEL_MAX_WIDTH = ITEM_MIN_WIDTH - 3*MARGIN - IMAGE_WIDTH - MARGIN - ICON_WIDTH;
 
+const int WALK_DISTANCE = 5;        ///< Walk distance limit for distance icon
+const int CAR_DISTANCE = 500;       ///< Car distance limit for distance icon
+const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
+
 FriendListItem::FriendListItem(QWidget *parent)
     : QWidget(parent)
     , m_expanded(false)
@@ -78,6 +82,10 @@ FriendListItem::FriendListItem(QWidget *parent)
     topLayout->setMargin(0);
     topLayout->setSpacing(0);
 
+    QVBoxLayout *distanceLayout = new QVBoxLayout();
+    distanceLayout->setMargin(0);
+    distanceLayout->setSpacing(0);
+
     QHBoxLayout *bottomLayout = new QHBoxLayout();
     bottomLayout->setMargin(0);
     bottomLayout->setSpacing(0);
@@ -106,8 +114,11 @@ FriendListItem::FriendListItem(QWidget *parent)
     m_nameLabel = new QLabel();
     m_nameLabel->setFixedHeight(IMAGE_HEIGHT);
 
-    m_distanceLabel = new QLabel();
-    m_distanceLabel->setFixedHeight(IMAGE_HEIGHT);
+    m_distanceTextLabel = new QLabel();
+    m_distanceTextLabel->setFixedHeight(ICON_HEIGHT);
+
+    m_distanceImageLabel = new QLabel();
+    m_distanceImageLabel->setFixedSize(ICON_WIDTH, ICON_HEIGHT);
 
     m_findButton = new ImageButton(this, ":/res/images/show_position.png",
                                    ":/res/images/show_position_s.png");
@@ -119,13 +130,16 @@ FriendListItem::FriendListItem(QWidget *parent)
     m_locationLabel = new QLabel();
     m_locationLabel->setWordWrap(true);
 
+    distanceLayout->addWidget(m_distanceImageLabel, 0, Qt::AlignRight);
+    distanceLayout->addWidget(m_distanceTextLabel, 0, Qt::AlignRight);
+
     infoLayout->addRow(envelopeLabel, m_statusTextLabel);
     infoLayout->addRow(compassLabel, m_locationLabel);
     infoLayout->addRow(clockLabel, m_updatedLabel);
 
     topLayout->addWidget(m_imageLabel);
     topLayout->addWidget(m_nameLabel, 1);
-    topLayout->addWidget(m_distanceLabel);
+    topLayout->addLayout(distanceLayout);
 
     bottomLayout->addWidget(m_findButton, 0, Qt::AlignTop);
     bottomLayout->addLayout(infoLayout);
@@ -164,12 +178,29 @@ void FriendListItem::setData(User *user)
     QString unit;
     double value;
     user->distance(value, unit);
-    m_distanceLabel->setText(QString::number(value) + " " + unit);
+    m_distanceTextLabel->setText(QString::number(value) + " " + unit);
+    setDistanceIcon(value);
 
     shortenTexts();
     setText(false);
 }
 
+void FriendListItem::setDistanceIcon(double value)
+{
+    QPixmap distanceImage;
+
+    if (value < WALK_DISTANCE)
+        distanceImage.load(":/res/images/walk_icon_gray.png");
+    else if (value < CAR_DISTANCE)
+        distanceImage.load(":/res/images/car_icon_gray.png");
+    else if (value < AEROPLANE_DISTANCE)
+        distanceImage.load(":/res/images/aeroplane_icon_gray.png");
+    else
+        distanceImage.load(":/res/images/rocket_icon_gray.png");
+
+    m_distanceImageLabel->setPixmap(distanceImage);
+}
+
 void FriendListItem::shortenTexts()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -204,7 +235,7 @@ void FriendListItem::shortenTexts()
         location.append("...");
     }
 
-    int distanceLabelWidth = otherLabelsMetrics.width(m_distanceLabel->text());
+    int distanceLabelWidth = otherLabelsMetrics.width(m_distanceTextLabel->text());
     m_shortenedName = nameLabelMetrics.elidedText(name, Qt::ElideRight, NAME_LABEL_MAX_WIDTH
                                                   - distanceLabelWidth);
     m_shortenedUpdated = otherLabelsMetrics.elidedText(updated, Qt::ElideRight, LABEL_MAX_WIDTH);
index 2c6c3a6..8c63eda 100644 (file)
@@ -89,11 +89,13 @@ public:
 
 private:
     /**
-    * @brief Set shortened texts from User data.
+    * @brief Set distance icon.
     *
-    * Text length is defined by MAXIMUM_CHARS.
+    * Icon is selected by distance.
+    *
+    * @param value distance value
     */
-    void shortenTexts();
+    void setDistanceIcon(double value);
 
     /**
     * @brief Set shortened or full-length text to labels.
@@ -102,6 +104,13 @@ private:
     */
     void setText(bool expanded);
 
+    /**
+    * @brief Set shortened texts from User data.
+    *
+    * Text length is defined by MAXIMUM_CHARS.
+    */
+    void shortenTexts();
+
 private slots:
     /**
     * @brief Slot for find button click
@@ -127,7 +136,8 @@ private:
     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_distanceImageLabel;   ///< Distance image for friend label
+    QLabel *m_distanceTextLabel;    ///< Distance text for friend label
     ImageButton *m_findButton;      ///< Friend find button
     QLabel *m_imageLabel;           ///< Image label
     QLabel *m_locationLabel;        ///< Location label
index 69e8694..92e5421 100644 (file)
@@ -96,7 +96,7 @@ void FriendListPanel::friendInfoReceived(QList<User *> &friendList)
         FriendListItem *item = new FriendListItem(m_friendListView);
         item->setData(user);
         m_friendListView->addWidget(user->userId(), item);
-
+        qDebug() << __PRETTY_FUNCTION__ << user->userId();
         connect(item, SIGNAL(findFriend(QPointF)),
             this, SIGNAL(findFriend(QPointF)));
     }
index 36c7cc3..fe7dd86 100644 (file)
@@ -62,7 +62,7 @@ void FriendListView::clear()
     widgets.clear();
 }
 
-void FriendListView::filter(const QList<QString> userIDs)
+void FriendListView::filter(const QList<QString> &userIDs)
 {
     foreach (QWidget *widget, widgets)
         widget->hide();
index 6dd26b8..af8ea28 100644 (file)
@@ -77,7 +77,7 @@ public:
     *
     * @param userIDs user ID's to widgets that are shown
     */
-    void filter(const QList<QString> userIDs);
+    void filter(const QList<QString> &userIDs);
 
 /******************************************************************************
 * DATA MEMBERS