GPS Sport Sniffer is a open source GPS application developed with Qt and made in...
[gpssportsniffer] / mainWindow.cpp
1 // checksum 0xcf61 version 0x30002
2 /*
3   This file was generated by the Mobile Qt Application wizard of Qt Creator.
4   MainWindow is a convenience class containing mobile device specific code
5   such as screen orientation handling.
6   It is recommended not to modify this file, since newer versions of Qt Creator
7   may offer an updated version of it.
8 */
9
10 #include "mainWindow.h"
11 #include "windowMap.h"
12 #include "ui_mainWindow.h"
13
14 #include <QAction>
15 #include <QMenu>
16 #include <QMenuBar>
17 #include <QMessageBox>
18
19 MainWindow::MainWindow(QWidget *parent)
20     : QMainWindow(parent), ui(new Ui::MainWindow)
21 {
22     ui->setupUi(this);
23
24     log = new Log(this,"gpssniffer.log",DEBUG_VERBOSITY);
25
26     settings = new Settings(log);
27
28     /*
29     windowMap = new WindowMap(this,settings,log);
30     windowMap->setWindowTitle(tr("GPSSniffer->Activity"));
31     */
32
33     //log->debug("log and windowMap created!");
34
35     QAction *simulateAction = new QAction(tr("Simulate GPS"),this);
36     QAction *tracksAction = new QAction(tr("Load tracks"), this);
37     QAction *settingsAction = new QAction(tr("Settings"), this);
38     // the next line doesn't work in Maemo 5
39     //settingsAction->setIcon(QIcon(":/images/shadow.png"));
40     QAction *activityAction = new QAction(tr("New activity"), this);
41     QAction *quitAction = new QAction(tr("Quit"),this);
42
43     //log->debug("connecting all slots...");
44     connect(simulateAction, SIGNAL(triggered()), SLOT(simulate()));
45     connect(tracksAction, SIGNAL(triggered()), SLOT(tracks()));
46     connect(settingsAction, SIGNAL(triggered()), SLOT(configureSettings()));
47     connect(activityAction, SIGNAL(triggered()), SLOT(newActivity()));
48     connect(quitAction, SIGNAL(triggered()), SLOT(quit()));
49
50     connect(ui->simulateButton, SIGNAL(clicked()), SLOT(simulate()));
51     connect(ui->tracksButton, SIGNAL(clicked()), SLOT(tracks()));
52     //connect(ui->settingsButton, SIGNAL(clicked()), SLOT(configureSettings()));
53     connect(ui->newActivityButton, SIGNAL(clicked()), SLOT(newActivity()));
54     connect(ui->quitButton, SIGNAL(clicked()), SLOT(quit()));
55
56
57     log->debug("done!");
58
59
60
61     //ui->tracksButton->setStyleSheet(ui->tracksButton->styleSheet().append("border-radius: 20px"));
62
63 #if defined(Q_OS_SYMBIAN) || defined(Q_OS_WINCE_WM) || defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6)
64         menuBar()->addAction(simulateAction);
65         menuBar()->addAction(tracksAction);
66         menuBar()->addAction(settingsAction);
67         menuBar()->addAction(activityAction);
68         menuBar()->addAction(quitAction);
69 #else
70         QMenu *menu = menuBar()->addMenu("&Options");
71         menu->addAction(simulateAction);
72         menu->addAction(tracksAction);
73         menu->addAction(settingsAction);
74         menu->addAction(activityAction);
75         menu->addAction(quitAction);
76 #endif
77 }
78
79 MainWindow::~MainWindow()
80 {
81     qDebug()<< "destructor MainWindow";
82     delete ui;
83     qDebug() << "ui deleted";
84     delete windowMap;
85     qDebug() << "windowMap deleted";
86     delete log;
87     qDebug()<< "destructor end";
88 }
89
90 void MainWindow::quit(){
91     this->close();
92 }
93
94 void MainWindow::configureSettings(){
95     // settings
96 }
97
98
99 void MainWindow::tracks(){
100     log->debug("Load tracks window...");
101
102     windowMap = new WindowMap(this,settings,log);
103
104     windowMap->setOrientation(WindowMap::ScreenOrientationAuto);
105     windowMap->setWindowTitle(tr("GPSSniffer->Activity"));
106     windowMap->setMode(Mode_LoadTracksWindow);
107     windowMap->setMenuLoadTracks();
108     windowMap->showExpanded();
109     this->hide();
110 }
111
112 void MainWindow::simulate(){
113
114     log->debug("new Activity simulating window...");
115     windowMap = new WindowMap(this,settings,log);
116     windowMap->setOrientation(WindowMap::ScreenOrientationAuto);
117     windowMap->setWindowTitle(tr("GPSSniffer->Activity"));
118     windowMap->setMode(Mode_NewActivityMode);
119     windowMap->setSimulateGPS(true);
120     windowMap->setMenuActivity();
121     log->debug(QString("MAIN WINDOWS SETTINGS CONFIGURED?:%1").arg(settings->getIsConfigured()));
122
123     windowMap->showExpanded();
124     this->hide();
125 }
126
127 void MainWindow::newActivity(){
128     log->debug("new Activity window...");
129     windowMap = new WindowMap(this,settings,log);
130     windowMap->setWindowTitle(tr("GPSSniffer->Activity"));
131     windowMap->setOrientation(WindowMap::ScreenOrientationAuto);
132     windowMap->setMode(Mode_NewActivityMode);
133     windowMap->setMenuActivity();
134     log->debug(QString("MAIN WINDOWS SETTINGS CONFIGURED?:%1").arg(settings->getIsConfigured()));
135     windowMap->showExpanded();
136     this->hide();
137
138 }
139
140
141 void MainWindow::setOrientation(ScreenOrientation orientation)
142 {
143     /*
144 #if defined(Q_OS_SYMBIAN)
145     // If the version of Qt on the device is < 4.7.2, that attribute won't work
146     if (orientation != ScreenOrientationAuto) {
147         const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
148         if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
149             qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
150             return;
151         }
152     }
153 #endif // Q_OS_SYMBIAN
154
155     Qt::WidgetAttribute attribute;
156     switch (orientation) {
157 #if QT_VERSION < 0x040702
158     // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
159     case ScreenOrientationLockPortrait:
160         attribute = static_cast<Qt::WidgetAttribute>(128);
161         break;
162     case ScreenOrientationLockLandscape:
163         attribute = static_cast<Qt::WidgetAttribute>(129);
164         break;
165     default:
166     case ScreenOrientationAuto:
167         attribute = static_cast<Qt::WidgetAttribute>(130);
168         break;
169 #else // QT_VERSION < 0x040702
170     case ScreenOrientationLockPortrait:
171         attribute = Qt::WA_LockPortraitOrientation;
172         break;
173     case ScreenOrientationLockLandscape:
174         attribute = Qt::WA_LockLandscapeOrientation;
175         break;
176     default:
177     case ScreenOrientationAuto:
178         attribute = Qt::WA_AutoOrientation;
179         break;
180 #endif // QT_VERSION < 0x040702
181     };
182     setAttribute(attribute, true);
183     */
184 }
185
186 void MainWindow::showExpanded()
187 {
188 #ifdef Q_OS_SYMBIAN
189     showFullScreen();
190 #elif defined(Q_WS_MAEMO_5)
191     showMaximized();
192 #else
193     show();
194 #endif
195 }
196
197 void MainWindow::closeEvent(QCloseEvent *event){
198
199 }