Fixed bug #5867.
[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 "friendlocationitem.h"
26 #include "mapcommon.h"
27
28 FriendLocationItem::FriendLocationItem(const QString &userId,
29                                        QObject *parent)
30     : BaseLocationItem(parent),
31       m_partOfGroup(false),
32       m_userId(userId),
33       m_mousePressPosition(QPoint(0, 0)),
34       m_clickEvent(false)
35 {
36     qDebug() << __PRETTY_FUNCTION__;
37
38     setPos(UNDEFINED, UNDEFINED);
39     setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
40 }
41
42 bool FriendLocationItem::isPartOfGroup() const
43 {
44     return m_partOfGroup;
45 }
46
47 void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
48 {
49     qDebug() << __PRETTY_FUNCTION__;
50
51     m_mousePressPosition = event->pos().toPoint();
52     m_clickEvent = true;
53 }
54
55 void FriendLocationItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
56 {
57     qDebug() << __PRETTY_FUNCTION__;
58
59     if ((abs(m_mousePressPosition.y() - event->pos().toPoint().y()) > FRIEND_ITEM_PRESS_HEIGHT) ||
60         (abs(m_mousePressPosition.x() - event->pos().toPoint().x()) > FRIEND_ITEM_PRESS_WIDTH)) {
61
62         m_clickEvent = false;
63     }
64 }
65
66 void FriendLocationItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
67 {
68     qDebug() << __PRETTY_FUNCTION__;
69
70     Q_UNUSED(event);
71
72     if (m_clickEvent) {
73         QList<QString> userIDs;
74         userIDs.append(m_userId);
75
76         emit locationItemClicked(userIDs);
77     }
78 }
79
80 void FriendLocationItem::setPartOfGroup(bool value)
81 {
82     m_partOfGroup = value;
83
84     if (value)
85         hide();
86     else
87         show();
88 }
89
90 QString FriendLocationItem::userId() const
91 {
92     qDebug() << __PRETTY_FUNCTION__;
93     return m_userId;
94 }
95
96 void FriendLocationItem::setProfileImage(const QPixmap image, const QUrl &url)
97 {
98     qDebug() << __PRETTY_FUNCTION__;
99     setPixmap(image);
100     setOffset(-image.width()/2, -image.height()/2);
101     m_profileImageUrl = url;
102 }
103
104 QUrl FriendLocationItem::profileImageUrl() const
105 {
106     qDebug() << __PRETTY_FUNCTION__;
107     return m_profileImageUrl;
108 }
109