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