/*
- * 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
*/
#include "math.h"
#include <QPainter>
#include <QPicture>
+#include <QDebug>
const int DIAGRAM_WIDTH = 400;
const int DIAGRAM_HEIGHT = 300;
const int DIAGRAMGAP5S = 80;
const int DIAGRAMGAP10S = 40;
+const int DIAGRAMGAP16S = 25;
const int DIAGRAMGAP20S = 20;
const QPoint diagramStemStart(70, 330);
ui(new Ui::ResultDialog)
{
ui->setupUi(this);
+
+ helpAccelerationDialog = NULL;
+
timeAxelLength = 10;
resultString = "";
speedList << "0" << "10" << "20" << "30" << "40" << "50" << "60" << "70" << "80" << "90" << "100" ;
timeList << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10" << "11"
<< "12" << "13" << "14" << "15" << "16" << "17" << "18" << "19" << "20";
+ this->diagramGapStem = DIAGRAMGAP100KMH;
+ this->diagramGapHorizontal = DIAGRAMGAP20S;
for (int i = 0; i < 11; i++)
{
timeArray[i] = 0;
}
+ //Clear info label
+ ui->labelInfoToUser->setText("");
+
if (loginSaved())
{
ui->pushButtonSend->setEnabled(true);
else
{
ui->pushButtonSend->setEnabled(false);
+ ui->labelInfoToUser->setText("You're not logged! Please register or log in and accelerate again.");
}
}
painter.setPen(QPen((Qt::darkCyan),2));
painter.drawLine(diagramStemStart, diagramStemEnd);
painter.drawLine(diagramHorizontalStart, diagramHorizontalEnd);
+ painter.drawText(diagramStemStart.x() - 50, diagramStemEnd.y() + 100, "S");
+ painter.drawText(diagramStemStart.x() - 50, diagramStemEnd.y() + 115, "P");
+ painter.drawText(diagramStemStart.x() - 50, diagramStemEnd.y() + 130, "E");
+ painter.drawText(diagramStemStart.x() - 50, diagramStemEnd.y() + 145, "E");
+ painter.drawText(diagramStemStart.x() - 50, diagramStemEnd.y() + 160, "D");
+ painter.drawText(diagramStemStart.x() - 65, diagramStemEnd.y() + 180, "(km/h)");
+
+ painter.drawText(diagramStemStart.x() + 140, diagramStemStart.y() + 40, "T");
+ painter.drawText(diagramStemStart.x() + 150, diagramStemStart.y() + 40, "I");
+ painter.drawText(diagramStemStart.x() + 155, diagramStemStart.y() + 40, "M");
+ painter.drawText(diagramStemStart.x() + 165, diagramStemStart.y() + 40, "E");
+ painter.drawText(diagramStemStart.x() + 180, diagramStemStart.y() + 40, "(s)");
int currentX = 0;
int currentY = diagramStemStart.y();
*/
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
{
timeArray[i] = 0;
}
+ 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()
{
+ ui->pushButtonSend->setEnabled(false);
emit sendresult(timeArray[this->getTargetChoice()]);
}
+double ResultDialog::getResult()
+{
+ return timeArray[this->getTargetChoice()];
+}
+
/**
* 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)
{
+ for (int i = 0; i < 11; i++)
+ {
+ timeArray[i] = 0;
+ }
+ resultString = "";
+
switch (pValue)
{
case 10:
void ResultDialog::setValue(int pSpeed, double pTime)
{
//timeArray[0] = 0;
- if (floor(pTime) <= 5)
+ if (pTime <= 5.0)
{
this->diagramGapHorizontal = DIAGRAMGAP5S;
}
- else if (floor(pTime) <= 10)
+ else if (pTime <= 10.0 && pTime > 5.0)
{
this->diagramGapHorizontal = DIAGRAMGAP10S;
}
+ else if (pTime <= 16.0 && pTime > 10.0)
+ {
+ this->diagramGapHorizontal = DIAGRAMGAP16S;
+ }
+
else
{
this->diagramGapHorizontal = DIAGRAMGAP20S;
//QString resultString;
resultString.append("Time was ");
+ QString time;
+
if (this->diagramGapStem == DIAGRAMGAP100KMH)
{
- resultString.append(QString::number(timeArray[10]));
+ time.sprintf("%.2f", timeArray[10]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 100 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP90KMH)
{
- resultString.append(QString::number(timeArray[9]));
+ time.sprintf("%.2f", timeArray[9]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 90 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP80KMH)
{
- resultString.append(QString::number(timeArray[8]));
+ time.sprintf("%.2f", timeArray[8]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 80 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP70KMH)
{
- resultString.append(QString::number(timeArray[7]));
+ time.sprintf("%.2f", timeArray[7]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 70 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP60KMH)
{
- resultString.append(QString::number(timeArray[6]));
+ time.sprintf("%.2f", timeArray[6]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 60 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP50KMH)
{
- resultString.append(QString::number(timeArray[5]));
+ time.sprintf("%.2f", timeArray[5]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 50 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP40KMH)
{
- resultString.append(QString::number(timeArray[4]));
+ time.sprintf("%.2f", timeArray[4]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 40 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP30KMH)
{
- resultString.append(QString::number(timeArray[3]));
+ time.sprintf("%.2f", timeArray[3]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 30 km/h");
}
else if (this->diagramGapStem == DIAGRAMGAP20KMH)
{
- resultString.append(QString::number(timeArray[2]));
+ time.sprintf("%.2f", timeArray[2]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 20 km/h");
}
else
{
- resultString.append(QString::number(timeArray[1]));
+ time.sprintf("%.2f", timeArray[1]);
+ resultString.append(time);
this->setWindowTitle("Result for accelerating 10 km/h");
}
}
}
return targetChoice;
}
+
+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;
+ }
+}
+