X-Git-Url: http://git.maemo.org/git/?p=speedfreak;a=blobdiff_plain;f=Client%2Froutesavedialog.cpp;h=53175f4fde531a730906222b6cd168a889ecf969;hp=fcccd5f65e3be1f9b06b3f2c0ad7bba8d7afb7ba;hb=135c535eafa1d10fc76a503efd912ecee78e955e;hpb=3fa5091583bdd9421a4ecd5851d954e9bed58731 diff --git a/Client/routesavedialog.cpp b/Client/routesavedialog.cpp index fcccd5f..53175f4 100644 --- a/Client/routesavedialog.cpp +++ b/Client/routesavedialog.cpp @@ -9,6 +9,21 @@ #include "routesavedialog.h" #include "ui_routesavedialog.h" #include +#include +#include +#include + +const QPoint arrowStartEast(100, 100); +const QPoint arrowEndEast(140, 100); + +const QPoint arrowStartNorth(120, 120); +const QPoint arrowEndNorth(120, 80); + +const QPoint arrowStartNortheast(100, 120); +const QPoint arrowEndNortheast(140, 80); + +const QPoint arrowStartNorthwest(140, 120); +const QPoint arrowEndNorthwest(100, 80); /** * Constructor of this class. @@ -32,6 +47,7 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : speed = 0.0; allSpeeds = 0.0; speedCount = 0; + direction = 0.0; //Button settings buttonStatus = true; @@ -73,6 +89,13 @@ RouteSaveDialog::RouteSaveDialog(QWidget *parent) : location = new Maemo5Location(this); gpsData = new GPSData(location); connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus())); + + // Route folder + QString folder = "speedfreak_route"; + if(!QDir(folder).exists()) + { + QDir().mkdir(folder); + } } /** @@ -89,6 +112,11 @@ RouteSaveDialog::~RouteSaveDialog() delete location; if(routeDialog) delete routeDialog; + if(calibrateDialog) + { + delete calibrateDialog; + calibrateDialog = NULL; + } delete timerSatellitePicture; delete timerRoutePicture; @@ -114,7 +142,100 @@ void RouteSaveDialog::changeEvent(QEvent *e) } /** - * This slot function is called when route start/stop button clicked. + * Draws compass to the UI + * @param QPaintEvent + */ +void RouteSaveDialog::paintEvent(QPaintEvent *) +{ + QPainter painter(this); + + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(QPen((Qt::gray),2)); + + painter.drawEllipse(arrowStartEast.x() - 30, arrowStartEast.y() - 50, 100, 100); + + QFont font; + font.setPixelSize(26); + painter.setFont(font); + painter.drawText(arrowStartNorth.x() - 10, arrowEndNorth.y() - 45, "N"); + painter.drawText(arrowStartEast.x() - 65, arrowStartEast.y() + 5, "W"); + painter.drawText(arrowStartNorth.x()-10, arrowStartNorth.y()+55, "S"); + painter.drawText(arrowEndEast.x() + 40, arrowEndEast.y() + 5, "E"); + + font.setPixelSize(12); + painter.setFont(font); + painter.drawText(arrowStartNorth.x() + 40, arrowEndNorth.y() - 25, "NE"); + painter.drawText(arrowStartNorth.x() + 40, arrowStartEast.y() + 45, "SE"); + painter.drawText(arrowStartEast.x() - 45, arrowStartEast.y() + 45, "SW"); + painter.drawText(arrowStartEast.x() - 45, arrowEndNorth.y() - 25, "NW"); + + if (direction >= 67.5 && direction <= 112.5) + { + // East arrow + painter.drawLine(arrowStartEast, arrowEndEast); + painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()-5); + painter.drawLine(arrowEndEast.x(), arrowEndEast.y(), arrowEndEast.x()-10, arrowEndEast.y()+5); + } + + else if (direction <= 292.5 && direction >= 247.5) + { + // West arrow + painter.drawLine(arrowStartEast, arrowEndEast); + painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowEndEast.y()-5); + painter.drawLine(arrowStartEast.x(), arrowStartEast.y(), arrowStartEast.x()+10, arrowStartEast.y()+5); + } + + else if (direction <= 202.5 && direction >= 157.5) + { + // South arrow + painter.drawLine(arrowStartNorth, arrowEndNorth); + painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()-5, arrowStartNorth.y()-10); + painter.drawLine(arrowStartNorth.x(), arrowStartNorth.y(), arrowStartNorth.x()+5, arrowStartNorth.y()-10); + } + + else if (direction > 22.5 && direction < 67.5) + { + // Northeast arrow + painter.drawLine(arrowStartNortheast, arrowEndNortheast); + painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x()-10, arrowEndNortheast.y()); + painter.drawLine(arrowEndNortheast.x(), arrowEndNortheast.y(), arrowEndNortheast.x(), arrowEndNortheast.y()+10); + } + + else if (direction > 202.5 && direction < 247.5) + { + // Southwest arrow + painter.drawLine(arrowStartNortheast, arrowEndNortheast); + painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x(), arrowStartNortheast.y() - 10); + painter.drawLine(arrowStartNortheast.x(), arrowStartNortheast.y(), arrowStartNortheast.x() + 10, arrowStartNortheast.y()); + } + + else if (direction > 292.5 && direction < 336.5) + { + // Northwest arrow + painter.drawLine(arrowStartNorthwest, arrowEndNorthwest); + painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x(), arrowEndNorthwest.y()+10); + painter.drawLine(arrowEndNorthwest.x(), arrowEndNorthwest.y(), arrowEndNorthwest.x()+10, arrowEndNorthwest.y()); + } + + else if (direction > 112.5 && direction < 157.5) + { + // Southeast arrow + painter.drawLine(arrowStartNorthwest, arrowEndNorthwest); + painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x(), arrowStartNorthwest.y()-10); + painter.drawLine(arrowStartNorthwest.x(), arrowStartNorthwest.y(), arrowStartNorthwest.x()-10, arrowStartNorthwest.y()); + } + + else + { + // North arrow + painter.drawLine(arrowStartNorth, arrowEndNorth); + painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()-5, arrowEndNorth.y()+10); + painter.drawLine(arrowEndNorth.x(), arrowEndNorth.y(), arrowEndNorth.x()+5, arrowEndNorth.y()+10); + } +} + +/** + *This slot function is called when route start/stop button clicked. */ void RouteSaveDialog::on_buttonRouteStartStop_clicked() { @@ -150,37 +271,42 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked() ui->labelRoutePicture->setVisible(0); timerRoutePicture->stop(); location->stopPollingGPS(); - - // Progres bar +/* + // Progress bar if(!calibrateDialog) + { calibrateDialog = new CalibrateDialog(); + } - calibrateDialog->show(); + progressbarPoints = 100; + progressbarIteration = 0; calibrateDialog->resetProgressValue(); - int points = 100; - int iteration = 0; - calibrateDialog->setMaxValue( points + 1 ); - - /*do { - calibrateDialog->setProgressValue(iteration); - iteration++; + calibrateDialog->setMaxValue( progressbarPoints ); + calibrateDialog->setTitle("Calculating route..."); + calibrateDialog->show(); - } while(iteration != points);*/ - QString routeFile = QString("routetemp.xml"); - if (routeDialog->readRouteFromFile( routeFile , calibrateDialog) == true) + if(!routeDialog) { - if(!routeDialog) - routeDialog = new RouteDialog(this); - connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute())); + routeDialog = new RouteDialog(this); + } + + connect(routeDialog, SIGNAL(sendroute(QString,int)), this, SLOT(sendRoute(QString,int))); + connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int))); + connect(routeDialog, SIGNAL(rejected()), this, SLOT(killRouteDialog())); + //connect(routeDialog, SIGNAL(killRoute()), this, SLOT(killRouteDialog())); - calibrateDialog->close(); + QString routeFile = QString(".//speedfreak_route/routetemp.xml"); + if (routeDialog->readRouteFromFile( routeFile ) == true) + { + //calibrateDialog->close(); routeDialog->show(); } else { - calibrateDialog->close(); + //calibrateDialog->close(); } +calibrateDialog->close();*/ //Set GPS speed labels in visible ui->labelGpsSpeed->setVisible(0); @@ -194,6 +320,8 @@ void RouteSaveDialog::on_buttonRouteStartStop_clicked() //User info label ui->labelUserInfo->setText("Push start button"); + + openRouteDialog("routetemp.xml"); } } @@ -264,6 +392,10 @@ void RouteSaveDialog::gpsStatus() //Get GPS speed speed = location->getSpeed(); + //Get GPS track means direction + direction = gpsData->getDirection(); + repaint(); + //Set GPS speed gpsSpeed.sprintf("%.0f", speed); ui->labelGpsSpeed->setText(gpsSpeed + " km/h"); @@ -273,7 +405,7 @@ void RouteSaveDialog::gpsStatus() allSpeeds += speed; averageSpeed = allSpeeds/speedCount; gpsSpeed.sprintf("%.0f",averageSpeed); - ui->labelGpsAvgSpeed->setText("Average: " + gpsSpeed + " km/h"); + ui->labelGpsAvgSpeed->setText("Avg: " + gpsSpeed + " km/h"); ui->labelGpsAvgSpeed->setVisible(1); speedCount++; @@ -333,9 +465,9 @@ void RouteSaveDialog::gpsStatus() /** * This slot function is called when routeDialog emit sendroute (sendPushButton). */ -void RouteSaveDialog::sendRoute() +void RouteSaveDialog::sendRoute(QString s,int i) { - emit sendroute(); //Emit mainwindow clientSendRoute + emit sendroute(s,i); //Emit mainwindow clientSendRoute } /** @@ -365,6 +497,25 @@ void RouteSaveDialog::killHelpDialog() } /** + * This slot function called when ever route dialog rejected. + */ +void RouteSaveDialog::killRouteDialog() +{ + if(routeDialog) + { + qDebug() << "__Route save kill: routeDialog"; + delete routeDialog; + routeDialog = NULL; + } + if(calibrateDialog) + { + qDebug() << "__Route save kill: calibrateDialog"; + delete calibrateDialog; + calibrateDialog = NULL; + } +} + +/** * This function return speed average. * @return double average speed */ @@ -381,3 +532,63 @@ QString RouteSaveDialog::getDistanceTraveled() { return distanceString; } + +/** + * This function + */ +void RouteSaveDialog::setProgressbar(int i) +{ + qDebug() << "__setProgressbar " ; + qDebug() << i; + calibrateDialog->setProgressValue(i); + progressbarIteration++; +} + +/** + * This slot function called when ever load route button clicked. + */ +void RouteSaveDialog::on_buttonLoadRoute_clicked() +{ + QString fileName = QFileDialog::getOpenFileName(this, tr("Open route"), QDir::currentPath()); + qDebug() << "__Opening: " + fileName; + openRouteDialog(fileName); +} + +/** + * This function open route. + * @param QString file name + */ +void RouteSaveDialog::openRouteDialog(QString fileName) +{ + // Progress bar + if(!calibrateDialog) + { + calibrateDialog = new CalibrateDialog(); + } + + progressbarPoints = 100; + progressbarIteration = 0; + calibrateDialog->resetProgressValue(); + calibrateDialog->setMaxValue( progressbarPoints ); + calibrateDialog->setTitle("Calculating route..."); + calibrateDialog->show(); + + if(!routeDialog) + { + routeDialog = new RouteDialog(this); + } + + connect(routeDialog, SIGNAL(sendroute()), this, SLOT(sendRoute())); + connect(routeDialog, SIGNAL(progressbar(int)), this, SLOT(setProgressbar(int))); + connect(routeDialog, SIGNAL(rejected()), this, SLOT(killRouteDialog())); + + if (routeDialog->readRouteFromFile( fileName ) == true) + { + calibrateDialog->close(); + routeDialog->show(); + } + else + { + calibrateDialog->close(); + } +}