2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@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 <QGraphicsSceneMouseEvent>
28 #include "friendlocationitem.h"
29 #include "mapcommon.h"
30 #include "friendgroupitem.h"
33 FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
36 qDebug() << __PRETTY_FUNCTION__;
38 QPixmap pixmap(":/res/images/friend_group.png");
41 setOffset(-pixmap.width()/2, -pixmap.height()/2);
42 setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
48 void FriendGroupItem::dropFriend(FriendLocationItem *item)
50 qDebug() << __PRETTY_FUNCTION__;
52 if (m_friends.removeOne(item))
53 item->setPartOfGroup(false);
56 bool FriendGroupItem::dropFriends(int zoomLevel)
58 qDebug() << __PRETTY_FUNCTION__;
60 foreach (FriendLocationItem *friendItem, m_friends) {
61 if (!friendItem->sceneTransformedBoundingRect(zoomLevel)
62 .intersects(sceneTransformedBoundingRect(zoomLevel)))
63 dropFriend(friendItem);
66 // group can be deleted if it includes max one friend
67 if (m_friends.size() <= 1) {
68 // drop remaining items
69 foreach (FriendLocationItem *friendItem, m_friends)
70 dropFriend(friendItem);
77 void FriendGroupItem::joinFriend(FriendLocationItem *item)
79 qDebug() << __PRETTY_FUNCTION__;
81 m_friends.append(item);
82 item->setPartOfGroup(true);
85 void FriendGroupItem::mergeWithGroup(FriendGroupItem *group)
87 qDebug() << __PRETTY_FUNCTION__;
89 foreach (FriendLocationItem *item, m_friends) {
90 m_friends.removeOne(item);
91 group->joinFriend(item);
95 void FriendGroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
98 qDebug() << __PRETTY_FUNCTION__;
100 BaseLocationItem::paint(painter, option, widget);
102 painter->setPen(Qt::white);
103 painter->setFont(NOKIA_FONT_SMALL);
104 painter->drawText(QRect(GROUP_ITEM_FRIENDS_COUNT_X, GROUP_ITEM_FRIENDS_COUNT_Y,
105 GROUP_ITEM_FRIENDS_COUNT_WIDTH, GROUP_ITEM_FRIENDS_COUNT_HEIGHT),
106 Qt::AlignCenter, QString::number(m_friends.count()));
109 void FriendGroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
111 qDebug() << __PRETTY_FUNCTION__;
113 if ((abs(m_mousePressPosition.y() - event->pos().toPoint().y()) > FRIEND_ITEM_PRESS_HEIGHT) ||
114 (abs(m_mousePressPosition.x() - event->pos().toPoint().x()) > FRIEND_ITEM_PRESS_WIDTH)) {
116 m_clickEvent = false;
120 void FriendGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
122 qDebug() << __PRETTY_FUNCTION__;
124 m_mousePressPosition = event->pos().toPoint();
128 void FriendGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
130 qDebug() << __PRETTY_FUNCTION__;
134 QList<QString> userIDs;
136 foreach (FriendLocationItem *item, m_friends)
137 userIDs.append(item->userId());
139 emit locationItemClicked(userIDs);