2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Jussi Laitinen - jussi.laitinen@ixonos.com
7 Situare is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 version 2 as published by the Free Software Foundation.
11 Situare is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Situare; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include "../user/user.h"
27 #include "../common.h"
28 #include "listcommon.h"
30 #include "friendlistitem.h"
32 FriendListItem::FriendListItem()
34 qDebug() << __PRETTY_FUNCTION__;
36 setSubitemTextWidth(SUBITEM_TEXT_MAX_WIDTH);
39 FriendListItem::~FriendListItem()
41 qDebug() << __PRETTY_FUNCTION__;
44 GeoCoordinate FriendListItem::coordinates() const
46 qDebug() << __PRETTY_FUNCTION__;
51 QString FriendListItem::facebookId() const
56 void FriendListItem::setAvatarImage(const QPixmap &image)
58 qDebug() << __PRETTY_FUNCTION__;
64 void FriendListItem::setCoordinates(const GeoCoordinate &coordinates)
66 qDebug() << __PRETTY_FUNCTION__;
68 m_coordinates = coordinates;
71 void FriendListItem::setDistanceIcon(double value, const QString &unit)
73 qDebug() << __PRETTY_FUNCTION__;
75 const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
76 const int CAR_DISTANCE = 500; ///< Car distance limit for distance icon
77 const int WALK_DISTANCE = 5; ///< Walk distance limit for distance icon
79 QPixmap distanceImage;
81 if ((unit == "m") || (value < WALK_DISTANCE))
82 distanceImage.load(":/res/images/walk_icon_gray.png");
83 else if (value < CAR_DISTANCE)
84 distanceImage.load(":/res/images/car_icon_gray.png");
85 else if (value < AEROPLANE_DISTANCE)
86 distanceImage.load(":/res/images/aeroplane_icon_gray.png");
88 distanceImage.load(":/res/images/rocket_icon_gray.png");
90 setData(DISTANCE_IMAGE_INDEX, distanceImage);
94 void FriendListItem::setFacebookId(const QString &facebookId)
96 qDebug() << __PRETTY_FUNCTION__;
98 m_facebookId = facebookId;
100 void FriendListItem::setUserData(User *user)
102 qDebug() << __PRETTY_FUNCTION__;
106 user->distance(value, unit);
107 QString distanceText = QString::number(value) + " " + unit;
108 setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
109 setDistanceIcon(value, unit);
111 setFacebookId(user->userId());
113 //Dummy value to get painter font metrics.
114 QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
115 QPainter painter(&p);
116 painter.setFont(NOKIA_FONT_SMALL);
117 QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
118 QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
120 setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
121 setTitle(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() - MARGIN * 2,
122 ListItem::TEXT_SIZE_NORMAL));
123 setCoordinates(user->coordinates());
125 if (!user->profileImage().isNull())
126 setImage(user->profileImage());
130 addSubItem(user->note(), QPixmap(":/res/images/envelope.png"));
131 addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
132 addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));