a2db728fde5556909e2f3a3af5d8ed0f944a3d9a
[situare] / src / map / friendlocationitem.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Ville Tiensuu - ville.tiensuu@ixonos.com
6        Sami Rämö - sami.ramo@ixonos.com
7
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.
11
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.
16
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,
20    USA.
21 */
22
23 #ifndef FRIENDLOCATIONITEM_H
24 #define FRIENDLOCATIONITEM_H
25
26
27 #include <QObject>
28 #include <QUrl>
29 #include <QPixmap>
30 #include <QPainter>
31
32 #include "baselocationitem.h"
33
34 /**
35 * @brief Class that shows friends location icons on the map
36 *
37 * @class FriendLocationItem friendlocationitem.h "map/friendlocationitem.h"
38 * @author Ville Tiensuu.
39 * @author Sami Rämö - sami.ramo@ixonos.com
40 */
41 class FriendLocationItem : public BaseLocationItem
42 {
43     Q_OBJECT
44
45 public:
46     /**
47     * @brief Constructor of FriendLocationItem
48     *
49     * Sets user ID
50     * Sets position to UNDEFINED.
51     * Sets default Z-value.
52     * Sets item to ignore transformations. this feature is needed to make icon on the map
53     * immune to scaling
54     *
55     * @param userId Used ID of the friend
56     * @param parent Parent
57     */
58     FriendLocationItem(const QString &userId, QObject *parent = 0);
59
60 /*******************************************************************************
61  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
62  ******************************************************************************/
63 public:
64     /**
65     * @brief Paints item pixmap.
66     *
67     * Paints normal or highlighted pixmap image.
68     *
69     * @param painter QPainter
70     * @param option QStyleOptionGraphicsItem
71     * @param widget QWidget
72     */
73     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
74
75 /*******************************************************************************
76 * MEMBER FUNCTIONS AND SLOTS
77 ******************************************************************************/
78 public:
79     /**
80     * @brief Is item part of any group
81     *
82     * @return True if item is part of group, otherwise false.
83     */
84     bool isPartOfGroup() const;
85
86     /**
87     * @brief getter for friends profile image URL
88     *
89     * @return QUrl friends profile images URL
90     */
91     QUrl profileImageUrl() const;
92
93     /**
94     * @brief Set profile image and it's URL for friend
95     *
96     * Also offset is set matching new image dimensions.
97     *
98     * @param image New profile image
99     * @param url URL of the new profile image
100     */
101     void setProfileImage(const QPixmap image, const QUrl &url);
102
103     /**
104     * @brief Set value for m_partOfGroup flag
105     *
106     * @param value New value
107     */
108     void setPartOfGroup(bool value);
109
110     /**
111     * @brief getter for m_userId
112     *
113     * @return QString friends user identity
114     */
115     QString userId() const;
116
117 protected:
118     /**
119     * @brief method that detects when friend icon is moved
120     *
121     * Disables m_clickEvent flag if press and release where not
122     * in same area.
123     *
124     * @param event detects the mouse move (or touch in Maemo)
125     */
126     void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
127
128     /**
129     * @brief method that detects when friend icon is clicked
130     *
131     * @param event detects the mouse click (or touch in Maemo)
132     */
133     void mousePressEvent(QGraphicsSceneMouseEvent *event);
134
135     /**
136     * @brief method that detects when friend icon press is released
137     *
138     * @param event detects the mouse release event (or touch in Maemo)
139     */
140     void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
141
142  /*******************************************************************************
143   * SIGNALS
144   ******************************************************************************/
145  signals:
146      /**
147      * @brief Signal is emitted when l item is clicked.
148      *
149      * @param userIDs list of friends user IDs in the group
150      */
151      void locationItemClicked(const QList<QString> &userIDs);
152
153 /*******************************************************************************
154 * DATA MEMBERS
155 ******************************************************************************/
156 private:
157     bool m_partOfGroup; ///< Flag to mark if item is part of any group
158     const QString m_userId; ///< Friends user ID. Can't be changed afterwards
159     QUrl m_profileImageUrl; ///< Friends Facebook profile image URL
160     QPointF m_mousePressPosition; ///< Mouse press position
161     bool m_clickEvent;          ///< Flag to mark click event
162 };
163
164 #endif // FRIENDLOCATIONITEM_H