Pre-merge. Also change drawOsmLicense to use QSize
[situare] / src / ui / mainwindow.h
1 /*
2    Situare - A location system for Facebook
3    Copyright (C) 2010  Ixonos Plc. Authors:
4
5       Henri Lampela - henri.lampela@ixonos.com
6       Kaj Wallin - kaj.wallin@ixonos.com
7       Sami Rämö - sami.ramo@ixonos.com
8
9    Situare is free software; you can redistribute it and/or
10    modify it under the terms of the GNU General Public License
11    version 2 as published by the Free Software Foundation.
12
13    Situare is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with Situare; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
21    USA.
22 */
23
24 #ifndef MAINWINDOW_H
25 #define MAINWINDOW_H
26
27 #include <QtGui/QMainWindow>
28 #include <QUrl>
29
30 class QGraphicsScene;
31 class QLabel;
32 class QWebView;
33
34 class FacebookAuthentication;
35 class FriendListPanel;
36 class LoginDialog;
37 class MapScene;
38 class MapView;
39 class SituareService;
40 class User;
41 class UserInfoPanel;
42 class ZoomButtonPanel;
43
44 /**
45 * @brief Main Window Class
46 */
47 class MainWindow : public QMainWindow
48 {
49     Q_OBJECT
50
51 public:
52     /**
53     * @brief Constructor
54     *
55     * @param parent Parent
56     */
57     MainWindow(QWidget *parent = 0);
58
59     /**
60     * @brief Destructor
61     *
62     */
63     ~MainWindow();
64
65 /*******************************************************************************
66  * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
67  ******************************************************************************/
68 private:
69     /**
70       * @brief HW increase and decrease key presses are grabbed and used for zooming the map.
71       */
72     void keyPressEvent(QKeyEvent* event);
73
74 /*******************************************************************************
75  * MEMBER FUNCTIONS AND SLOTS
76  ******************************************************************************/
77 public:
78     /**
79     * @brief Enable / disable auto centering button.
80     *
81     * @param enabled true if shoud be enabled, false otherwise
82     */
83     void setAutoCenteringButtonEnabled(bool enabled);
84
85     /**
86     * @brief Enable / disable GPS button.
87     *
88     * Does set visibilities for manual location cursor and auto centering menu button.
89     *
90     * @param enabled true if enabled, false otherwise
91     */
92     void setGPSButtonEnabled(bool enabled);
93
94     /**
95       * @brief Set scene for MapView
96       *
97       * @param scene Scene to be set
98       */
99     void setMapViewScene(QGraphicsScene *scene);
100
101     /**
102     * @brief Show Maemo information box with message.
103     *
104     * @brief message information message
105     */
106     void showMaemoInformationBox(const QString &message);
107
108     /**
109     * @brief Gets the username from member variable for saving purposes
110     *
111     * @return QString Username
112     */
113     const QString username();
114
115 public slots:
116     /**
117     * @brief Slot to intercept signal when user has pressed connect button from loginDialog
118     *
119     * @param email E-mail
120     * @param password Password
121     */
122     void loginDialogDone(const QString &email, const QString &password);
123
124     /**
125     * @brief Slot to intercept signal when login has failed (loginFailure signal)
126     *
127     */
128     void loginFailed();
129
130     /**
131     * @brief Public slot, which open settings dialog
132     */
133     void openSettingsDialog();
134
135     /**
136     * @brief Sets username to member variable for login dialog
137     *
138     * @param username Username to be set
139     */
140     void setUsername(const QString &username);
141
142     /**
143     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
144     *        doesn't exist yet
145     *
146     * @param url Login page url
147     */
148     void startLoginProcess(const QUrl &url);
149
150     /**
151     * @brief Toggle progress indicator.
152     *
153     * @param state true if progress indicator should be shown, false otherwise
154     */
155     void toggleProgressIndicator(bool state);
156
157 private:
158     /**
159       * @brief Build friend list panel and connect slots
160       */
161     void buildFriendListPanel();
162
163     /**
164       * @brief Build manual location setting cross hair and connect slots
165       */
166     void buildManualLocationCrosshair();
167
168     /**
169       * @brief Build map and connect slots
170       */
171     void buildMap();
172
173     /**
174       * @brief Build OSM license and connect slots
175       */
176     void buildOsmLicense();
177
178     /**
179       * @brief Build user info panel and connect slots
180       */
181     void buildUserInfoPanel();
182
183     /**
184       * @brief Build zoom button panel and connect slots
185       */
186     void buildZoomButtonPanel();
187
188     /**
189     * @brief Private method to create the Menu items
190     */
191     void createMenus();
192
193     /**
194       * @brief Grab or release HW increase and decrease buttons.
195       *
196       * @param grab Use true for grabbing and false for releasing the keys
197       */
198     void grabZoomKeys(bool grab);
199
200     /**
201       * @brief Set own location crosshair visibility
202       *
203       * @param visible
204       */
205     void setOwnLocationCrosshairVisibility(bool visible);
206
207 private slots:
208     /**
209     * @brief Slot for drawing the Open Street Map license text
210     *
211     * @param size Size of the screen
212     */
213     void drawOsmLicense(const QSize &size);
214
215     /**
216     * @brief Slot for drawing the own location crosshair
217     *
218     * @param width Width of the viewport
219     * @param height Height of the viewport
220     */
221     void drawOwnLocationCrosshair(int width, int height);
222
223     /**
224     * @brief Slot for gps error.
225     *
226     * @param message error message
227     */
228     void gpsError(const QString &message);
229
230     /**
231     * @brief Slot for gps timeout.
232     *
233     * Called when request timeout occurs.
234     */
235     void gpsTimeout();
236
237     /**
238     * @brief Slot to intercept signal when webview has finished loading webpage
239     *
240     * @param done Status of the loading
241     */
242     void loadDone(bool done);
243
244     /**
245     * @brief Set correnct view port size to datamembers
246     *
247     * @param width Width of the viewport
248     * @param height Height of the viewport
249     */
250     void setViewPortSize(const int width, const int height);
251
252 /*******************************************************************************
253  * SIGNALS
254  ******************************************************************************/
255 signals:
256     /**
257     * @brief Automatic centering setting changed by user
258     *
259     * @param enabled True if automatic centering is enabled, otherwise false
260     */
261     void autoCenteringTriggered(bool enabled);
262
263     /**
264     * @brief Signal that indicates when user has cancelled login process
265     *
266     */
267     void cancelLoginProcess();
268
269     /**
270     * @brief View should be centered to new location
271     *
272     * @param sceneCoordinate Scene coordinates of the new center point
273     */
274     void centerToSceneCoordinates(QPoint sceneCoordinate);
275
276     /**
277     * @brief Signal for requesting username from settings
278     *
279     */
280     void fetchUsernameFromSettings();
281
282     /**
283     * @brief GPS setting changed
284     *
285     * @param enabled True if GPS is enabled, otherwise false
286     */
287     void gpsTriggered(bool enabled);
288
289     /**
290     * @brief Signal for finding friend.
291     *
292     * @param coordinates friend's geo coordinates
293     */
294     void findFriend(const QPointF &coordinates);
295
296     /**
297     * @brief Signal for friend location ready.
298     *
299     * @param friendsList
300     */
301     void friendsLocationsReady(QList<User *> &friendsList);
302
303     /**
304     * @brief MapView has been resized
305     *
306     * @param size view size
307     */
308     void mapViewResized(const QSize &size);
309
310     /**
311       * @brief Forwarding signal from MapView to MapEngine
312       *
313       * @param sceneCoordinate
314       */
315     void mapViewScrolled(QPoint sceneCoordinate);
316
317     /**
318       * @brief Forwarding signal from MapEngine to MapView
319       */
320     void maxZoomLevelReached();
321
322     /**
323       * @brief Forwarding signal from MapEngine to MapView
324       */
325     void minZoomLevelReached();
326
327     /**
328     * @brief Signal for refreshing user data.
329     *
330     */
331     void refreshUserData();
332
333     /**
334     * @brief Signal for requesting reverseGeo from SituareEngine
335     *
336     */
337     void requestReverseGeo();
338
339     /**
340     * @brief Signals, when address data is ready
341     *
342     * @param address Street address
343     */
344     void reverseGeoReady(const QString &address);
345
346     /**
347     * @brief Signal for requestLocationUpdate from SituareEngine
348     *
349     * @param status Status message
350     * @param publish Publish on Facebook
351     */
352     void statusUpdate(const QString &status, const bool &publish);
353
354     /**
355     * @brief Signals when webview's urlChanged signal is emitted
356     *
357     * @param url New url
358     */
359     void updateCredentials(const QUrl &url);
360
361     /**
362     * @brief MapView has finished zooming
363     */
364     void viewZoomFinished();
365
366     /**
367     * @brief Signal for use location ready.
368     *
369     * @param user User object
370     */
371     void userLocationReady(User *user);
372
373     /**
374     * @brief Map zoom in request
375     */
376     void zoomIn();
377
378     /**
379       * @brief Forwarding signal from MapEngine to MapView
380       */
381     void zoomLevelChanged(int zoomLevel);
382
383     /**
384     * @brief Map zoom out request
385     */
386     void zoomOut();
387
388 /*******************************************************************************
389  * DATA MEMBERS
390  ******************************************************************************/
391 private:
392
393     bool m_drawOwnLocationCrosshair;        ///< Flag for making ownLocationCrosshair visible or not
394     bool m_refresh;                         ///< Indicates when webpage is refreshed
395
396     int m_viewPortHeight;                   ///< Height of view port
397     int m_viewPortWidth;                    ///< Width of view port
398
399     QAction *m_autoCenteringAct;            ///< Action to auto center map using gps position
400     QAction *m_gpsToggleAct;                ///< Action to trigger gps toggle
401     QAction *m_toSettingsAct;               ///< Action to trigger switch to settings dialog
402
403     QLabel *m_osmLicense;                   ///< Label for Open Street Map license
404     QLabel *m_ownLocationCrosshair;         ///< Label that show ownLocationCrosshair
405
406     QMenu *m_viewMenu;                      ///< Object that hold the view menu items
407
408     QString m_email;                        ///< Placeholder for email
409     QString m_password;                     ///< Placeholder for password
410
411     QUrl m_loginUrl;                        ///< Placeholder for login page url
412
413     QWebView *m_webView;                    ///< Shows facebook login page
414
415     FriendListPanel *m_friendsListPanel;    ///< Instance of friends list panel
416     LoginDialog *m_loginDialog;             ///< Login dialog
417     MapView *m_mapView;                     ///< Instance of the map view
418     UserInfoPanel *m_userPanel;             ///< Instance of the user information panel
419     ZoomButtonPanel *m_zoomButtonPanel;     ///< Instance of zoom button panel
420 };
421
422 #endif // MAINWINDOW_H