--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+#include <QDebug>
+#include <QList>
+#include <QPainter>
+#include <QRect>
+
+#include "friendlocationitem.h"
+#include "mapcommon.h"
+
+#include "friendgroupitem.h"
+
+FriendGroupItem::FriendGroupItem(FriendLocationItem *item)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ QPixmap pixmap(":/res/images/friend_group.png");
+ setPixmap(pixmap);
+
+ setOffset(-pixmap.width()/2, -pixmap.height()/2);
+ setZValue(FRIEND_LOCATION_ICON_Z_LEVEL);
+
+ joinFriend(item);
+ setPos(item->pos());
+}
+
+void FriendGroupItem::dropFriend(FriendLocationItem *item)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ qWarning() << __PRETTY_FUNCTION__ << "Dropped: " << m_friends.removeAll(item);
+ item->setPartOfGroup(false);
+ item->show();
+}
+
+void FriendGroupItem::debugPrint()
+{
+ /// @todo REMOVE DEBUG PRINT METHOD AND PRINTOUTS
+ qWarning() << __PRETTY_FUNCTION__;
+
+ foreach (FriendLocationItem *item, m_friends) {
+ qWarning() << __PRETTY_FUNCTION__ << "member: " << item;
+ }
+}
+
+bool FriendGroupItem::dropFriends(int zoomLevel)
+{
+ foreach (FriendLocationItem *friendItem, m_friends) {
+ if (!friendItem->sceneTransformedBoundingRect(zoomLevel).intersects(sceneTransformedBoundingRect(zoomLevel)))
+ dropFriend(friendItem);
+ }
+
+ // group can be deleted if it includes max one friend
+ if (m_friends.size() <= 1) {
+ // drop remaining items
+ foreach (FriendLocationItem *friendItem, m_friends)
+ dropFriend(friendItem);
+
+ qWarning() << __PRETTY_FUNCTION__ << "Group can be deleted";
+ return true;
+ }
+ return false;
+}
+
+void FriendGroupItem::joinFriend(FriendLocationItem *item)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ m_friends.append(item);
+ item->setPartOfGroup(true);
+ item->hide();
+
+// centerToMiddleOfAssociatedFriends();
+}
+
+void FriendGroupItem::mergeWithGroup(FriendGroupItem *group)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ foreach (FriendLocationItem *item, m_friends) {
+ m_friends.removeOne(item);
+ group->joinFriend(item);
+ }
+}
+
+void FriendGroupItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ BaseLocationItem::paint(painter, option, widget);
+
+ QFont font = painter->font();
+ font.setPointSize(painter->font().pointSize() * 2);
+ painter->setFont(font);
+ painter->drawText(QRect(-25, -25, 50, 50), Qt::AlignCenter, QString::number(m_friends.size()));
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Sami Rämö - sami.ramo@ixonos.com
+
+ Situare is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ version 2 as published by the Free Software Foundation.
+
+ Situare is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Situare; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA.
+*/
+
+
+#ifndef FRIENDGROUPITEM_H
+#define FRIENDGROUPITEM_H
+
+#include <QList>
+
+#include "baselocationitem.h"
+
+class FriendLocationItem;
+
+/**
+ * @brief Friend group map item
+ *
+ * Contains grouped FriendLocationItem items and draws group image with number of grouped friends
+ */
+class FriendGroupItem : public BaseLocationItem
+{
+public:
+ /**
+ * @brief Constructor
+ *
+ * Create new group, set picture and join first FriendLocationItem to the group.
+ * Group position is set to be exactly same as item given as parameter.
+ *
+ * @param item First FriendLocationItem to be joined to new group
+ */
+ FriendGroupItem(FriendLocationItem *item);
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+ /**
+ * @brief Paint event
+ *
+ * Draw amount of joined FriendLocationItem items over the image.
+ */
+ void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+
+/*******************************************************************************
+ * MEMBER FUNCTIONS AND SLOTS
+ ******************************************************************************/
+public:
+ void debugPrint();
+
+ /**
+ * @brief Drop all FriendLocationItem items which bounding rect is not colliding with
+ * this group anymore
+ *
+ * Dropped items are set to visible again.
+ */
+ bool dropFriends(int zoomLevel);
+
+ /**
+ * @brief Join new FriendLocationItem to this group.
+ *
+ * Given item is also hidden.
+ *
+ * @param item FriendLocationItem to be joined
+ */
+ void joinFriend(FriendLocationItem *item);
+
+ /**
+ * @brief Merge this group to another FriendGroupItem
+ *
+ * Removes all FrienLocationItem items from this group and joins then to given group.
+ * Group item is not deleted, so caller must delete group after merging.
+ *
+ * @param group FriendGroupItem which takes all this group FriendLocationItem items
+ */
+ void mergeWithGroup(FriendGroupItem *group);
+
+private:
+ /**
+ * @brief Drop single FriendLocationItem from this group
+ *
+ * @param item FriendLocationItem to be dropped
+ */
+ void dropFriend(FriendLocationItem *item);
+
+private:
+ QList<FriendLocationItem *> m_friends; ///< List of joined FriendLocationItem items
+};
+
+#endif // FRIENDGROUPITEM_H