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 const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
33 const int CAR_DISTANCE = 500; ///< Car distance limit for distance icon
34 const int WALK_DISTANCE = 5; ///< Walk distance limit for distance icon
36 FriendListItem::FriendListItem()
38 qDebug() << __PRETTY_FUNCTION__;
40 setSubitemTextWidth(SUBITEM_TEXT_MAX_WIDTH);
43 GeoCoordinate FriendListItem::coordinates()
45 qDebug() << __PRETTY_FUNCTION__;
50 void FriendListItem::setUserData(User *user)
52 qDebug() << __PRETTY_FUNCTION__;
58 user->distance(value, unit);
59 QString distanceText = QString::number(value) + " " + unit;
60 setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
61 setDistanceIcon(value, unit);
63 //Dummy value to get painter font metrics.
64 QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
66 painter.setFont(NOKIA_FONT_SMALL);
67 QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
68 QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
70 setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
71 setName(shortenText(user->name(), NAME_TEXT_MAX_WIDTH - distanceRect.width() + MARGIN,
72 ListItem::TEXT_SIZE_NORMAL));
73 setCoordinates(user->coordinates());
75 if (!user->profileImage().isNull())
76 setImage(user->profileImage());
80 addSubItem(user->note(), QPixmap(":/res/images/envelope.png"));
81 addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
82 addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));
86 void FriendListItem::setAvatarImage(const QPixmap &image)
88 qDebug() << __PRETTY_FUNCTION__;
94 void FriendListItem::setCoordinates(const GeoCoordinate &coordinates)
96 qDebug() << __PRETTY_FUNCTION__;
98 m_coordinates = coordinates;
101 void FriendListItem::setDistanceIcon(double value, const QString &unit)
103 qDebug() << __PRETTY_FUNCTION__;
105 QPixmap distanceImage;
107 if ((unit == "m") || (value < WALK_DISTANCE))
108 distanceImage.load(":/res/images/walk_icon_gray.png");
109 else if (value < CAR_DISTANCE)
110 distanceImage.load(":/res/images/car_icon_gray.png");
111 else if (value < AEROPLANE_DISTANCE)
112 distanceImage.load(":/res/images/aeroplane_icon_gray.png");
114 distanceImage.load(":/res/images/rocket_icon_gray.png");
116 setData(DISTANCE_IMAGE_INDEX, distanceImage);
119 FriendListItem::~FriendListItem()
121 qDebug() << __PRETTY_FUNCTION__;