2 * Route save dialog class
4 * @author Toni Jussila <toni.jussila@fudeco.com>
5 * @copyright (c) 2010 Speed Freak team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 #include "routesavedialog.h"
10 #include "ui_routesavedialog.h"
13 #include <QFileDialog>
15 const QPoint arrowStartEast(100, 100);
16 const QPoint arrowEndEast(140, 100);
18 const QPoint arrowStartNorth(120, 120);
19 const QPoint arrowEndNorth(120, 80);
21 const QPoint arrowStartNortheast(100, 120);
22 const QPoint arrowEndNortheast(140, 80);
24 const QPoint arrowStartNorthwest(140, 120);
25 const QPoint arrowEndNorthwest(100, 80);
28 * Constructor of this class.
29 * @param QWidget pointer to parent object. By default the value is NULL.
31 RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
32 QDialog(parent), ui(new Ui::RouteSaveDialog){
34 qDebug() << "__RouteSaveDialog";
36 this->setWindowTitle("Tracking");
41 helpRoutingDialog = NULL;
42 calibrateDialog = NULL;
53 pixmapRouteStop = new QPixmap("Graphics/route_stop.png");
54 pixmapRouteStart = new QPixmap("Graphics/route_start.png");
55 iconRouteStop = new QIcon(*pixmapRouteStop);
56 iconRouteStart = new QIcon(*pixmapRouteStart);
57 QSize iconSize(125, 125);
58 ui->buttonRouteStartStop->setIconSize(iconSize);
59 ui->buttonRouteStartStop->setIcon(*iconRouteStart);
60 ui->buttonRouteStartStop->setAutoFillBackground(true);
61 ui->buttonRouteStartStop->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
62 ui->pushButtonInfo->setAutoFillBackground(true);
63 ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
65 //Satellite picture and label
66 ui->labelRouteSatelliteStatus->setVisible(0);
67 ui->labelRouteSatellitePicture->setVisible(0);
68 //ui->labelRouteSatellitePicture->setPixmap(QPixmap("Graphics/satellite_vista.png"));
69 timerSatellitePicture = new QTimer();
70 timerSatellitePicture->setInterval(400);
71 connect(timerSatellitePicture, SIGNAL(timeout()),this, SLOT(timerSatellitePictureTimeout()));
72 ui->labelUserInfo->setText("Push start button"); //User info label
74 //Invisible or clear labels
75 ui->labelRouteStatus->setVisible(0);
76 ui->labelRoutePicture->setVisible(0);
77 ui->labelGpsSpeed->setVisible(0); //GPS speed label
78 ui->labelGpsAvgSpeed->setVisible(0); //GPS average speed label
79 ui->labelDistance->setVisible(0); //GPS distance label
80 ui->labelSignalStrength->setText(""); //GPS signal strength label
83 timerRoutePicture = new QTimer();
84 timerRoutePicture->setInterval(400);
85 connect(timerRoutePicture, SIGNAL(timeout()),this, SLOT(timerRoutePictureTimeout()));
88 location = new Maemo5Location(this);
89 gpsData = new GPSData(location);
90 connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
94 * Destructor of this class. Deletes all dynamic objects and sets them to NULL.
96 RouteSaveDialog::~RouteSaveDialog()
98 qDebug() << "__~RouteSaveDialog";
109 delete calibrateDialog;
110 calibrateDialog = NULL;
113 delete timerSatellitePicture;
114 delete timerRoutePicture;
115 delete pixmapRouteStop;
116 delete pixmapRouteStart;
117 delete iconRouteStop;
118 delete iconRouteStart;
124 void RouteSaveDialog::changeEvent(QEvent *e)
126 QDialog::changeEvent(e);
128 case QEvent::LanguageChange:
129 ui->retranslateUi(this);
137 * Draws compass to the UI
140 void RouteSaveDialog::paintEvent(QPaintEvent *)
142 QPainter painter(this);
144 painter.setRenderHint(QPainter::Antialiasing, true);
145 painter.setPen(QPen((Qt::gray),2));
147 painter.drawEllipse(arrowStartEast.x() - 30, arrowStartEast.y() - 50, 100, 100);
150 font.setPixelSize(26);
151 painter.setFont(font);
152 painter.drawText(arrowStartNorth.x() - 10, arrowEndNorth.y() - 45, "N");
153 painter.drawText(arrowStartEast.x() - 65, arrowStartEast.y() + 5, "W");
154 painter.drawText(arrowStartNorth.x()-10, arrowStartNorth.y()+55, "S");
155 painter.drawText(arrowEndEast.x() + 40, arrowEndEast.y() + 5, "E");
157 font.setPixelSize(12);
158 painter.setFont(font);
159 painter.drawText(arrowStartNorth.x() + 40, arrowEndNorth.y() - 25, "NE");
160 painter.drawText(arrowStartNorth.x() + 40, arrowStartEast.y() + 45, "SE");
161 painter.drawText(arrowStartEast.x() - 45, arrowStartEast.y() + 45, "SW");
162 painter.drawText(arrowStartEast.x() - 45, arrowEndNorth.y() - 25, "NW");
164 if (direction >= 67.5 && direction <= 112.5)
167 painter.drawLine(arrowStartEast, arrowEndEast);
168 painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()-5);
169 painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()+5);
172 else if (direction <= 292.5 && direction >= 247.5)
175 painter.drawLine(arrowStartEast, arrowEndEast);
176 painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowEndEast.y()-5);
177 painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowStartEast.y()+5);
180 else if (direction <= 202.5 && direction >= 157.5)
183 painter.drawLine(arrowStartNorth, arrowEndNorth);
184 painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()-5, arrowStartNorth.y()-10);
185 painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()+5, arrowStartNorth.y()-10);
188 else if (direction > 22.5 && direction < 67.5)
191 painter.drawLine(arrowStartNortheast, arrowEndNortheast);
192 painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x()-10, arrowEndNortheast.y());
193 painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x(), arrowEndNortheast.y()+10);
196 else if (direction > 202.5 && direction < 247.5)
199 painter.drawLine(arrowStartNortheast, arrowEndNortheast);
200 painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x(), arrowStartNortheast.y() - 10);
201 painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x() + 10, arrowStartNortheast.y());
204 else if (direction > 292.5 && direction < 336.5)
207 painter.drawLine(arrowStartNorthwest, arrowEndNorthwest);
208 painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x(), arrowEndNorthwest.y()+10);
209 painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x()+10, arrowEndNorthwest.y());
212 else if (direction > 112.5 && direction < 157.5)
215 painter.drawLine(arrowStartNorthwest, arrowEndNorthwest);
216 painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x(), arrowStartNorthwest.y()-10);
217 painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x()-10, arrowStartNorthwest.y());
223 painter.drawLine(arrowStartNorth, arrowEndNorth);
224 painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()-5, arrowEndNorth.y()+10);
225 painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()+5, arrowEndNorth.y()+10);
230 *This slot function is called when route start/stop button clicked.
232 void RouteSaveDialog::on_buttonRouteStartStop_clicked()
234 if ( buttonStatus == true )//If start button clicked
236 qDebug() << "__start button clicked";
244 buttonStatus = false;
245 ui->buttonRouteStartStop->setIcon(*iconRouteStop);
246 location->startPollingGPS();
249 else //If stop button clicked
251 qDebug() << "__stop button clicked";
253 ui->buttonRouteStartStop->setIcon(*iconRouteStart);
255 //Satellite picture and label
256 ui->labelRouteSatelliteStatus->setText("Searching satellite");
257 ui->labelRouteSatelliteStatus->setVisible(0);
258 ui->labelRouteSatellitePicture->setVisible(0);
259 timerSatellitePicture->stop();
261 //Route picture and label
262 ui->labelRouteStatus->setVisible(0);
263 ui->labelRoutePicture->setVisible(0);
264 timerRoutePicture->stop();
265 location->stopPollingGPS();
267 //Set GPS speed labels in visible
268 ui->labelGpsSpeed->setVisible(0);
269 ui->labelGpsAvgSpeed->setVisible(0);
272 ui->labelDistance->setVisible(0);
274 //Stop route recording
275 gpsData->stopRouteRecording();
278 ui->labelUserInfo->setText("Push start button");
280 openRouteDialog("routetemp.xml");
285 * This slot function is called when satellite picture timer timeout(400ms).
287 void RouteSaveDialog::timerSatellitePictureTimeout()
289 //If satellite picture visible.
290 if (ui->labelRouteSatellitePicture->isVisible() == 1)
292 ui->labelRouteSatelliteStatus->setVisible(0);
293 ui->labelRouteSatellitePicture->setVisible(0);
297 ui->labelRouteSatelliteStatus->setVisible(1);
298 ui->labelRouteSatellitePicture->setVisible(1);
300 timerSatellitePicture->start();
304 * This slot function is called when route picture timer timeout(400ms).
306 void RouteSaveDialog::timerRoutePictureTimeout()
308 //If route picture visible.
309 if (ui->labelRoutePicture->isVisible() == 1)
311 ui->labelRouteStatus->setVisible(0);
312 ui->labelRoutePicture->setVisible(0);
316 ui->labelRouteStatus->setVisible(1);
317 ui->labelRoutePicture->setVisible(1);
319 timerRoutePicture->start();
323 * This slot function is called when GPS update location.
325 void RouteSaveDialog::gpsStatus()
327 //IF GPS start button clicked
328 if (buttonStatus == false)
330 //ui->labelSignalStrength->setText(QString::number(location->getSignalStrength())); //Returns average signal strength of satellites which are in use.
332 //If GPS find 4 or more satellite and signal stregth is 30 or more.
333 if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
335 //Satellite picture and label
336 ui->labelRouteSatelliteStatus->setText("GPS Ready");
337 ui->labelRouteSatelliteStatus->setVisible(1);
338 ui->labelRouteSatellitePicture->setVisible(1);
339 timerSatellitePicture->stop();
341 //Route picture and label
342 ui->labelRouteStatus->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
343 ui->labelUserInfo->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
344 ui->labelRouteStatus->setVisible(1);
345 ui->labelRoutePicture->setVisible(1);
346 timerRoutePicture->start();
349 speed = location->getSpeed();
351 //Get GPS track means direction
352 direction = gpsData->getDirection();
356 gpsSpeed.sprintf("%.0f", speed);
357 ui->labelGpsSpeed->setText(gpsSpeed + " km/h");
358 ui->labelGpsSpeed->setVisible(1);
360 //Set GPS average speed
362 averageSpeed = allSpeeds/speedCount;
363 gpsSpeed.sprintf("%.0f",averageSpeed);
364 ui->labelGpsAvgSpeed->setText("Avg: " + gpsSpeed + " km/h");
365 ui->labelGpsAvgSpeed->setVisible(1);
368 //Set distance traveled.
369 distanceString.sprintf("%.3f", gpsData->getDistanceTraveled());
370 ui->labelDistance->setText(distanceString + " km");
371 ui->labelDistance->setVisible(1);
373 //Start route recording
374 gpsData->startRouteRecording();
376 else //If GPS find less than 4 satellite or signal strength is poor.
378 //Satellite picture and label
379 ui->labelRouteSatelliteStatus->setText("Searching satellite");
380 ui->labelUserInfo->setText("Searching satellite");
381 ui->labelRouteSatelliteStatus->setVisible(1);
382 ui->labelRouteSatellitePicture->setVisible(1);
383 timerSatellitePicture->start();
385 //Route picture and label
386 ui->labelRouteStatus->setVisible(0);
387 ui->labelRoutePicture->setVisible(0);
388 timerRoutePicture->stop();
390 //Set GPS speed labels in visible
391 ui->labelGpsSpeed->setVisible(0);
392 ui->labelGpsAvgSpeed->setVisible(0);
395 ui->labelDistance->setVisible(0);
398 else //If stop button clicked
400 //Satellite picture and label
401 ui->labelRouteSatelliteStatus->setText("Searching satellite");
402 ui->labelUserInfo->setText("Push start button");
403 ui->labelRouteSatelliteStatus->setVisible(0);
404 ui->labelRouteSatellitePicture->setVisible(0);
405 timerSatellitePicture->stop();
407 //Route picture and label
408 ui->labelRouteStatus->setVisible(0);
409 ui->labelRoutePicture->setVisible(0);
410 timerRoutePicture->stop();
412 //Set GPS speed labels in visible
413 ui->labelGpsSpeed->setVisible(0);
414 ui->labelGpsAvgSpeed->setVisible(0);
417 ui->labelDistance->setVisible(0);
422 * This slot function is called when routeDialog emit sendroute (sendPushButton).
424 void RouteSaveDialog::sendRoute()
426 emit sendroute(); //Emit mainwindow clientSendRoute
430 * This slot function called when ever info button clicked.
432 void RouteSaveDialog::on_pushButtonInfo_clicked()
434 if(!helpRoutingDialog)
436 helpRoutingDialog = new HelpRoutingDialog;
438 connect(helpRoutingDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
439 helpRoutingDialog->show();
443 * This slot function called when ever dialog rejected.
445 void RouteSaveDialog::killHelpDialog()
447 if(helpRoutingDialog)
449 qDebug() << "__Route save kill: helpRoutingDialog";
450 delete helpRoutingDialog;
451 helpRoutingDialog = NULL;
456 * This slot function called when ever route dialog rejected.
458 void RouteSaveDialog::killRouteDialog()
462 qDebug() << "__Route save kill: routeDialog";
468 qDebug() << "__Route save kill: calibrateDialog";
469 delete calibrateDialog;
470 calibrateDialog = NULL;
475 * This function return speed average.
476 * @return double average speed
478 double RouteSaveDialog::getAverageSpeed()
484 * This function return distance traveled in QString.
485 * @return QString distance traveled
487 QString RouteSaveDialog::getDistanceTraveled()
489 return distanceString;
495 void RouteSaveDialog::setProgressbar(int i)
497 qDebug() << "__setProgressbar " ;
499 calibrateDialog->setProgressValue(i);
500 progressbarIteration++;
504 * This slot function called when ever load route button clicked.
506 void RouteSaveDialog::on_buttonLoadRoute_clicked()
508 QString fileName = QFileDialog::getOpenFileName(this, tr("Open route"), QDir::currentPath());
509 qDebug() << "__Opening: " + fileName;
510 openRouteDialog(fileName);
514 * This function open route.
515 * @param QString file name
517 void RouteSaveDialog::openRouteDialog(QString fileName)
522 calibrateDialog = new CalibrateDialog();
525 progressbarPoints = 100;
526 progressbarIteration = 0;
527 calibrateDialog->resetProgressValue();
528 calibrateDialog->setMaxValue( progressbarPoints );
529 calibrateDialog->setTitle("Calculating route...");
530 calibrateDialog->show();
534 routeDialog = new RouteDialog(this);
537 connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute()));
538 connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int)));
539 connect(routeDialog, SIGNAL(rejected()), this, SLOT(killRouteDialog()));
541 if (routeDialog->readRouteFromFile( fileName ) == true)
543 calibrateDialog->close();
548 calibrateDialog->close();