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";
107 delete timerSatellitePicture;
108 delete timerRoutePicture;
109 delete pixmapRouteStop;
110 delete pixmapRouteStart;
111 delete iconRouteStop;
112 delete iconRouteStart;
118 void RouteSaveDialog::changeEvent(QEvent *e)
120 QDialog::changeEvent(e);
122 case QEvent::LanguageChange:
123 ui->retranslateUi(this);
131 * Draws compass to the UI
134 void RouteSaveDialog::paintEvent(QPaintEvent *)
136 QPainter painter(this);
138 painter.setRenderHint(QPainter::Antialiasing, true);
139 painter.setPen(QPen((Qt::gray),2));
141 painter.drawEllipse(arrowStartEast.x() - 30, arrowStartEast.y() - 50, 100, 100);
144 font.setPixelSize(26);
145 painter.setFont(font);
146 painter.drawText(arrowStartNorth.x() - 10, arrowEndNorth.y() - 45, "N");
147 painter.drawText(arrowStartEast.x() - 65, arrowStartEast.y() + 5, "W");
148 painter.drawText(arrowStartNorth.x()-10, arrowStartNorth.y()+55, "S");
149 painter.drawText(arrowEndEast.x() + 40, arrowEndEast.y() + 5, "E");
151 font.setPixelSize(12);
152 painter.setFont(font);
153 painter.drawText(arrowStartNorth.x() + 40, arrowEndNorth.y() - 25, "NE");
154 painter.drawText(arrowStartNorth.x() + 40, arrowStartEast.y() + 45, "SE");
155 painter.drawText(arrowStartEast.x() - 45, arrowStartEast.y() + 45, "SW");
156 painter.drawText(arrowStartEast.x() - 45, arrowEndNorth.y() - 25, "NW");
158 if (direction >= 67.5 && direction <= 112.5)
161 painter.drawLine(arrowStartEast, arrowEndEast);
162 painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()-5);
163 painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()+5);
166 else if (direction <= 292.5 && direction >= 247.5)
169 painter.drawLine(arrowStartEast, arrowEndEast);
170 painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowEndEast.y()-5);
171 painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowStartEast.y()+5);
174 else if (direction <= 202.5 && direction >= 157.5)
177 painter.drawLine(arrowStartNorth, arrowEndNorth);
178 painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()-5, arrowStartNorth.y()-10);
179 painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()+5, arrowStartNorth.y()-10);
182 else if (direction > 22.5 && direction < 67.5)
185 painter.drawLine(arrowStartNortheast, arrowEndNortheast);
186 painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x()-10, arrowEndNortheast.y());
187 painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x(), arrowEndNortheast.y()+10);
190 else if (direction > 202.5 && direction < 247.5)
193 painter.drawLine(arrowStartNortheast, arrowEndNortheast);
194 painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x(), arrowStartNortheast.y() - 10);
195 painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x() + 10, arrowStartNortheast.y());
198 else if (direction > 292.5 && direction < 336.5)
201 painter.drawLine(arrowStartNorthwest, arrowEndNorthwest);
202 painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x(), arrowEndNorthwest.y()+10);
203 painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x()+10, arrowEndNorthwest.y());
206 else if (direction > 112.5 && direction < 157.5)
209 painter.drawLine(arrowStartNorthwest, arrowEndNorthwest);
210 painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x(), arrowStartNorthwest.y()-10);
211 painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x()-10, arrowStartNorthwest.y());
217 painter.drawLine(arrowStartNorth, arrowEndNorth);
218 painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()-5, arrowEndNorth.y()+10);
219 painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()+5, arrowEndNorth.y()+10);
224 *This slot function is called when route start/stop button clicked.
226 void RouteSaveDialog::on_buttonRouteStartStop_clicked()
228 if ( buttonStatus == true )//If start button clicked
230 qDebug() << "__start button clicked";
238 buttonStatus = false;
239 ui->buttonRouteStartStop->setIcon(*iconRouteStop);
240 location->startPollingGPS();
243 else //If stop button clicked
245 qDebug() << "__stop button clicked";
247 ui->buttonRouteStartStop->setIcon(*iconRouteStart);
249 //Satellite picture and label
250 ui->labelRouteSatelliteStatus->setText("Searching satellite");
251 ui->labelRouteSatelliteStatus->setVisible(0);
252 ui->labelRouteSatellitePicture->setVisible(0);
253 timerSatellitePicture->stop();
255 //Route picture and label
256 ui->labelRouteStatus->setVisible(0);
257 ui->labelRoutePicture->setVisible(0);
258 timerRoutePicture->stop();
259 location->stopPollingGPS();
263 calibrateDialog = new CalibrateDialog();
265 calibrateDialog->show();
266 calibrateDialog->resetProgressValue();
269 calibrateDialog->setMaxValue( points + 1 );
272 calibrateDialog->setProgressValue(iteration);
275 } while(iteration != points);*/
277 QString routeFile = QString("routetemp.xml");
278 if (routeDialog->readRouteFromFile( routeFile , calibrateDialog) == true)
281 routeDialog = new RouteDialog(this);
282 connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute()));
284 calibrateDialog->close();
289 calibrateDialog->close();
292 //Set GPS speed labels in visible
293 ui->labelGpsSpeed->setVisible(0);
294 ui->labelGpsAvgSpeed->setVisible(0);
297 ui->labelDistance->setVisible(0);
299 //Stop route recording
300 gpsData->stopRouteRecording();
303 ui->labelUserInfo->setText("Push start button");
308 * This slot function is called when satellite picture timer timeout(400ms).
310 void RouteSaveDialog::timerSatellitePictureTimeout()
312 //If satellite picture visible.
313 if (ui->labelRouteSatellitePicture->isVisible() == 1)
315 ui->labelRouteSatelliteStatus->setVisible(0);
316 ui->labelRouteSatellitePicture->setVisible(0);
320 ui->labelRouteSatelliteStatus->setVisible(1);
321 ui->labelRouteSatellitePicture->setVisible(1);
323 timerSatellitePicture->start();
327 * This slot function is called when route picture timer timeout(400ms).
329 void RouteSaveDialog::timerRoutePictureTimeout()
331 //If route picture visible.
332 if (ui->labelRoutePicture->isVisible() == 1)
334 ui->labelRouteStatus->setVisible(0);
335 ui->labelRoutePicture->setVisible(0);
339 ui->labelRouteStatus->setVisible(1);
340 ui->labelRoutePicture->setVisible(1);
342 timerRoutePicture->start();
346 * This slot function is called when GPS update location.
348 void RouteSaveDialog::gpsStatus()
350 //IF GPS start button clicked
351 if (buttonStatus == false)
353 //ui->labelSignalStrength->setText(QString::number(location->getSignalStrength())); //Returns average signal strength of satellites which are in use.
355 //If GPS find 4 or more satellite and signal stregth is 30 or more.
356 if (location->getSatellitesInUse() >= 4 && location->getSignalStrength() >= 30)
358 //Satellite picture and label
359 ui->labelRouteSatelliteStatus->setText("GPS Ready");
360 ui->labelRouteSatelliteStatus->setVisible(1);
361 ui->labelRouteSatellitePicture->setVisible(1);
362 timerSatellitePicture->stop();
364 //Route picture and label
365 ui->labelRouteStatus->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
366 ui->labelUserInfo->setText("Recorded " + QString::number(gpsData->roundCounter) + " route point");
367 ui->labelRouteStatus->setVisible(1);
368 ui->labelRoutePicture->setVisible(1);
369 timerRoutePicture->start();
372 speed = location->getSpeed();
374 //Get GPS track means direction
375 direction = gpsData->getDirection();
379 gpsSpeed.sprintf("%.0f", speed);
380 ui->labelGpsSpeed->setText(gpsSpeed + " km/h");
381 ui->labelGpsSpeed->setVisible(1);
383 //Set GPS average speed
385 averageSpeed = allSpeeds/speedCount;
386 gpsSpeed.sprintf("%.0f",averageSpeed);
387 ui->labelGpsAvgSpeed->setText("Avg: " + gpsSpeed + " km/h");
388 ui->labelGpsAvgSpeed->setVisible(1);
391 //Set distance traveled.
392 distanceString.sprintf("%.3f", gpsData->getDistanceTraveled());
393 ui->labelDistance->setText(distanceString + " km");
394 ui->labelDistance->setVisible(1);
396 //Start route recording
397 gpsData->startRouteRecording();
399 else //If GPS find less than 4 satellite or signal strength is poor.
401 //Satellite picture and label
402 ui->labelRouteSatelliteStatus->setText("Searching satellite");
403 ui->labelUserInfo->setText("Searching satellite");
404 ui->labelRouteSatelliteStatus->setVisible(1);
405 ui->labelRouteSatellitePicture->setVisible(1);
406 timerSatellitePicture->start();
408 //Route picture and label
409 ui->labelRouteStatus->setVisible(0);
410 ui->labelRoutePicture->setVisible(0);
411 timerRoutePicture->stop();
413 //Set GPS speed labels in visible
414 ui->labelGpsSpeed->setVisible(0);
415 ui->labelGpsAvgSpeed->setVisible(0);
418 ui->labelDistance->setVisible(0);
421 else //If stop button clicked
423 //Satellite picture and label
424 ui->labelRouteSatelliteStatus->setText("Searching satellite");
425 ui->labelUserInfo->setText("Push start button");
426 ui->labelRouteSatelliteStatus->setVisible(0);
427 ui->labelRouteSatellitePicture->setVisible(0);
428 timerSatellitePicture->stop();
430 //Route picture and label
431 ui->labelRouteStatus->setVisible(0);
432 ui->labelRoutePicture->setVisible(0);
433 timerRoutePicture->stop();
435 //Set GPS speed labels in visible
436 ui->labelGpsSpeed->setVisible(0);
437 ui->labelGpsAvgSpeed->setVisible(0);
440 ui->labelDistance->setVisible(0);
445 * This slot function is called when routeDialog emit sendroute (sendPushButton).
447 void RouteSaveDialog::sendRoute()
449 emit sendroute(); //Emit mainwindow clientSendRoute
453 * This slot function called when ever info button clicked.
455 void RouteSaveDialog::on_pushButtonInfo_clicked()
457 if(!helpRoutingDialog)
459 helpRoutingDialog = new HelpRoutingDialog;
461 connect(helpRoutingDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
462 helpRoutingDialog->show();
466 * This slot function called when ever dialog rejected.
468 void RouteSaveDialog::killHelpDialog()
470 if(helpRoutingDialog)
472 qDebug() << "__Route save kill: helpRoutingDialog";
473 delete helpRoutingDialog;
474 helpRoutingDialog = NULL;
479 * This function return speed average.
480 * @return double average speed
482 double RouteSaveDialog::getAverageSpeed()
488 * This function return distance traveled in QString.
489 * @return QString distance traveled
491 QString RouteSaveDialog::getDistanceTraveled()
493 return distanceString;