Maemo package folder added.
[speedfreak] / Client / resultdialog.cpp
index 3ab0591..e78c201 100644 (file)
@@ -1,7 +1,8 @@
 /*
- * CarMainWindow main class
+ * Result dialog
  *
  * @author     Janne Änäkkälä <janne.anakkala@fudeco.com>
+ * @author     Toni Jussila    <toni.jussila@fudeco.com>
  * @copyright  (c) 2010 Speed Freak team
  * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  */
@@ -12,6 +13,7 @@
 #include "math.h"
 #include <QPainter>
 #include <QPicture>
+#include <QDebug>
 
 const int DIAGRAM_WIDTH = 400;
 const int DIAGRAM_HEIGHT = 300;
@@ -49,6 +51,7 @@ QPoint points[11];
 
 /**
   * Constructor of this class.
+  *
   * @param QWidget pointer to parent object. By default the value is NULL.
   */
 ResultDialog::ResultDialog(QWidget *parent) :
@@ -56,6 +59,9 @@ ResultDialog::ResultDialog(QWidget *parent) :
     ui(new Ui::ResultDialog)
 {
     ui->setupUi(this);
+
+    helpAccelerationDialog = NULL;
+
     timeAxelLength = 10;
     resultString = "";
     speedList << "0" << "10" << "20" << "30" << "40" << "50" << "60" << "70" << "80" << "90" << "100" ;
@@ -68,6 +74,9 @@ ResultDialog::ResultDialog(QWidget *parent) :
         timeArray[i] = 0;
     }
 
+    //Clear info label
+    ui->labelInfoToUser->setText("");
+
     if (loginSaved())
     {
         ui->pushButtonSend->setEnabled(true);
@@ -75,6 +84,7 @@ ResultDialog::ResultDialog(QWidget *parent) :
     else
     {
         ui->pushButtonSend->setEnabled(false);
+        ui->labelInfoToUser->setText("You're not logged! Please register or log in and accelerate again.");
     }
 }
 
@@ -86,6 +96,9 @@ ResultDialog::~ResultDialog()
     delete ui;
 }
 
+/**
+  *
+  */
 void ResultDialog::changeEvent(QEvent *e)
 {
     QDialog::changeEvent(e);
@@ -100,6 +113,7 @@ void ResultDialog::changeEvent(QEvent *e)
 
 /**
   * Draws speed diagram to the UI
+  *
   * @param QPaintEvent
  */
 void ResultDialog::paintEvent(QPaintEvent *)
@@ -193,6 +207,7 @@ void ResultDialog::paintEvent(QPaintEvent *)
 
 /**
   * Change the given speed and time to the point for the diagram.
+  *
   * @param aSpeed is speed which need to change, aTime is time in seconds which need to change.
   * @return point is calculated from aSpeed and aTime.
   */
@@ -219,52 +234,52 @@ QPoint ResultDialog::changeMeasuresToDiagramPoint(int aSpeed, qreal aTime)
 void ResultDialog::setTimesIntoLabels()
 {
     QString time, timeInteger;
-    timeInteger.setNum(timeArray[4]);
+    timeInteger.sprintf("%.2f", timeArray[4]);
     time = "0 - 40 km/h: ";
     time.append(timeInteger);
     ui->labelResult40kmh->setText(time);
 
-    timeInteger.setNum(timeArray[3]);
+    timeInteger.sprintf("%.2f", timeArray[3]);
     time = "0 - 30 km/h: ";
     time.append(timeInteger);
     ui->labelResult30kmh->setText(time);
 
-    timeInteger.setNum(timeArray[2]);
+    timeInteger.sprintf("%.2f", timeArray[2]);
     time = "0 - 20 km/h: ";
     time.append(timeInteger);
     ui->labelResult20kmh->setText(time);
 
-    timeInteger.setNum(timeArray[1]);
+    timeInteger.sprintf("%.2f", timeArray[1]);
     time = "0 - 10 km/h: ";
     time.append(timeInteger);
     ui->labelResult10kmh->setText(time);
 
-    timeInteger.setNum(timeArray[6]);
+    timeInteger.sprintf("%.2f", timeArray[6]);
     time = "0 - 60 km/h: ";
     time.append(timeInteger);
     ui->labelResult60kmh->setText(time);
 
-    timeInteger.setNum(timeArray[5]);
+    timeInteger.sprintf("%.2f", timeArray[5]);
     time = "0 - 50 km/h: ";
     time.append(timeInteger);
     ui->labelResult50kmh->setText(time);
 
-    timeInteger.setNum(timeArray[7]);
+    timeInteger.sprintf("%.2f", timeArray[7]);
     time = "0 - 70 km/h: ";
     time.append(timeInteger);
     ui->labelResult70kmh->setText(time);
 
-    timeInteger.setNum(timeArray[8]);
+    timeInteger.sprintf("%.2f", timeArray[8]);
     time = "0 - 80 km/h: ";
     time.append(timeInteger);
     ui->labelResult80kmh->setText(time);
 
-    timeInteger.setNum(timeArray[9]);
+    timeInteger.sprintf("%.2f", timeArray[9]);
     time = "0 - 90 km/h: ";
     time.append(timeInteger);
     ui->labelResult90kmh->setText(time);
 
-    timeInteger.setNum(timeArray[10]);
+    timeInteger.sprintf("%.2f", timeArray[10]);
     time = "0 - 100 km/h: ";
     time.append(timeInteger);
     ui->labelResult100kmh->setText(time);
@@ -275,6 +290,8 @@ void ResultDialog::setTimesIntoLabels()
 /**
   * Sets right timeAxelLength value depending the time which
   * has spent to reach target speed.
+  *
+  * @param int choice
   */
 void ResultDialog::setTimeAxelLength(int pChoice)
 {
@@ -310,18 +327,25 @@ void ResultDialog::on_pushButtonNew_clicked()
     }
     resultString = "";
     this->close();
+    emit rejected();
 }
 
 /**
   * This slot function emits sendresult signal for sending results to server when
   * send results -button has been clicked.
+  * Emit accrealtimedialog sendresult.
   */
 void ResultDialog::on_pushButtonSend_clicked()
 {
-    emit sendresult();
-    //emit sendresult(timeArray[this->getTargetChoice()]);
+    ui->pushButtonSend->setEnabled(false);
+    emit sendresult(timeArray[this->getTargetChoice()]);
 }
 
+/**
+  * Get result.
+  *
+  * @return double result.
+  */
 double ResultDialog::getResult()
 {
     return timeArray[this->getTargetChoice()];
@@ -329,6 +353,7 @@ double ResultDialog::getResult()
 
 /**
   * This public function sets diagram's stem gap
+  *
   * @param pValue is the speed value which determines diagram gap's value
   */
 void ResultDialog::setEnd(int pValue)
@@ -389,6 +414,7 @@ void ResultDialog::setEnd(int pValue)
 
 /**
   * This public function stores time in timeArray
+  *
   * @param pSpeed is the speed value at the time so we know where store time
   * @param pTime is the result which needs to be store in timeArray
   */
@@ -689,8 +715,9 @@ void ResultDialog::showOrHideLabels()
 
 /**
   * Checks which target speed has been choosed
+  *
   * @return targetChoice which tells to caller integer value about the target speed
-  * e.g. 20 km/h is value 2 and 60 km/h is value 6
+  *         e.g. 20 km/h is value 2 and 60 km/h is value 6
   */
 int ResultDialog::getTargetChoice()
 {
@@ -748,3 +775,46 @@ int ResultDialog::getTargetChoice()
     }
     return targetChoice;
 }
+/**
+  * Set label info to user.
+  *
+  * @param QString info text
+  */
+void ResultDialog::setLabelInfoToUser(QString infoText)
+{
+    this->ui->labelInfoToUser->setText(infoText);
+}
+
+/**
+  * This function enable send server button.
+  */
+void ResultDialog::setSendServerButtonEnabled()
+{
+    ui->pushButtonSend->setEnabled(true);
+}
+
+/**
+  * This slot function called when ever info button clicked.
+  */
+void ResultDialog::on_pushButtonInfo_clicked()
+{
+    if(!helpAccelerationDialog)
+    {
+        helpAccelerationDialog = new HelpAccelerationDialog;
+    }
+    connect(helpAccelerationDialog, SIGNAL(rejected()), this, SLOT(killHelpDialog()));
+    helpAccelerationDialog->show();
+}
+
+/**
+  * This slot function called when ever dialog rejected.
+  */
+void ResultDialog::killHelpDialog()
+{
+    if(helpAccelerationDialog)
+    {
+        qDebug() << "__Result kill: helpAccelerationDialog";
+        delete helpAccelerationDialog;
+        helpAccelerationDialog = NULL;
+    }
+}