1 /****************************************************************************
3 ** Copyright (C) 2011 Tito Eritja Real <jtitoo@gmail.com>
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.
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.
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/>.
18 ****************************************************************************/
20 #include "mainWindow.h"
21 #include "windowMap.h"
22 #include "ui_mainWindow.h"
27 #include <QMessageBox>
29 MainWindow::MainWindow(QWidget *parent)
30 : QMainWindow(parent), ui(new Ui::MainWindow)
34 log = new Log(this,"gpssniffer.log",DEBUG_VERBOSITY);
36 settings = new Settings(log);
39 windowMap = new WindowMap(this,settings,log);
40 windowMap->setWindowTitle(tr("GPSSniffer->Activity"));
43 //log->debug("log and windowMap created!");
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);
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()));
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()));
71 //ui->tracksButton->setStyleSheet(ui->tracksButton->styleSheet().append("border-radius: 20px"));
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);
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);
89 MainWindow::~MainWindow()
91 qDebug()<< "destructor MainWindow";
93 qDebug() << "ui deleted";
95 qDebug() << "windowMap deleted";
97 qDebug()<< "destructor end";
100 void MainWindow::quit(){
104 void MainWindow::configureSettings(){
109 void MainWindow::tracks(){
110 log->debug("Load tracks window...");
112 windowMap = new WindowMap(this,settings,log);
114 windowMap->setOrientation(WindowMap::ScreenOrientationAuto);
115 windowMap->setWindowTitle(tr("GPSSniffer->Activity"));
116 windowMap->setMode(Mode_LoadTracksWindow);
117 windowMap->setMenuLoadTracks();
118 windowMap->showExpanded();
122 void MainWindow::simulate(){
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()));
133 windowMap->showExpanded();
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();
151 void MainWindow::setOrientation(ScreenOrientation orientation)
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");
163 #endif // Q_OS_SYMBIAN
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);
172 case ScreenOrientationLockLandscape:
173 attribute = static_cast<Qt::WidgetAttribute>(129);
176 case ScreenOrientationAuto:
177 attribute = static_cast<Qt::WidgetAttribute>(130);
179 #else // QT_VERSION < 0x040702
180 case ScreenOrientationLockPortrait:
181 attribute = Qt::WA_LockPortraitOrientation;
183 case ScreenOrientationLockLandscape:
184 attribute = Qt::WA_LockLandscapeOrientation;
187 case ScreenOrientationAuto:
188 attribute = Qt::WA_AutoOrientation;
190 #endif // QT_VERSION < 0x040702
192 setAttribute(attribute, true);
196 void MainWindow::showExpanded()
200 #elif defined(Q_WS_MAEMO_5)
207 void MainWindow::closeEvent(QCloseEvent *event){