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,
23 #ifndef FRIENDITEMSHANDLER_H
24 #define FRIENDITEMSHANDLER_H
26 #include <QLinkedList>
29 class BaseLocationItem;
30 class FriendGroupItem;
31 class FriendLocationItem;
36 * @brief Handler for friend and friend group items
38 * Handles all friend map items. Colliding items and groups are grouped. All items are owned
41 * @author Sami Rämö - sami.ramo@ixonos.com
42 * @author Ville Tiensuu - ville.tiensuu@ixonos.com
44 class FriendItemsHandler : public QObject
52 * @param mapScene MapScene object
53 * @param parent Parent QObject
55 FriendItemsHandler(MapScene *mapScene, QObject *parent = 0);
57 /*******************************************************************************
58 * MEMBER FUNCTIONS AND SLOTS
59 ******************************************************************************/
62 * @brief Add new FriendLocationItem
64 * New FriendLocationItem is created, values are set and item is added to map.
65 * Item is also added to m_friendItems list.
67 * @param friendData Data for new friend
69 void addFriendItem(User *friendData);
72 * @brief Group colliding friends
74 * Call checkFriendForCollidingFriends() for all visible FriendLocationItem items.
76 void checkAllFriendsForCollidingFriends();
79 * @brief Join friends to colliding group
81 * Call checkGroupForCollidingFriends() for all FriendGroupItem items.
83 void checkAllGroupsForCollidingFriends();
86 * @brief Check single FriendLocationItem for colliding FriendLocationItem items
88 * Check FriendLocationItem against another visible FriendLocationItem items. If collision is
89 * found, then new FriendGroupItem is made and colliding FriendLocationItem items are joined
90 * to this new FriendGroupItem.
92 * @param item FriendLocationItem to be checked
94 void checkFriendForCollidingFriends(FriendLocationItem *item);
97 * @brief Check single FriendGroupItem for colliding FriendLocationItem
99 * Check FriendGroupItem against all visible FriendLocationItem items. Colliding
100 * FriendLocationItem items are joiden to given FriendGroupItem.
102 * @param group FriendGroupItem to be checked
104 void checkGroupForCollidingFriends(FriendGroupItem *group);
107 * @brief Check single FriendGroupItem for colliding FriendGroupItem items
109 * Colliding FriendGroupItem items are merged. Item given as parameter remains and colliding
110 * items are deleted after their friend items are merged to remaining group.
112 * @param group FriendGroupItem to be checked
114 void checkGroupForCollidingGroups(FriendGroupItem *group);
117 * @brief clean old friend data from m_mapScene and m_friendItems
119 * @param friendsList QList item of friend information
121 void cleanOldFriendData(const QList<User *> &friendsList);
124 * @brief Check if items collide
126 * Does check if items sceneTransformedBoundingRect() does intersect. If item1's rect is
127 * over the limits of the map, then rect is translated to opposite side of the map and
128 * intersections are tested there too.
130 * @param item1 First item
131 * @param item2 Secont item
132 * @return True if collision was found, otherwise false
134 bool collides(BaseLocationItem *item1, BaseLocationItem *item2);
137 * @brief Delete FriendLocationItem
139 * Drops item from all groups, removes it from scene and deletes the item.
141 * @param item Item to be deleted
143 void deleteFriendItem(FriendLocationItem *item);
146 * @brief Drop FriendLocationItem from all FriendGroupItem groups
148 * @param item Item to be dropped.
150 void dropFriendFromAllGroups(FriendLocationItem *item);
153 * @brief Drop all FriendLocationItem items, which are out of FriendGroupItem boundaries,
154 * from all FriendGroupItem items.
156 void dropOutOfGroupFriends();
159 * @brief Merge all colliding groups
161 * Calls checkGroupForCollidingGroups() for all FriendGroupItem items.
163 void mergeCollidingGroups();
166 * @brief Update FriendLocationItem data
168 * Position and image are updated.
170 * @param friendItem Item to be updated
171 * @param friendData New data for the item
173 void updateFriendItem(FriendLocationItem *friendItem, User *friendData);
176 * @brief updates data member m_friendItems from given parameter
178 * @param friendsList QList item of friend information
180 void updateFriendItemList(const QList<User *> &friendsList);
183 * @brief updates data member m_friendItems values that differs from given parameter
185 * @param friendsList QList item of friend information
187 void updateFriendLocationsAndImages(const QList<User *> &friendsList);
191 * @brief Slot for upgrading friend items and groups
193 * Does add and/or remove FriendLocationItem items if there are new friends
194 * or old ones deleted in the given list. Remaining FriensLocationItems are updated.
196 * @param friendsList QList item of friend information
198 void friendListUpdated(QList<User *> &friendsList);
201 * @brief Re-factors all FriendLocationItem and FriendGroupItem items.
203 * Calls mergeCollidingGroups(), dropOutOfGroupFriends(), checkAllGroupsForCollidingFriends()
204 * and checkAllFriendsForCollidingFriends().
206 * @param zoomLevel Current view zoom level
208 void refactorFriendItems(int zoomLevel);
210 /*******************************************************************************
212 ******************************************************************************/
215 * @brief Signal is emitted when location item is clicked.
217 * @param userIDs list of friends user IDs in the group
219 void locationItemClicked(const QList<QString> &userIDs);
221 /*******************************************************************************
223 ******************************************************************************/
225 QLinkedList<FriendGroupItem *> m_friendGroupItems; ///< All FriendGroupItem items
226 QLinkedList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
227 MapScene *m_mapScene; ///< Pointer to MapScene
228 int m_zoomLevel; ///< Current view zoom level used for calculation of items bounding rect
231 #endif // FRIENDITEMSHANDLER_H