Updated changelog
[situare] / src / map / friendlocationitem.cpp
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Ville Tiensuu - ville.tiensuu@ixonos.com
6        Sami Rämö - sami.ramo@ixonos.com
7
8    Situare is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License
10    version 2 as published by the Free Software Foundation.
11
12    Situare is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with Situare; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
20    USA.
21 */
22
23 #include <QDebug>
24 #include <QGraphicsSceneMouseEvent>
25 #include <QIcon>
26 #include "friendlocationitem.h"
27 #include "mapcommon.h"
28
29 FriendLocationItem::FriendLocationItem(const QString &userId,
30                                        QObject *parent)
31     : BaseLocationItem(parent),
32       m_partOfGroup(false),
33       m_userId(userId),
34       m_mousePressPosition(QPoint(0, 0)),
35       m_clickEvent(false)
36 {
37     qDebug() << __PRETTY_FUNCTION__;
38
39     setPos(UNDEFINED, UNDEFINED);
40     setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
41 }
42
43 bool FriendLocationItem::isPartOfGroup() const
44 {
45     return m_partOfGroup;
46 }
47
48 void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
49 {
50     qDebug() << __PRETTY_FUNCTION__;
51
52     m_mousePressPosition = event->pos();
53     m_clickEvent = true;
54     update();
55 }
56
57 void FriendLocationItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
58 {
59     qDebug() << __PRETTY_FUNCTION__;
60
61     if (m_clickEvent) {
62         if ((event->pos() - m_mousePressPosition).manhattanLength() > PRESS_MANHATTAN_LENGTH) {
63             m_clickEvent = false;
64             update();
65         }
66     }
67 }
68
69 void FriendLocationItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
70 {
71     qDebug() << __PRETTY_FUNCTION__;
72
73     Q_UNUSED(event);
74
75     if (m_clickEvent) {
76         m_clickEvent = false;
77         QList<QString> userIDs;
78         userIDs.append(m_userId);
79
80         emit locationItemClicked(userIDs);
81     }
82
83     update();
84 }
85
86 void FriendLocationItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
87                                QWidget *widget)
88 {
89     qDebug() << __PRETTY_FUNCTION__;
90
91     if (m_clickEvent) {
92         QIcon icon;
93         icon.addPixmap(pixmap());
94         painter->drawPixmap(offset(), icon.pixmap(pixmap().size(), QIcon::Selected,
95                                                                  QIcon::On));
96     }
97     else {
98         BaseLocationItem::paint(painter, option, widget);
99     }
100 }
101
102 void FriendLocationItem::setPartOfGroup(bool value)
103 {
104     m_partOfGroup = value;
105
106     if (value)
107         hide();
108     else
109         show();
110 }
111
112 QString FriendLocationItem::userId() const
113 {
114     qDebug() << __PRETTY_FUNCTION__;
115     return m_userId;
116 }
117
118 void FriendLocationItem::setProfileImage(const QPixmap image, const QUrl &url)
119 {
120     qDebug() << __PRETTY_FUNCTION__;
121
122     setPixmap(image);
123     setOffset(-image.width()/2, -image.height()/2);
124     m_profileImageUrl = url;
125 }
126
127 QUrl FriendLocationItem::profileImageUrl() const
128 {
129     qDebug() << __PRETTY_FUNCTION__;
130     return m_profileImageUrl;
131 }
132