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>
29 #include "friendlocationitem.h"
30 #include "mapcommon.h"
31 #include "friendgroupitem.h"
34 FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
37 qDebug() << __PRETTY_FUNCTION__;
39 m_image = QPixmap(":/res/images/friend_group.png");
41 icon.addPixmap(m_image);
42 m_highlightImage = icon.pixmap(m_image.size(), QIcon::Selected, QIcon::On);
45 setOffset(-m_image.width()/2, -m_image.height()/2);
46 setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
52 void FriendGroupItem::dropFriend(FriendLocationItem *item)
54 qDebug() << __PRETTY_FUNCTION__;
56 if (m_friends.removeOne(item))
57 item->setPartOfGroup(false);
60 bool FriendGroupItem::dropFriends(int zoomLevel)
62 qDebug() << __PRETTY_FUNCTION__;
64 foreach (FriendLocationItem *friendItem, m_friends) {
65 if (!friendItem->sceneTransformedBoundingRect(zoomLevel)
66 .intersects(sceneTransformedBoundingRect(zoomLevel)))
67 dropFriend(friendItem);
70 // group can be deleted if it includes max one friend
71 if (m_friends.size() <= 1) {
72 // drop remaining items
73 foreach (FriendLocationItem *friendItem, m_friends)
74 dropFriend(friendItem);
81 void FriendGroupItem::joinFriend(FriendLocationItem *item)
83 qDebug() << __PRETTY_FUNCTION__;
85 m_friends.append(item);
86 item->setPartOfGroup(true);
89 void FriendGroupItem::mergeWithGroup(FriendGroupItem *group)
91 qDebug() << __PRETTY_FUNCTION__;
93 foreach (FriendLocationItem *item, m_friends) {
94 m_friends.removeOne(item);
95 group->joinFriend(item);
99 void FriendGroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
102 qDebug() << __PRETTY_FUNCTION__;
104 BaseLocationItem::paint(painter, option, widget);
106 painter->setPen(Qt::white);
107 painter->setFont(NOKIA_FONT_SMALL);
108 painter->drawText(QRect(GROUP_ITEM_FRIENDS_COUNT_X, GROUP_ITEM_FRIENDS_COUNT_Y,
109 GROUP_ITEM_FRIENDS_COUNT_WIDTH, GROUP_ITEM_FRIENDS_COUNT_HEIGHT),
110 Qt::AlignCenter, QString::number(m_friends.count()));
113 void FriendGroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
115 qDebug() << __PRETTY_FUNCTION__;
118 if ((abs(m_mousePressPosition.y() - event->pos().toPoint().y()) > FRIEND_ITEM_PRESS_HEIGHT)
120 (abs(m_mousePressPosition.x() - event->pos().toPoint().x()) > FRIEND_ITEM_PRESS_WIDTH)){
123 m_clickEvent = false;
128 void FriendGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
130 qDebug() << __PRETTY_FUNCTION__;
132 m_mousePressPosition = event->pos().toPoint();
134 setPixmap(m_highlightImage);
137 void FriendGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
141 qDebug() << __PRETTY_FUNCTION__;
145 QList<QString> userIDs;
147 foreach (FriendLocationItem *item, m_friends)
148 userIDs.append(item->userId());
150 emit locationItemClicked(userIDs);