The first "kind of" working version of the new panels
[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
45 public:
46     /**
47      * @brief Constructor
48      *
49      * @param parent Parent
50      */
51     UserInfo(QWidget *parent=0);
52
53     /**
54      * @brief Desctructor
55      * saves unsend user message to settings
56      *
57      */
58     ~UserInfo();
59
60 /*******************************************************************************
61 * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
62 *******************************************************************************/
63 protected:
64     /**
65      * @brief Set current mouse position to mouse event position.
66      *
67      * @param event QMouseEvent mouse press event
68      */
69     void mousePressEvent(QMouseEvent *event);
70
71     /**
72      * @brief Call toggleHeight if mouse position is unchanged.
73      *
74      * Check if current mouse position is same as mouse release position.
75      * @param event QMouseEvent mouse release event
76      */
77     void mouseReleaseEvent(QMouseEvent *event);
78
79     /**
80      * @brief This function is called when the widget is drawn
81      *
82      * @param aPaintEvent Pointer to paint event
83      */
84     void paintEvent(QPaintEvent *aPaintEvent);
85
86 /******************************************************************************
87 * MEMBER FUNCTIONS AND SLOTS
88 ******************************************************************************/
89 public:
90     /**
91      * @brief Sets the users current address
92      *
93      * @param address Reference to users current address
94      */
95     void setAddress(const QString &address);
96
97     /**
98      * @brief Sets the users current coordinates
99      *
100      * @param coordinates Reference to users current coordinates
101      */
102     void setCoordinates(const GeoCoordinate &coordinates);
103
104     /**
105      * @brief Sets the user picture
106      *
107      * @param image Reference to user picture
108      */
109     void setProfileImage(const QPixmap &image);
110
111     /**
112      * @brief Sets the time of updated message
113      *
114      * @param time Reference to time when message was sent.
115      */
116     void setTime(const QString &time);
117
118     /**
119      * @brief Sets the user name
120      *
121      * @param name Reference to user name
122      */
123     void setUserName(const QString &name);
124
125 public slots:
126
127     /**
128      * @brief Clears backups of message and publish on Facebook setting
129      */
130     void clearUpdateLocationDialogData();
131
132     /**
133      * @brief Saves status message and Facebook publish setting
134      *
135      * @param status message that user sends. Message is stored to m_backupMessage data member
136      * @param publish setting that determines whether the user status message is published on
137      *        Facebook. This value is stored to m_backupFacebookPublishPolicity data member.
138      */
139     void backupUpdateLocationDialogData(const QString &status, bool publish);
140
141     /**
142      * @brief Sets the message text
143      *
144      * @param text Reference to user message
145      */
146     void setMessageText(const QString &text);
147
148 private:
149
150     /**
151      * @brief reads Unsend message from settings at startup
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     void messageUpdate();
179
180     /**
181      * @brief Slot function to get indication when dialog is finished
182      */
183     void updateLocationDialogFinished(int reason);
184
185 /******************************************************************************
186 * SIGNALS
187 ******************************************************************************/
188 signals:
189     /**
190      * @brief Signal for finding user.
191      *
192      * @param coordinates user geo coordinates
193      */
194     void findUser(const GeoCoordinate &coordinates);
195
196     /**
197      * @brief Signal that used to inform user that his message/location update tp Situare server
198      *        was failed.
199      *        This signal is originally sended from UserInfo
200      * @param message message for notification
201      * @param modal true if modal notification otherwice false
202      */
203     void notificateUpdateFailing(const QString &message, bool modal);
204
205     /**
206      * @brief Signal for refreshing user data.
207      */
208     void refreshUserData();
209
210     /**
211      * @brief Signal for requesting reverseGeo from SituareEngine
212      */
213     void requestReverseGeo();
214
215     /**
216      * @brief Signals, when address data is ready
217      *
218      * @param address Street address
219      */
220     void reverseGeoReady(const QString &address);
221
222     /**
223      * @brief Signal for requestLocationUpdate from SituareEngine via MainWindow class
224      *
225      * @param status Status message
226      * @param publish Publish on Facebook
227      */
228     void statusUpdate(const QString &status, const bool &publish);
229
230 /******************************************************************************
231 * DATA MEMBERS
232 ******************************************************************************/
233 private:
234     bool m_backupFacebookPublishPolicity;   ///< Backup of publish on Facebook checkbox value
235     bool m_expanded;                        ///< Item expanded state
236
237     QLabel *m_locationLabel;                ///< Location label
238     QLabel *m_nameLabel;                    ///< Name label
239     QLabel *m_statusTextLabel;              ///< Status text label
240     QLabel *m_updatedLabel;                 ///< Updated label
241
242     QPixmap m_backgroundBottomImage;        ///< Bottom background image
243     QPixmap m_backgroundMiddleImage;        ///< Middle background image
244     QPixmap m_backgroundTopImage;           ///< Top background image
245
246     QPoint m_mousePosition;                 ///< Current mouse press position
247
248     QString m_address;                      ///< Address from where the new message was sent
249     QString m_backupMessage;                ///< Backup of users message
250     QString m_expandedMessageText;          ///< Expanded message text
251     QString m_messageText;                  ///< User's message
252     QString m_time;                         ///< Time when the new message was sent
253     QString m_userName;                     ///< User's name
254
255     GeoCoordinate m_coordinates;            ///< User current coordinates
256     ImageButton *m_findButton;              ///< User find button
257     UpdateLocationDialog *m_updateLocation; ///< Update location dialog
258 };
259
260 #endif // USERINFO_H