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 "friendgroupitem.h"
31 #include "mapcommon.h"
34 FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
37 qDebug() << __PRETTY_FUNCTION__;
39 setPixmap(QPixmap(":/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__;
102 icon.addPixmap(pixmap());
103 painter->drawPixmap(offset(), icon.pixmap(pixmap().size(), QIcon::Selected,
106 QGraphicsPixmapItem::paint(painter, option, widget);
109 painter->setPen(Qt::white);
110 painter->setFont(NOKIA_FONT_SMALL);
111 painter->drawText(QRect(GROUP_ITEM_FRIENDS_COUNT_X, GROUP_ITEM_FRIENDS_COUNT_Y,
112 GROUP_ITEM_FRIENDS_COUNT_WIDTH, GROUP_ITEM_FRIENDS_COUNT_HEIGHT),
113 Qt::AlignCenter, QString::number(m_friends.count()));
116 void FriendGroupItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
118 qDebug() << __PRETTY_FUNCTION__;
121 if ((event->pos() - m_mousePressPosition).manhattanLength() > PRESS_MANHATTAN_LENGTH) {
122 m_clickEvent = false;
128 void FriendGroupItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
130 qDebug() << __PRETTY_FUNCTION__;
132 m_mousePressPosition = event->pos();
137 void FriendGroupItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
141 qDebug() << __PRETTY_FUNCTION__;
144 m_clickEvent = false;
145 QList<QString> userIDs;
147 foreach (FriendLocationItem *item, m_friends)
148 userIDs.append(item->userId());
150 emit locationItemClicked(userIDs);