Profile dialog development
[speedfreak] / Client / routedialog.cpp
index 7ad0e70..35f232f 100644 (file)
@@ -7,6 +7,7 @@
  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
  */
 
+#include "routesavedialog.h"
 #include "routedialog.h"
 #include "ui_routedialog.h"
 #include "usersettings.h"
@@ -169,36 +170,35 @@ qreal countDistance(Vector *p1, Vector *p2)
 /**
   * Constructor of this class.
   */
-RouteDialog::RouteDialog(QWidget *parent) :
-    QDialog(parent),
-    ui(new Ui::RouteDialog)
+RouteDialog::RouteDialog(RouteSaveDialog *parent) :
+    QDialog(parent), ui(new Ui::RouteDialog)
 {
     qDebug() << "__RouteDialog";
     ui->setupUi(this);
+
     this->setWindowTitle("Route");
     left = 5; top = 5; right = 495; bottom = 295; // Limits in screen coordinates
 
-    //Button settings
+    helpRoutingDialog = NULL;
+
+    // Button settings
     ui->sendPushButton->setAutoFillBackground(true);
     ui->sendPushButton->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
     ui->newPushButton->setAutoFillBackground(true);
     ui->newPushButton->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
 
-    //Clear labels
+    // Clear labels
     ui->labelInfoToUser->setText("");
-    ui->maxSpeedLabel->setText("");
     ui->speedValueLabel->setText("");
+    ui->avgSpeedValueLabel->setText("");
 
-    // Send rout to server button disable/enable.
-    ui->sendPushButton->setEnabled(false);
-    if (loginSaved())
-    {
-        ui->sendPushButton->setEnabled(true);
-    }
-    else
-    {
-        ui->labelInfoToUser->setText("You're not logged! Please register or log in.");
-    }
+    // Check login
+    checkLogin();
+
+    // Set average speed
+    QString average;
+    ui->avgSpeedValueLabel->setText(average.sprintf("%.1f", parent->getAverageSpeed()) + " km/h");
+    ui->distanceValueLabel->setText(parent->getDistanceTraveled() + " km");
 }
 
 /**
@@ -209,6 +209,8 @@ RouteDialog::~RouteDialog()
     qDebug() << "__~RouteDialog";
     if(ui)
         delete ui;
+    if(calibrateDialog)
+        delete calibrateDialog;
 }
 
 /**
@@ -261,7 +263,7 @@ int RouteDialog::getBottom()
 /**
   *
   */
-void drawFlag( RouteDialog *rD, QPainter *p, int x, int y)
+void drawFlag( RouteDialog *rD, QPainter *p, int x, int y, QString startFinish)
 {
     /*QPolygon pg;
 
@@ -279,6 +281,9 @@ void drawFlag( RouteDialog *rD, QPainter *p, int x, int y)
             p->drawLine( x,    y-25, x+10, y-20);
             p->drawLine( x+10, y-20, x,    y-15);
             p->drawLine( x,    y-15, x,    y-25);
+
+            // Draw start or finish
+            p->drawText(x+10, y, startFinish);
         }
         else
         {
@@ -286,8 +291,10 @@ void drawFlag( RouteDialog *rD, QPainter *p, int x, int y)
             p->drawLine( x,    y-25, x-10, y-20);
             p->drawLine( x-10, y-20, x,    y-15);
             p->drawLine( x,    y-15, x,    y-25);
-        }
 
+            // Draw start or finish
+            p->drawText(x+10, y, startFinish);
+        }    
     }
     else if (y <= (rD->getTop() + 25))
     {
@@ -299,6 +306,9 @@ void drawFlag( RouteDialog *rD, QPainter *p, int x, int y)
             p->drawLine( x,    y+25, x+10, y+20);
             p->drawLine( x+10, y+20, x,    y+15);
             p->drawLine( x,    y+15, x,    y+25);
+
+            // Draw start or finish
+            p->drawText(x+10, y+15, startFinish);
         }
         else
         {
@@ -306,6 +316,9 @@ void drawFlag( RouteDialog *rD, QPainter *p, int x, int y)
             p->drawLine( x,    y+25, x-10, y+20);
             p->drawLine( x-10, y+20, x,    y+15);
             p->drawLine( x,    y+15, x,    y+25);
+
+            // Draw start or finish
+            p->drawText(x+10, y+15, startFinish);
         }
     }
     //p->drawPolygon();
@@ -322,6 +335,9 @@ void drawFlag( RouteDialog *rD, QPainter *p, int x, int y)
 /* */
 void RouteDialog::paintEvent(QPaintEvent *)
 {
+    // Check login
+    checkLogin();
+
     int type = 0; //  0 for 2d, 1 for 3d
     int startx, starty; // Starting point of the route
     int i, maxi;
@@ -329,6 +345,7 @@ void RouteDialog::paintEvent(QPaintEvent *)
     int x1Screen, y1Screen, x2Screen, y2Screen;
     Vector v1, v2;
     QPainter painter(this);
+    int startStop = 0;
 
     painter.setRenderHint(QPainter::Antialiasing, true);
     painter.setPen(QPen((Qt::white),2));
@@ -370,7 +387,7 @@ void RouteDialog::paintEvent(QPaintEvent *)
             // Starting point
             startx = x1Screen; starty = y1Screen;
            // painter.drawEllipse( x1Screen-5, y1Screen-5, 10, 10);
-           drawFlag( this, &painter,  x1Screen ,  y1Screen);
+           drawFlag( this, &painter,  x1Screen,  y1Screen, "Start" );
         }
         painter.drawLine( x1Screen, y1Screen, x2Screen, y2Screen);
     }
@@ -378,7 +395,7 @@ void RouteDialog::paintEvent(QPaintEvent *)
     if (x2Screen != startx || y2Screen != starty)
     {
         //painter.drawEllipse( x2Screen-5, y2Screen-5, 10, 10);
-        drawFlag( this, &painter,x2Screen, y2Screen );
+        drawFlag( this, &painter, x2Screen, y2Screen, "Finish" );
     }
 
     {
@@ -403,10 +420,11 @@ void RouteDialog::paintEvent(QPaintEvent *)
 
         // Show max velocity point by yellow circle
         painter.drawEllipse( x1Screen-5, y1Screen-5, 10, 10);
+        painter.drawEllipse( ui->maxSpeedLabel->geometry().x()-15, ui->maxSpeedLabel->geometry().y()+15, 10, 10);
 
         QString jono;
         //jono = QString("%1 km/h").arg(maxv);
-        jono.sprintf("%.1f km/h", maxv);
+        jono.sprintf("%.1f km/h", maxv); // Show only 1 decimal
         ui->speedValueLabel->setText(jono);
     }
 }
@@ -414,13 +432,17 @@ void RouteDialog::paintEvent(QPaintEvent *)
 /**
   *
   */
-bool RouteDialog::readRouteFromFile( QString &routeFile)
- {
+bool RouteDialog::readRouteFromFile( QString &routeFile , CalibrateDialog *calibrateDialog)
+{
     QString rFile = routeFile; //Not used
     Vector temp;
     QString rivi;
     QFile file;
 
+    progresbar = calibrateDialog;
+    int progresbarValue = 0;
+    progresbar->setProgressValue(++progresbarValue);
+
     //QString fileName = QFileDialog::getOpenFileName(this,
     //     tr("Read Route"), "./", tr("Route Files (*.txt)"));
 
@@ -429,6 +451,7 @@ bool RouteDialog::readRouteFromFile( QString &routeFile)
     if (!file.open(QIODevice::ReadOnly))
     {
         QMessageBox::about(0, "Error", "File not found");
+        progresbar->setProgressValue(100);
         return false;
     }
 
@@ -544,7 +567,7 @@ bool RouteDialog::readRouteFromFile( QString &routeFile)
      */
 
      return true;
- }
+}
 
 /**
   * Find out data range for x-, y- and z-coordinates
@@ -817,3 +840,46 @@ void RouteDialog::setSendServerButtonEnabled()
 {
     ui->sendPushButton->setEnabled(true);
 }
+
+/**
+  * This function check login and set send route to server button disabled/enabled.
+  */
+void RouteDialog::checkLogin()
+{
+    if (loginSaved())
+    {
+        ui->sendPushButton->setEnabled(true);
+        ui->labelInfoToUser->setText("");
+    }
+    else
+    {
+        ui->sendPushButton->setEnabled(false);
+        ui->labelInfoToUser->setText("You're not logged! Please register or log in.");
+    }
+}
+
+/**
+  * This slot function called when ever info button clicked.
+  */
+void RouteDialog::on_pushButtonInfo_clicked()
+{    
+    if(!helpRoutingDialog)
+    {
+        helpRoutingDialog = new HelpRoutingDialog;
+    }
+    connect(helpRoutingDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
+    helpRoutingDialog->show();
+}
+
+/**
+  * This slot function called when ever dialog rejected.
+  */
+void RouteDialog::killHelpDialog()
+{
+    if(helpRoutingDialog)
+    {
+        qDebug() << "__Route kill: helpRoutingDialog";
+        delete helpRoutingDialog;
+        helpRoutingDialog = NULL;
+    }
+}