Added mouse press and release methods to FriendGroupItem and
[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 {
35     qDebug() << __PRETTY_FUNCTION__;
36
37     setPos(UNDEFINED, UNDEFINED);
38     setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
39 }
40
41 bool FriendLocationItem::isPartOfGroup() const
42 {
43     return m_partOfGroup;
44 }
45
46 void FriendLocationItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
47 {
48     qDebug() << __PRETTY_FUNCTION__;
49
50     m_mousePressPosition = event->screenPos();
51 }
52
53 void FriendLocationItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
54 {
55     qDebug() << __PRETTY_FUNCTION__;
56
57     if ((abs(m_mousePressPosition.y() - event->screenPos().y()) <= FRIEND_ITEM_PRESS_HEIGHT) &&
58         (abs(m_mousePressPosition.x() - event->screenPos().x()) <= FRIEND_ITEM_PRESS_WIDTH)) {
59         QList<QString> userIDs;
60         userIDs.append(m_userId);
61
62         emit locationItemClicked(userIDs);
63     }
64 }
65
66 void FriendLocationItem::setPartOfGroup(bool value)
67 {
68     m_partOfGroup = value;
69
70     if (value)
71         hide();
72     else
73         show();
74 }
75
76 QString FriendLocationItem::userId() const
77 {
78     qDebug() << __PRETTY_FUNCTION__;
79     return m_userId;
80 }
81
82 void FriendLocationItem::setProfileImage(const QPixmap image, const QUrl &url)
83 {
84     qDebug() << __PRETTY_FUNCTION__;
85     setPixmap(image);
86     setOffset(-image.width()/2, -image.height()/2);
87     m_profileImageUrl = url;
88 }
89
90 QUrl FriendLocationItem::profileImageUrl() const
91 {
92     qDebug() << __PRETTY_FUNCTION__;
93     return m_profileImageUrl;
94 }
95