669324633ed47a6e847cacff632c57efa2471422
[situare] / src / ui / friendlistitem.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jussi Laitinen - jussi.laitinen@ixonos.com
6
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.
10
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.
15
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,
19    USA.
20 */
21
22 #include <QPainter>
23 #include <QDebug>
24 #include <QPixmap>
25
26 #include "../user/user.h"
27 #include "../common.h"
28 #include "listcommon.h"
29
30 #include "friendlistitem.h"
31
32 FriendListItem::FriendListItem()
33 {
34     qDebug() << __PRETTY_FUNCTION__;
35
36     setSubitemTextWidth(SUBITEM_TEXT_MAX_WIDTH);
37 }
38
39 FriendListItem::~FriendListItem()
40 {
41     qDebug() << __PRETTY_FUNCTION__;
42 }
43
44 GeoCoordinate FriendListItem::coordinates() const
45 {
46     qDebug() << __PRETTY_FUNCTION__;
47
48     return m_coordinates;
49 }
50
51 void FriendListItem::setAvatarImage(const QPixmap &image)
52 {
53     qDebug() << __PRETTY_FUNCTION__;
54
55     if(!image.isNull())
56         setImage(image);
57 }
58
59 void FriendListItem::setCoordinates(const GeoCoordinate &coordinates)
60 {
61     qDebug() << __PRETTY_FUNCTION__;
62
63     m_coordinates = coordinates;
64 }
65
66 void FriendListItem::setDistanceIcon(double value, const QString &unit)
67 {
68     qDebug() << __PRETTY_FUNCTION__;
69
70     const int AEROPLANE_DISTANCE = 5000;///< Aeroplane distance limit for distance icon
71     const int CAR_DISTANCE = 500;       ///< Car distance limit for distance icon
72     const int WALK_DISTANCE = 5;        ///< Walk distance limit for distance icon
73
74     QPixmap distanceImage;
75
76     if ((unit == "m") || (value < WALK_DISTANCE))
77         distanceImage.load(":/res/images/walk_icon_gray.png");
78     else if (value < CAR_DISTANCE)
79         distanceImage.load(":/res/images/car_icon_gray.png");
80     else if (value < AEROPLANE_DISTANCE)
81         distanceImage.load(":/res/images/aeroplane_icon_gray.png");
82     else
83         distanceImage.load(":/res/images/rocket_icon_gray.png");
84
85     setData(DISTANCE_IMAGE_INDEX, distanceImage);
86 }
87
88 void FriendListItem::setUserData(User *user)
89 {
90     qDebug() << __PRETTY_FUNCTION__;
91
92     QString unit;
93     double value;
94     user->distance(value, unit);
95     QString distanceText = QString::number(value) + " " + unit;
96     setData(DISTANCE_TEXT_DISPLAY_INDEX, distanceText);
97     setDistanceIcon(value, unit);
98
99     //Dummy value to get painter font metrics.
100     QPixmap p = QPixmap(ICON_WIDTH, ICON_HEIGHT);
101     QPainter painter(&p);
102     painter.setFont(NOKIA_FONT_SMALL);
103     QFontMetrics distanceTextFontMetrics = painter.fontMetrics();
104     QRect distanceRect = distanceTextFontMetrics.boundingRect(distanceText);
105
106     setData(DISTANCE_SIZE_HINT_INDEX, distanceRect);
107     QString nameTemp = QString("Pitka nimi pitka nimi pitka nimi");
108     setTitle(shortenText(nameTemp, NAME_TEXT_MAX_WIDTH - distanceRect.width() - MARGIN * 2,
109                         ListItem::TEXT_SIZE_NORMAL));
110     setCoordinates(user->coordinates());
111
112     if (!user->profileImage().isNull())
113         setImage(user->profileImage());
114
115     clearSubItems();
116
117     QString noteTemp = QString("Joillakin lehdillä on tosi tarkat rajat painon kanssa, ja emme "
118                                "menneet Playboyn pyytämiin koekuvauksiinkaan, kun he sanoivat, "
119                                "että se on ainoa mahdollisuus. Jos on esim. liian ruskettunut, "
120                                "niin he karsivat saman tien pois. Nain jälkikäteen ajatellen minua "
121                                "on jäänyt harmittamaan, ettemme menneet koekuvaukseen kun kerran "
122                                "pyydettiin! Kun Julia pääsi kyseisen lehden Grapevine-sivulle "
123                                "vuonna 2003, meille molemmille jäi kytemään ajatus jatkosta. "
124                                "Olemme ihmetelleet, miksi Suomen lehdistö sivuutti asian vain "
125                                "nopeasti. Vaikka kyseessä ei ollutkaan monen kuvan kuvasarja "
126                                "Juliasta, hän silti poseerasi varsinaisessa Playboy-lehdessä.");
127     QString noteTemp2 = QString("hei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\n"
128                                 "hei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei\nhei");
129
130     static int index = 0;
131
132 //    if (index % 2)
133         addSubItem(noteTemp, QPixmap(":/res/images/envelope.png"));
134 //    else
135 //        addSubItem(noteTemp2, QPixmap(":/res/images/envelope.png"));
136     addSubItem(user->address(), QPixmap(":/res/images/compass.png"));
137     addSubItem(user->timestamp(), QPixmap(":/res/images/clock.png"));
138
139     index++;
140 }