From 46174265c34b22ec6a5458d0f7beccb9d72bbbc5 Mon Sep 17 00:00:00 2001 From: Jussi Laitinen Date: Thu, 20 May 2010 14:34:01 +0300 Subject: [PATCH] Added distance icons to FriendListItem. --- images.qrc | 6 +++++- src/map/frienditemshandler.cpp | 3 --- src/ui/friendlistitem.cpp | 41 +++++++++++++++++++++++++++++++++++----- src/ui/friendlistitem.h | 18 ++++++++++++++---- src/ui/friendlistpanel.cpp | 2 +- src/ui/friendlistview.cpp | 2 +- src/ui/friendlistview.h | 2 +- 7 files changed, 58 insertions(+), 16 deletions(-) diff --git a/images.qrc b/images.qrc index 1c97969..701bd37 100644 --- a/images.qrc +++ b/images.qrc @@ -31,6 +31,10 @@ res/images/gps_pos_accurate.png res/images/gps_pos_coarse.png res/images/friend_group.png - res/images/sight.png + res/images/sight.png + res/images/aeroplane_icon_gray.png + res/images/car_icon_gray.png + res/images/rocket_icon_gray.png + res/images/walk_icon_gray.png diff --git a/src/map/frienditemshandler.cpp b/src/map/frienditemshandler.cpp index 29b5854..d5aa9bb 100644 --- a/src/map/frienditemshandler.cpp +++ b/src/map/frienditemshandler.cpp @@ -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; diff --git a/src/ui/friendlistitem.cpp b/src/ui/friendlistitem.cpp index 60c82e2..ff3255b 100644 --- a/src/ui/friendlistitem.cpp +++ b/src/ui/friendlistitem.cpp @@ -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); diff --git a/src/ui/friendlistitem.h b/src/ui/friendlistitem.h index 2c6c3a6..8c63eda 100644 --- a/src/ui/friendlistitem.h +++ b/src/ui/friendlistitem.h @@ -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 diff --git a/src/ui/friendlistpanel.cpp b/src/ui/friendlistpanel.cpp index 69e8694..92e5421 100644 --- a/src/ui/friendlistpanel.cpp +++ b/src/ui/friendlistpanel.cpp @@ -96,7 +96,7 @@ void FriendListPanel::friendInfoReceived(QList &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))); } diff --git a/src/ui/friendlistview.cpp b/src/ui/friendlistview.cpp index 36c7cc3..fe7dd86 100644 --- a/src/ui/friendlistview.cpp +++ b/src/ui/friendlistview.cpp @@ -62,7 +62,7 @@ void FriendListView::clear() widgets.clear(); } -void FriendListView::filter(const QList userIDs) +void FriendListView::filter(const QList &userIDs) { foreach (QWidget *widget, widgets) widget->hide(); diff --git a/src/ui/friendlistview.h b/src/ui/friendlistview.h index 6dd26b8..af8ea28 100644 --- a/src/ui/friendlistview.h +++ b/src/ui/friendlistview.h @@ -77,7 +77,7 @@ public: * * @param userIDs user ID's to widgets that are shown */ - void filter(const QList userIDs); + void filter(const QList &userIDs); /****************************************************************************** * DATA MEMBERS -- 1.7.9.5