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