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"
14 const QPoint arrowStartEast(100, 100);
15 const QPoint arrowEndEast(140, 100);
17 const QPoint arrowStartNorth(120, 120);
18 const QPoint arrowEndNorth(120, 80);
20 const QPoint arrowStartNortheast(100, 120);
21 const QPoint arrowEndNortheast(140, 80);
23 const QPoint arrowStartNorthwest(140, 120);
24 const QPoint arrowEndNorthwest(100, 80);
27 * Constructor of this class.
28 * @param QWidget pointer to parent object. By default the value is NULL.
30 RouteSaveDialog::RouteSaveDialog(QWidget *parent) :
31 QDialog(parent), ui(new Ui::RouteSaveDialog){
33 qDebug() << "__RouteSaveDialog";
35 this->setWindowTitle("Tracking");
40 helpRoutingDialog = NULL;
41 calibrateDialog = NULL;
52 pixmapRouteStop = new QPixmap("Graphics/route_stop.png");
53 pixmapRouteStart = new QPixmap("Graphics/route_start.png");
54 iconRouteStop = new QIcon(*pixmapRouteStop);
55 iconRouteStart = new QIcon(*pixmapRouteStart);
56 QSize iconSize(125, 125);
57 ui->buttonRouteStartStop->setIconSize(iconSize);
58 ui->buttonRouteStartStop->setIcon(*iconRouteStart);
59 ui->buttonRouteStartStop->setAutoFillBackground(true);
60 ui->buttonRouteStartStop->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
61 ui->pushButtonInfo->setAutoFillBackground(true);
62 ui->pushButtonInfo->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
64 //Satellite picture and label
65 ui->labelRouteSatelliteStatus->setVisible(0);
66 ui->labelRouteSatellitePicture->setVisible(0);
67 //ui->labelRouteSatellitePicture->setPixmap(QPixmap("Graphics/satellite_vista.png"));
68 timerSatellitePicture = new QTimer();
69 timerSatellitePicture->setInterval(400);
70 connect(timerSatellitePicture, SIGNAL(timeout()),this, SLOT(timerSatellitePictureTimeout()));
71 ui->labelUserInfo->setText("Push start button"); //User info label
73 //Invisible or clear labels
74 ui->labelRouteStatus->setVisible(0);
75 ui->labelRoutePicture->setVisible(0);
76 ui->labelGpsSpeed->setVisible(0); //GPS speed label
77 ui->labelGpsAvgSpeed->setVisible(0); //GPS average speed label
78 ui->labelDistance->setVisible(0); //GPS distance label
79 ui->labelSignalStrength->setText(""); //GPS signal strength label
82 timerRoutePicture = new QTimer();
83 timerRoutePicture->setInterval(400);
84 connect(timerRoutePicture, SIGNAL(timeout()),this, SLOT(timerRoutePictureTimeout()));
87 location = new Maemo5Location(this);
88 gpsData = new GPSData(location);
89 connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
93 * Destructor of this class. Deletes all dynamic objects and sets them to NULL.
95 RouteSaveDialog::~RouteSaveDialog()
97 qDebug() << "__~RouteSaveDialog";
108 delete calibrateDialog;
109 calibrateDialog = NULL;
112 delete timerSatellitePicture;
113 delete timerRoutePicture;
114 delete pixmapRouteStop;
115 delete pixmapRouteStart;
116 delete iconRouteStop;
117 delete iconRouteStart;
123 void RouteSaveDialog::changeEvent(QEvent *e)
125 QDialog::changeEvent(e);
127 case QEvent::LanguageChange:
128 ui->retranslateUi(this);
136 * Draws compass to the UI
139 void RouteSaveDialog::paintEvent(QPaintEvent *)
141 QPainter painter(this);
143 painter.setRenderHint(QPainter::Antialiasing, true);
144 painter.setPen(QPen((Qt::gray),2));
146 painter.drawEllipse(arrowStartEast.x() - 30, arrowStartEast.y() - 50, 100, 100);
149 font.setPixelSize(26);
150 painter.setFont(font);
151 painter.drawText(arrowStartNorth.x() - 10, arrowEndNorth.y() - 45, "N");
152 painter.drawText(arrowStartEast.x() - 65, arrowStartEast.y() + 5, "W");
153 painter.drawText(arrowStartNorth.x()-10, arrowStartNorth.y()+55, "S");
154 painter.drawText(arrowEndEast.x() + 40, arrowEndEast.y() + 5, "E");
156 font.setPixelSize(12);
157 painter.setFont(font);
158 painter.drawText(arrowStartNorth.x() + 40, arrowEndNorth.y() - 25, "NE");
159 painter.drawText(arrowStartNorth.x() + 40, arrowStartEast.y() + 45, "SE");
160 painter.drawText(arrowStartEast.x() - 45, arrowStartEast.y() + 45, "SW");
161 painter.drawText(arrowStartEast.x() - 45, arrowEndNorth.y() - 25, "NW");
163 if (direction >= 67.5 && direction <= 112.5)
166 painter.drawLine(arrowStartEast, arrowEndEast);
167 painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()-5);
168 painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()+5);
171 else if (direction <= 292.5 && direction >= 247.5)
174 painter.drawLine(arrowStartEast, arrowEndEast);
175 painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowEndEast.y()-5);
176 painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowStartEast.y()+5);
179 else if (direction <= 202.5 && direction >= 157.5)
182 painter.drawLine(arrowStartNorth, arrowEndNorth);
183 painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()-5, arrowStartNorth.y()-10);
184 painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()+5, arrowStartNorth.y()-10);
187 else if (direction > 22.5 && direction < 67.5)
190 painter.drawLine(arrowStartNortheast, arrowEndNortheast);
191 painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x()-10, arrowEndNortheast.y());
192 painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x(), arrowEndNortheast.y()+10);
195 else if (direction > 202.5 && direction < 247.5)
198 painter.drawLine(arrowStartNortheast, arrowEndNortheast);
199 painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x(), arrowStartNortheast.y() - 10);
200 painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x() + 10, arrowStartNortheast.y());
203 else if (direction > 292.5 && direction < 336.5)
206 painter.drawLine(arrowStartNorthwest, arrowEndNorthwest);
207 painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x(), arrowEndNorthwest.y()+10);
208 painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x()+10, arrowEndNorthwest.y());
211 else if (direction > 112.5 && direction < 157.5)
214 painter.drawLine(arrowStartNorthwest, arrowEndNorthwest);
215 painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x(), arrowStartNorthwest.y()-10);
216 painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x()-10, arrowStartNorthwest.y());
222 painter.drawLine(arrowStartNorth, arrowEndNorth);
223 painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()-5, arrowEndNorth.y()+10);
224 painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()+5, arrowEndNorth.y()+10);
229 *This slot function is called when route start/stop button clicked.
231 void RouteSaveDialog::on_buttonRouteStartStop_clicked()
233 if ( buttonStatus == true )//If start button clicked
235 qDebug() << "__start button clicked";
243 buttonStatus = false;
244 ui->buttonRouteStartStop->setIcon(*iconRouteStop);
245 location->startPollingGPS();
248 else //If stop button clicked
250 qDebug() << "__stop button clicked";
252 ui->buttonRouteStartStop->setIcon(*iconRouteStart);
254 //Satellite picture and label
255 ui->labelRouteSatelliteStatus->setText("Searching satellite");
256 ui->labelRouteSatelliteStatus->setVisible(0);
257 ui->labelRouteSatellitePicture->setVisible(0);
258 timerSatellitePicture->stop();
260 //Route picture and label
261 ui->labelRouteStatus->setVisible(0);
262 ui->labelRoutePicture->setVisible(0);
263 timerRoutePicture->stop();
264 location->stopPollingGPS();
269 calibrateDialog = new CalibrateDialog();
272 progressbarPoints = 100;
273 progressbarIteration = 0;
274 calibrateDialog->resetProgressValue();
275 calibrateDialog->setMaxValue( progressbarPoints );
276 calibrateDialog->setTitle("Calculating route...");
277 calibrateDialog->show();
282 routeDialog = new RouteDialog(this);
285 connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute()));
286 connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int)));
287 connect(routeDialog, SIGNAL(rejected()), this, SLOT(killRouteDialog()));
288 //connect(routeDialog, SIGNAL(killRoute()), this, SLOT(killRouteDialog()));
290 QString routeFile = QString("routetemp.xml");
291 if (routeDialog->readRouteFromFile( routeFile ) == true)
293 //calibrateDialog->close();
298 //calibrateDialog->close();
300 calibrateDialog->close();
301 //Set GPS speed labels in visible
302 ui->labelGpsSpeed->setVisible(0);
303 ui->labelGpsAvgSpeed->setVisible(0);
306 ui->labelDistance->setVisible(0);
308 //Stop route recording
309 gpsData->stopRouteRecording();
312 ui->labelUserInfo->setText("Push start button");
317 * This slot function is called when satellite picture timer timeout(400ms).
319 void RouteSaveDialog::timerSatellitePictureTimeout()
321 //If satellite picture visible.
322 if (ui->labelRouteSatellitePicture->isVisible() == 1)
324 ui->labelRouteSatelliteStatus->setVisible(0);
325 ui->labelRouteSatellitePicture->setVisible(0);
329 ui->labelRouteSatelliteStatus->setVisible(1);
330 ui->labelRouteSatellitePicture->setVisible(1);
332 timerSatellitePicture->start();
336 * This slot function is called when route picture timer timeout(400ms).
338 void RouteSaveDialog::timerRoutePictureTimeout()
340 //If route picture visible.
341 if (ui->labelRoutePicture->isVisible() == 1)
343 ui->labelRouteStatus->setVisible(0);
344 ui->labelRoutePicture->setVisible(0);
348 ui->labelRouteStatus->setVisible(1);
349 ui->labelRoutePicture->setVisible(1);
351 timerRoutePicture->start();
355 * This slot function is called when GPS update location.
357 void RouteSaveDialog::gpsStatus()
359 //IF GPS start button clicked
360 if (buttonStatus == false)
362 //ui->labelSignalStrength->setText(QString::number(location->getSignalStrength())); //Returns average signal strength of satellites which are in use.
364 //If GPS find 4 or more satellite and signal stregth is 30 or more.
365 if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
367 //Satellite picture and label
368 ui->labelRouteSatelliteStatus->setText("GPS Ready");
369 ui->labelRouteSatelliteStatus->setVisible(1);
370 ui->labelRouteSatellitePicture->setVisible(1);
371 timerSatellitePicture->stop();
373 //Route picture and label
374 ui->labelRouteStatus->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
375 ui->labelUserInfo->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
376 ui->labelRouteStatus->setVisible(1);
377 ui->labelRoutePicture->setVisible(1);
378 timerRoutePicture->start();
381 speed = location->getSpeed();
383 //Get GPS track means direction
384 direction = gpsData->getDirection();
388 gpsSpeed.sprintf("%.0f", speed);
389 ui->labelGpsSpeed->setText(gpsSpeed + " km/h");
390 ui->labelGpsSpeed->setVisible(1);
392 //Set GPS average speed
394 averageSpeed = allSpeeds/speedCount;
395 gpsSpeed.sprintf("%.0f",averageSpeed);
396 ui->labelGpsAvgSpeed->setText("Avg: " + gpsSpeed + " km/h");
397 ui->labelGpsAvgSpeed->setVisible(1);
400 //Set distance traveled.
401 distanceString.sprintf("%.3f", gpsData->getDistanceTraveled());
402 ui->labelDistance->setText(distanceString + " km");
403 ui->labelDistance->setVisible(1);
405 //Start route recording
406 gpsData->startRouteRecording();
408 else //If GPS find less than 4 satellite or signal strength is poor.
410 //Satellite picture and label
411 ui->labelRouteSatelliteStatus->setText("Searching satellite");
412 ui->labelUserInfo->setText("Searching satellite");
413 ui->labelRouteSatelliteStatus->setVisible(1);
414 ui->labelRouteSatellitePicture->setVisible(1);
415 timerSatellitePicture->start();
417 //Route picture and label
418 ui->labelRouteStatus->setVisible(0);
419 ui->labelRoutePicture->setVisible(0);
420 timerRoutePicture->stop();
422 //Set GPS speed labels in visible
423 ui->labelGpsSpeed->setVisible(0);
424 ui->labelGpsAvgSpeed->setVisible(0);
427 ui->labelDistance->setVisible(0);
430 else //If stop button clicked
432 //Satellite picture and label
433 ui->labelRouteSatelliteStatus->setText("Searching satellite");
434 ui->labelUserInfo->setText("Push start button");
435 ui->labelRouteSatelliteStatus->setVisible(0);
436 ui->labelRouteSatellitePicture->setVisible(0);
437 timerSatellitePicture->stop();
439 //Route picture and label
440 ui->labelRouteStatus->setVisible(0);
441 ui->labelRoutePicture->setVisible(0);
442 timerRoutePicture->stop();
444 //Set GPS speed labels in visible
445 ui->labelGpsSpeed->setVisible(0);
446 ui->labelGpsAvgSpeed->setVisible(0);
449 ui->labelDistance->setVisible(0);
454 * This slot function is called when routeDialog emit sendroute (sendPushButton).
456 void RouteSaveDialog::sendRoute()
458 emit sendroute(); //Emit mainwindow clientSendRoute
462 * This slot function called when ever info button clicked.
464 void RouteSaveDialog::on_pushButtonInfo_clicked()
466 if(!helpRoutingDialog)
468 helpRoutingDialog = new HelpRoutingDialog;
470 connect(helpRoutingDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
471 helpRoutingDialog->show();
475 * This slot function called when ever dialog rejected.
477 void RouteSaveDialog::killHelpDialog()
479 if(helpRoutingDialog)
481 qDebug() << "__Route save kill: helpRoutingDialog";
482 delete helpRoutingDialog;
483 helpRoutingDialog = NULL;
488 * This slot function called when ever dialog rejected.
490 void RouteSaveDialog::killRouteDialog()
494 qDebug() << "__Route save kill: routeDialog";
500 qDebug() << "__Route save kill: calibrateDialog";
501 delete calibrateDialog;
502 calibrateDialog = NULL;
507 * This function return speed average.
508 * @return double average speed
510 double RouteSaveDialog::getAverageSpeed()
516 * This function return distance traveled in QString.
517 * @return QString distance traveled
519 QString RouteSaveDialog::getDistanceTraveled()
521 return distanceString;
527 void RouteSaveDialog::setProgressbar(int i)
529 qDebug() << "__setProgressbar " ;//+ i;
531 calibrateDialog->setProgressValue(i);//progressbarIteration);
532 progressbarIteration++;