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,
27 #include "friendlocationitem.h"
28 #include "mapcommon.h"
29 #include "friendgroupitem.h"
32 FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
34 qDebug() << __PRETTY_FUNCTION__;
36 QPixmap pixmap(":/res/images/friend_group.png");
39 setOffset(-pixmap.width()/2, -pixmap.height()/2);
40 setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
46 void FriendGroupItem::dropFriend(FriendLocationItem *item)
48 qDebug() << __PRETTY_FUNCTION__;
50 if (m_friends.removeOne(item))
51 item->setPartOfGroup(false);
54 bool FriendGroupItem::dropFriends(int zoomLevel)
56 qDebug() << __PRETTY_FUNCTION__;
58 foreach (FriendLocationItem *friendItem, m_friends) {
59 if (!friendItem->sceneTransformedBoundingRect(zoomLevel)
60 .intersects(sceneTransformedBoundingRect(zoomLevel)))
61 dropFriend(friendItem);
64 // group can be deleted if it includes max one friend
65 if (m_friends.size() <= 1) {
66 // drop remaining items
67 foreach (FriendLocationItem *friendItem, m_friends)
68 dropFriend(friendItem);
75 void FriendGroupItem::joinFriend(FriendLocationItem *item)
77 qDebug() << __PRETTY_FUNCTION__;
79 m_friends.append(item);
80 item->setPartOfGroup(true);
83 void FriendGroupItem::mergeWithGroup(FriendGroupItem *group)
85 qDebug() << __PRETTY_FUNCTION__;
87 foreach (FriendLocationItem *item, m_friends) {
88 m_friends.removeOne(item);
89 group->joinFriend(item);
93 void FriendGroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
96 qDebug() << __PRETTY_FUNCTION__;
98 BaseLocationItem::paint(painter, option, widget);
100 painter->setPen(Qt::black);
101 painter->setFont(NOKIA_FONT_SMALL);
102 painter->drawText(QRect(GROUP_ITEM_FRIENDS_COUNT_X, GROUP_ITEM_FRIENDS_COUNT_Y,
103 GROUP_ITEM_FRIENDS_COUNT_WIDTH, GROUP_ITEM_FRIENDS_COUNT_HEIGHT),
104 Qt::AlignCenter, QString::number(m_friends.count()));
107 void FriendGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
109 qDebug() << __PRETTY_FUNCTION__;
113 QList<QString> userIDs;
115 foreach (FriendLocationItem *item, m_friends) {
116 userIDs.append(item->userId());
119 emit locationItemClicked(userIDs);