Merge branch 'master' of https://vcs.maemo.org/git/gpssportsniffer
[gpssportsniffer] / windowMap.h
1 /****************************************************************************
2 **
3 **  Copyright (C) 2011  Tito Eritja Real <jtitoo@gmail.com>
4 **
5 **  This program is free software: you can redistribute it and/or modify
6 **  it under the terms of the GNU General Public License as published by
7 **  the Free Software Foundation, either version 3 of the License, or
8 **  (at your option) any later version.
9 **
10 **  This program is distributed in the hope that it will be useful,
11 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 **  GNU General Public License for more details.
14 **
15 **  You should have received a copy of the GNU General Public License
16 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 **
18 ****************************************************************************/
19
20 #ifndef ACTIVITYMAP_H
21 #define ACTIVITYMAP_H
22
23 #include <QMainWindow>
24 #include <QDir>
25 #include <QNetworkSession>
26 #include <QTimer>
27 #include <QToolButton>
28 #include <QProgressBar>
29
30
31 //QtMobility API headers
32 #include <qmobilityglobal.h>
33 #include <qgeosatelliteinfosource.h>
34 #include <qnmeapositioninfosource.h>
35 #include <qgeopositioninfo.h>
36 #include <qnetworkconfigmanager.h>
37 #include <qnetworksession.h>
38
39 #include "log.h"
40 #include "track.h"
41 #include "tilesMap.h"
42 #include "loadTracksWindow.h"
43 #include "settingsWindow.h"
44 #include "activityinfo.h"
45 #include "downloadingStatus.h"
46
47 class Settings;
48 class ConnectivityHelper;
49 //class SatelliteDialog;
50
51
52 // Use the QtMobility namespace
53 QTM_USE_NAMESPACE
54
55
56 class WindowMap : public QMainWindow
57 {
58     Q_OBJECT
59
60 private:
61
62     int zoom;
63     // Atributes
64     qreal firstLat;
65     qreal firstLong;
66
67     Mode mode;
68
69     bool network;
70
71     bool isConfigured;
72
73     bool pressed;
74     bool snapped;
75     bool possitionPaint;
76     bool isDisplayInit;
77
78     int tilesToDownload;
79
80
81     QPoint pressPos;
82     QPoint dragPos;
83
84     QPointF topLeft;
85     QGeoPositionInfoSource *location;
86
87     TilesMap* slippyMap;
88
89     QNetworkSession *nSession;
90     ConnectivityHelper *nConHelp;
91     QString networkError;
92
93
94     //Menus
95
96     QAction *startNetworkAction;
97     QAction *loadTrackAction;
98     QAction *downloadMapsTrackAction;
99     QAction *newActivityAction;
100     QAction *simulatedActivityAction;
101     QAction *quitAction;
102     QAction *lapAction;
103     QAction *settingsAction;
104     QAction *stopAction;
105     QAction *startAction;
106     QAction *tracksAction;
107     //QAction *satelliteAction;
108     QAction *infoAction;
109
110     // Dialogs
111     LoadTracksWindow *loadTracksWindow;
112     SettingsWindow *settingsWindow;
113     ActivityInfo *infoWindow;
114
115     // Progress bar
116
117     DownloadingStatus* downloadingStatus;
118
119     //QGeoSatelliteInfoSource *satelliteInfo;
120     //SatelliteDialog *satelliteDialog;
121
122
123     Log *log;
124
125     Track *track;
126     Track *trackToSniff;
127
128     QList<GpsPoint*> trackToSimulate;
129
130     //bool waitingForFix;
131     int validPositions;
132     int invalidPositions;
133
134     QTimer *autosaveTimer;
135     QTimer *sPossitioningTimer;
136     QTimer *simulatePossitioningTimer;
137
138     bool simulateGPS;
139
140     // events
141     void closeEvent(QCloseEvent *event);
142     void showEvent(QShowEvent *);
143     void paintEvent(QPaintEvent *event);
144     void mousePressEvent(QMouseEvent *event);
145     void mouseMoveEvent(QMouseEvent *event);
146     void mouseReleaseEvent(QMouseEvent *event);
147     void resizeEvent(QResizeEvent * );
148
149     void chooseDisplay();
150 public:
151
152     QToolButton *zoomInButton;
153     QToolButton *zoomOutButton;
154
155     Settings *settings;
156
157     enum ScreenOrientation {
158         ScreenOrientationLockPortrait,
159         ScreenOrientationLockLandscape,
160         ScreenOrientationAuto
161     };
162
163     explicit WindowMap(QWidget *parent = 0,Settings* settings=0, Log *log=0);
164     virtual ~WindowMap();
165
166     void displayInit(QPainter *p);
167
168     void fixZoomButtons();
169     void updateSummary();
170     void clearAllMaps();
171     void setMenuActivity();
172     void setMenuLoadTracks();
173     void setTopLeft(qreal lat, qreal lng);
174     bool drawTrack(Track* track_p, QPainter* p, QString color, bool boolLast);
175     bool drawTrack(Track* track_p, QPainter* p, QString color);
176     void drawFullTrackMaps(Track* track_p);
177
178     void changeMapType(MapType map);
179     void changeUpdateInterval(int millis);
180     bool checkGPS();
181     void startGPS();
182     void startMaps();
183
184     //void showSatelliteInfo();
185     void startNetworking();
186     void stopNetworking();
187     void setOrientation(ScreenOrientation orientation);
188     void showExpanded();
189     void startServices();
190     inline Track* getTrack(){return track;}
191     inline Track* getTrackToSniff(){return trackToSniff;}
192     inline void setTrackToSimulate(QList<GpsPoint*> toDo){trackToSimulate=toDo;}
193     inline bool hasTrackToSimulate(){return (trackToSimulate.size()>0);}
194     inline void startAutosaveTimer(int milliseconds){autosaveTimer->start(milliseconds);}
195     inline void startSimulatePossitioning(int milliseconds){simulatePossitioningTimer->start(milliseconds);}
196     inline void startSimulatePossitioning(){simulatePossitioningTimer->start();}
197     inline void startSPositioningTimer(){sPossitioningTimer->start();}
198     inline void saveXml(){autosave();}
199     inline void setMode(Mode m){mode=m;}
200     inline Mode getMode(){return mode;}
201     inline void setTrackToSniff(Track* t){trackToSniff=t;}
202     inline bool simulatingGPS(){return simulateGPS;}
203     inline void setSimulateGPS(bool value){simulateGPS=value;}
204     inline int getTilesToDownload(){return tilesToDownload;}
205     inline void setIsCacheEnabled(bool value){
206         if(slippyMap)
207             slippyMap->setIsCacheEnabled(value);
208     }
209     inline bool isCacheEnabled(){return slippyMap->isCacheEnabled();}
210
211     void setTrack(QString filename,QString activity);
212     void setCenter(qreal lat, qreal lng);
213
214
215     public slots:
216     void desactivatePossitionPaint();
217     void activatePossitionPaint();
218     void simulatedPossitionUpdated();
219     void updateProgress(int val);
220
221     private slots:
222     void networkSessionOpened();
223     void error(QNetworkSession::SessionError error);
224     void stopActivity();
225     void startActivity();
226     void configureSettings();
227     void lapActivity();
228     void tracksActivity();
229     void newSimulation();
230     void info();
231
232     void loadTrack();
233     void downloadMapTrack();
234     void newActivityTrack();
235     void networkStart();
236
237
238     void quit();
239     //void satellite();
240
241     void onZoomIn();
242     void onZoomOut();
243     void startPositioning();
244     void stopPositioning();
245
246
247     //void networkSessionOpened();
248     //void waitForFix();
249     void updateMap(const QRect &r);
250
251
252     void positionUpdated(const QGeoPositionInfo &info);
253     void autosave();
254
255 };
256
257 #endif // ACTIVITYMAP_H