Added highlight mode to FriendGroupItem and FriendLocationItem.
[situare] / src / map / friendgroupitem.h
1 /*
2     Situare - A location system for Facebook
3     Copyright (C) 2010  Ixonos Plc. Authors:
4
5         Sami Rämö - sami.ramo@ixonos.com
6
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.
10
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.
15
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,
19     USA.
20 */
21
22
23 #ifndef FRIENDGROUPITEM_H
24 #define FRIENDGROUPITEM_H
25
26 #include <QList>
27
28 #include "baselocationitem.h"
29
30 class FriendLocationItem;
31
32 /**
33   * @brief Friend group map item
34   *
35   * Contains grouped FriendLocationItem items and draws group image with number of grouped friends
36   *
37   * @author Sami Rämö - sami.ramo@ixonos.com
38   */
39 class FriendGroupItem : public BaseLocationItem
40 {
41     Q_OBJECT
42
43 public:
44     /**
45       * @brief Constructor
46       *
47       * Create new group, set picture and join first FriendLocationItem to the group.
48       * Group position is set to be exactly same as item given as parameter.
49       *
50       * @param item First FriendLocationItem to be joined to new group
51       */
52     FriendGroupItem(FriendLocationItem *item);
53
54 /*******************************************************************************
55  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
56  ******************************************************************************/
57     /**
58       * @brief Paint event
59       *
60       * Draw amount of joined FriendLocationItem items over the image.
61       */
62     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
63
64 protected:
65     /**
66     * @brief Mouse move event.
67     *
68     * Disables m_clickEvent flag if press and release where not
69     * in same area.
70     *
71     * @param event QGraphicsSceneMouseEvent.
72     */
73     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
74
75     /**
76     * @brief Mouse press event.
77     *
78     * Sets mouse press position.
79     *
80     * @param event QGraphicsSceneMouseEvent.
81     */
82     void mousePressEvent(QGraphicsSceneMouseEvent *event);
83
84     /**
85     * @brief Mouse release event.
86     *
87     * Emits friendGroupItemClicked signal if press and release where
88     * in same area.
89     *
90     * @param event QGraphicsSceneMouseEvent.
91     */
92     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
93
94 /*******************************************************************************
95  * MEMBER FUNCTIONS AND SLOTS
96  ******************************************************************************/
97 public:
98     /**
99       * @brief Drop all FriendLocationItem items which bounding rect is not colliding with
100       * this group anymore
101       *
102       * Dropped items are set to visible again.
103       */
104     bool dropFriends(int zoomLevel);
105
106     /**
107       * @brief Drop single FriendLocationItem from this group
108       *
109       * @param item FriendLocationItem to be dropped
110       */
111     void dropFriend(FriendLocationItem *item);
112
113     /**
114       * @brief Join new FriendLocationItem to this group.
115       *
116       * Given item is also hidden.
117       *
118       * @param item FriendLocationItem to be joined
119       */
120     void joinFriend(FriendLocationItem *item);
121
122     /**
123       * @brief Merge this group to another FriendGroupItem
124       *
125       * Removes all FrienLocationItem items from this group and joins then to given group.
126       * Group item is not deleted, so caller must delete group after merging.
127       *
128       * @param group FriendGroupItem which takes all this group FriendLocationItem items
129       */
130     void mergeWithGroup(FriendGroupItem *group);
131
132 /*******************************************************************************
133  * SIGNALS
134  ******************************************************************************/
135 signals:
136     /**
137     * @brief Signal is emitted when l item is clicked.
138     *
139     * @param userIDs list of friends user IDs in the group
140     */
141     void locationItemClicked(const QList<QString> &userIDs);
142
143 /*******************************************************************************
144  * DATA MEMBERS
145  ******************************************************************************/
146 private:
147     QList<FriendLocationItem *> m_friends; ///< List of joined FriendLocationItem items
148     QPoint m_mousePressPosition;    ///< Mouse press position
149     bool m_clickEvent;              ///< Mouse click event flag
150     QPixmap m_image;            ///< Normal item image
151     QPixmap m_highlightImage;   ///< Highlighted item image
152 };
153
154 #endif // FRIENDGROUPITEM_H