Re-factored the source to use the new coordinate classes
[situare] / src / ui / userinfo.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5        Jukka Saastamoinen - jukka.saastamoinen@ixonos.com
6        Jussi Laitinen - jussi.laitinen@ixonos.com
7        Katri Kaikkonen - katri.kaikkonen@ixonos.com
8        Henri Lampela - henri.lampela@ixonos.com
9        Ville Tiensuu - ville.tiensuu@ixonos.com
10
11    Situare is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    version 2 as published by the Free Software Foundation.
14
15    Situare is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with Situare; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
23    USA.
24 */
25
26 #ifndef USERINFO_H
27 #define USERINFO_H
28
29 #include <QWidget>
30
31 #include "coordinates/geocoordinate.h"
32 #include "updatelocation/updatelocationdialog.h"
33
34 class ImageButton;
35
36 /**
37 * @brief UserInfo shows user's data in expandable item.
38 *
39 * @class UserInfo userinfo.h "ui/userinfo.h"
40 */
41 class UserInfo : public QWidget
42 {
43     Q_OBJECT
44 public:
45     /**
46     * @brief Constructor
47     *
48     * @param parent Parent
49     */
50     UserInfo(QWidget *parent=0);
51
52     /**
53     * @brief Desctructor
54     * saves unsend user message to settings
55     *
56     */
57     ~UserInfo();
58
59 /*******************************************************************************
60 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
61 *******************************************************************************/
62 protected:
63     /**
64     * @brief Set current mouse position to mouse event position.
65     *
66     * @param event QMouseEvent mouse press event
67     */
68     void mousePressEvent(QMouseEvent *event);
69
70     /**
71     * @brief Call toggleHeight if mouse position is unchanged.
72     *
73     * Check if current mouse position is same as mouse release position.
74     * @param event QMouseEvent mouse release event
75     */
76     void mouseReleaseEvent(QMouseEvent *event);
77
78     /**
79     * @brief This function is called when the widget is drawn
80     *
81     * @param aPaintEvent Pointer to paint event
82     */
83     void paintEvent(QPaintEvent *aPaintEvent);
84
85 /******************************************************************************
86 * MEMBER FUNCTIONS AND SLOTS
87 ******************************************************************************/
88 public:
89     /**
90     * @brief Sets the users current address
91     *
92     * @param address Reference to users current address
93     */
94     void setAddress(const QString &address);
95
96     /**
97     * @brief Sets the users current coordinates
98     *
99     * @param coordinates Reference to users current coordinates
100     */
101     void setCoordinates(const GeoCoordinate &coordinates);
102
103     /**
104     * @brief Sets the user picture
105     *
106     * @param image Reference to user picture
107     */
108     void setProfileImage(const QPixmap &image);
109
110     /**
111     * @brief Sets the time of updated message
112     *
113     * @param time Reference to time when message was sent.
114     */
115     void setTime(const QString &time);
116
117    /**
118     * @brief Sets the user name
119     *
120     * @param name Reference to user name
121     */
122     void setUserName(const QString &name);
123
124 public slots:
125
126     /**
127     * @brief Clears backups of message and publish on Facebook setting
128     */
129     void clearUpdateLocationDialogData();
130
131     /**
132     * @brief Saves status message and Facebook publish setting
133     *
134     * @param status message that user sends. Message is stored to m_backupMessage data member
135     * @param publish setting that determines whether the user status message is published on
136     *        Facebook. This value is stored to m_backupFacebookPublishPolicity data member.
137     */
138     void backupUpdateLocationDialogData(const QString &status, bool publish);
139
140     /**
141     * @brief Sets the message text
142     *
143     * @param text Reference to user message
144     */
145     void setMessageText(const QString &text);
146
147 private:
148
149     /**
150     * @brief reads Unsend message from settings at startup
151     *
152     */
153     void restoreUnsendMessage();
154
155     /**
156     * @brief Set shortened or full-length text to labels.
157     *
158     * @param expanded true if full-length text is set, false otherwise
159     */
160     void setText(bool expanded);
161
162     /**
163     * @brief Set shortened texts from User data.
164     *
165     * Text length is defined by MAXIMUM_CHARS.
166     */
167     QString shortenText(const QLabel *label, const QString &text, int textMaxWidth);
168
169 private slots:
170     /**
171     * @brief Slot for find button click
172     */
173     void findButtonClicked();
174
175     /**
176     * @brief Slot function to forward messageUpdate launch signal
177     *
178     */
179     void messageUpdate();
180
181     /**
182     * @brief Slot function to get indication when dialog is finished
183     *
184     */
185     void updateLocationDialogFinished(int reason);
186
187 /******************************************************************************
188 * SIGNALS
189 ******************************************************************************/
190 signals:
191     /**
192     * @brief Signal for finding user.
193     *
194     * @param coordinates user geo coordinates
195     */
196     void findUser(const GeoCoordinate &coordinates);
197
198     /**
199     * @brief Signal that used to inform user that his message/location update tp Situare server
200     *        was failed.
201     *        This signal is originally sended from UserInfo
202     * @param message message for notification
203     * @param modal true if modal notification otherwice false
204     */
205     void notificateUpdateFailing(const QString &message, bool modal);
206
207     /**
208     * @brief Signal for refreshing user data.
209     *
210     */
211     void refreshUserData();
212
213     /**
214     * @brief Signal for requesting reverseGeo from SituareEngine
215     *
216     */
217     void requestReverseGeo();
218
219     /**
220     * @brief Signals, when address data is ready
221     *
222     * @param address Street address
223     */
224     void reverseGeoReady(const QString &address);
225
226     /**
227     * @brief Signal for requestLocationUpdate from SituareEngine via MainWindow class
228     *
229     * @param status Status message
230     * @param publish Publish on Facebook
231     */
232     void statusUpdate(const QString &status, const bool &publish);
233
234 /******************************************************************************
235 * DATA MEMBERS
236 ******************************************************************************/
237 private:
238     bool m_backupFacebookPublishPolicity; ///< Backup of publish on Facebook checkbox value
239     bool m_expanded;                    ///< Item expanded state
240     QLabel *m_locationLabel;            ///< Location label
241     QLabel *m_nameLabel;                ///< Name label
242     QLabel *m_statusTextLabel;          ///< Status text label
243     QLabel *m_updatedLabel;             ///< Updated label
244     QPixmap m_backgroundBottomImage;    ///< Bottom background image
245     QPixmap m_backgroundMiddleImage;    ///< Middle background image
246     QPixmap m_backgroundTopImage;       ///< Top background image
247     QPoint m_mousePosition;             ///< Current mouse press position
248     GeoCoordinate m_coordinates;        ///< User current coordinates
249     QString m_address;                  ///< Address from where the new message was sent
250     QString m_backupMessage;            ///< Backup of users message
251     QString m_expandedMessageText;      ///< Expanded message text
252     QString m_messageText;              ///< User's message
253     QString m_time;                     ///< Time when the new message was sent
254     QString m_userName;                 ///< User's name
255     ImageButton *m_findButton;          ///< User find button
256     UpdateLocationDialog *m_updateLocation; ///< Update location dialog
257 };
258
259 #endif // USERINFO_H