Added function to kill usersDialog when dialog is closed.
[speedfreak] / Client / resultdialog.cpp
index a01a168..1f75c6e 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,9 @@
 #include "math.h"
 #include <QPainter>
 #include <QPicture>
+#include <QDebug>
+#include <QDesktopServices>
+#include <QUrl>
 
 const int DIAGRAM_WIDTH = 400;
 const int DIAGRAM_HEIGHT = 300;
@@ -56,6 +60,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 +75,9 @@ ResultDialog::ResultDialog(QWidget *parent) :
         timeArray[i] = 0;
     }
 
+    //Clear info label
+    ui->labelInfoToUser->setText("");
+
     if (loginSaved())
     {
         ui->pushButtonSend->setEnabled(true);
@@ -75,6 +85,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.");
     }
 }
 
@@ -105,7 +116,15 @@ void ResultDialog::changeEvent(QEvent *e)
 void ResultDialog::paintEvent(QPaintEvent *)
 {
     setHeaders();
-    QPainter painter(this);
+    //Create Pixmap, where image will be draw
+    QPixmap image(ui->scrollArea->width(), ui->scrollArea->height()/*DIAGRAM_WIDTH+100, DIAGRAM_HEIGHT+70*/);
+       
+    //Create painter and give paramemeter where image will be draw
+    QPainter painter(&image);
+    painter.setPen(Qt::white);
+    painter.setBrush(Qt::white);
+    painter.drawRect(QRect(0, 0, ui->scrollArea->width(), ui->scrollArea->height()/*DIAGRAM_WIDTH+100, DIAGRAM_HEIGHT+70*/));
+    
 
     painter.setRenderHint(QPainter::Antialiasing, true);
     painter.setPen(QPen((Qt::gray),2));
@@ -117,7 +136,7 @@ void ResultDialog::paintEvent(QPaintEvent *)
 
     fontForResult.setPixelSize(50);
     painter.setFont(fontForResult);
-    painter.drawText(diagramStemStart.x() + 50, diagramStemStart.y() - 150, resultString);
+    painter.drawText(diagramStemStart.x() + 30, diagramStemStart.y() - 150, resultString);
     painter.setFont(font);
 
     painter.setPen(QPen((Qt::darkCyan),2));
@@ -189,6 +208,18 @@ void ResultDialog::paintEvent(QPaintEvent *)
     {
         painter.drawPolyline(points, pointsToShow);
     }
+    //Save image in file acceleration.png
+    image.save("acceleration.png", 0, -1);
+
+    //Create label
+    QLabel *imageLabel = new QLabel(this);
+    
+    //Set image pixmap to label
+    imageLabel->setPixmap(image);
+    
+    //Set image label to scrollArea
+    ui->scrollArea->setWidget(imageLabel);
+
 }
 
 /**
@@ -278,19 +309,19 @@ void ResultDialog::setTimesIntoLabels()
   */
 void ResultDialog::setTimeAxelLength(int pChoice)
 {
-    if (timeArray[pChoice] <= 5)
+    if (timeArray[pChoice] <= 5.0)
     {
         timeAxelLength = 5;
     }
 
-    else if (timeArray[pChoice] <= 10)
+    else if (timeArray[pChoice] <= 10.0 && timeArray[pChoice] > 5.0)
     {
         timeAxelLength = 10;
     }
 
-    else if (timeArray[pChoice] <= 15)
+    else if (timeArray[pChoice] <= 16.0 && timeArray[pChoice] > 10.0)
     {
-        timeAxelLength = 15;
+        timeAxelLength = 16;
     }
 
     else
@@ -310,16 +341,18 @@ 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()]);
 }
 
 double ResultDialog::getResult()
@@ -400,12 +433,12 @@ void ResultDialog::setValue(int pSpeed, double pTime)
         this->diagramGapHorizontal = DIAGRAMGAP5S;
     }
 
-    else if (pTime <= 10.0)
+    else if (pTime <= 10.0 && pTime > 5.0)
     {
        this->diagramGapHorizontal = DIAGRAMGAP10S;
     }
 
-    else if (pTime <= 16.0)
+    else if (pTime <= 16.0 && pTime > 10.0)
     {
         this->diagramGapHorizontal = DIAGRAMGAP16S;
     }
@@ -754,3 +787,45 @@ 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;
+    }
+}
+/**
+  * This slot function opens E-mail application with attachment file
+  * (acceleration.png). Image of resultdialog
+  */
+
+void ResultDialog::on_pushButtonEMail_clicked()
+{
+    QDesktopServices::openUrl(QUrl("mailto:name@domain.com?Subject=Acceleration Result&Body=Hi, Here are my acceleration result!&Attachment=acceleration.png"));
+}