2 Situare - A location system for Facebook
3 Copyright (C) 2010 Ixonos Plc. Authors:
5 Sami Rämö - sami.ramo@ixonos.com
6 Henri Lampela - henri.lampela@ixonos.com
8 Situare is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 version 2 as published by the Free Software Foundation.
12 Situare is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Situare; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
24 #ifndef FRIENDITEMSHANDLER_H
25 #define FRIENDITEMSHANDLER_H
27 #include <QLinkedList>
30 class BaseLocationItem;
31 class FriendGroupItem;
32 class FriendLocationItem;
37 * @brief Handler for friend and friend group items
39 * Handles all friend map items. Colliding items and groups are grouped. All items are owned
42 * @author Sami Rämö - sami.ramo@ixonos.com
43 * @author Ville Tiensuu - ville.tiensuu@ixonos.com
45 class FriendItemsHandler : public QObject
53 * @param mapScene MapScene object
54 * @param parent Parent QObject
56 FriendItemsHandler(MapScene *mapScene, QObject *parent = 0);
58 /*******************************************************************************
59 * MEMBER FUNCTIONS AND SLOTS
60 ******************************************************************************/
63 * @brief Add new FriendLocationItem
65 * New FriendLocationItem is created, values are set and item is added to map.
66 * Item is also added to m_friendItems list.
68 * @param friendData Data for new friend
70 void addFriendItem(User *friendData);
73 * @brief Group colliding friends
75 * Call checkFriendForCollidingFriends() for all visible FriendLocationItem items.
77 void checkAllFriendsForCollidingFriends();
80 * @brief Check single FriendLocationItem for colliding FriendLocationItem items
82 * Check FriendLocationItem against another visible FriendLocationItem items. If collision is
83 * found, then new FriendGroupItem is made and colliding FriendLocationItem items are joined
84 * to this new FriendGroupItem.
86 * @param item FriendLocationItem to be checked
88 void checkFriendForCollidingFriends(FriendLocationItem *item);
91 * @brief clean old friend data from m_mapScene and m_friendItems
93 * @param friendsList QList item of friend information
95 void cleanOldFriendData(const QList<User *> &friendsList);
98 * @brief Check if items collide
100 * Does check if items sceneTransformedBoundingRect() does intersect. If item1's rect is max
101 * half of the rect width from the vertical limits of the map (from inside), then rect is
102 * translated to opposite side of the map and intersections are tested there too.
104 * @param item1 First item
105 * @param item2 Secont item
106 * @return True if collision was found, otherwise false
108 bool collides(BaseLocationItem *item1, BaseLocationItem *item2);
111 * @brief Delete FriendLocationItem
113 * Drops item from all groups, removes it from scene and deletes the item.
115 * @param item Item to be deleted
117 void deleteFriendItem(FriendLocationItem *item);
120 * @brief Destructs all current group items
122 void destructGroups();
125 * @brief Update FriendLocationItem data
127 * Position and image are updated.
129 * @param friendItem Item to be updated
130 * @param friendData New data for the item
132 void updateFriendItem(FriendLocationItem *friendItem, User *friendData);
135 * @brief updates data member m_friendItems from given parameter
137 * @param friendsList QList item of friend information
139 void updateFriendItemList(const QList<User *> &friendsList);
142 * @brief updates data member m_friendItems values that differs from given parameter
144 * @param friendsList QList item of friend information
146 void updateFriendLocationsAndImages(const QList<User *> &friendsList);
151 * @brief Slot updating friend item's profile image
155 void friendImageReady(User *user);
158 * @brief Slot for upgrading friend items and groups
160 * Does add and/or remove FriendLocationItem items if there are new friends
161 * or old ones deleted in the given list. Remaining FriensLocationItems are updated.
163 * @param friendsList QList item of friend information
165 void friendListUpdated(QList<User *> &friendsList);
168 * @brief Destroys all current groups and runs grouping again
170 * Calls destructGroups() and checkAllFriendsForCollidingFriends().
172 * @param zoomLevel Current view zoom level, used for friend item rect scaling
174 void refactorFriendItems(int zoomLevel);
176 /*******************************************************************************
178 ******************************************************************************/
181 * @brief Signal is emitted when location item is clicked.
183 * @param userIDs list of friends user IDs in the group
185 void locationItemClicked(const QList<QString> &userIDs);
187 /*******************************************************************************
189 ******************************************************************************/
191 QLinkedList<FriendGroupItem *> m_friendGroupItems; ///< All FriendGroupItem items
192 QLinkedList<FriendLocationItem *> m_friendItems; ///< List of friendLocationItems
193 MapScene *m_mapScene; ///< Pointer to MapScene
194 int m_zoomLevel; ///< Current view zoom level used for calculation of items bounding rect
197 #endif // FRIENDITEMSHANDLER_H