X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=Client%2Fmeasuredialog.cpp;h=c469a7e7312c6741d4c317f744574c76cacb4014;hb=f1156b17c0735067d363a1dc6a6c0a5c3688ffcc;hp=11944f21eb1481ade292f7a821868eb451c3f67c;hpb=b7e5e4f21ee31476d5b9d3ceb3b7070b7f6e7101;p=speedfreak diff --git a/Client/measuredialog.cpp b/Client/measuredialog.cpp index 11944f2..c469a7e 100644 --- a/Client/measuredialog.cpp +++ b/Client/measuredialog.cpp @@ -1,13 +1,42 @@ +/* + * CarMainWindow main class + * + * @author Janne Änäkkälä + * @copyright (c) 2010 Speed Freak team + * @license http://opensource.org/licenses/gpl-license.php GNU Public License + */ + #include "measuredialog.h" #include "ui_measuredialog.h" +#include "math.h" +/** + * Constructor of this class. + * @param QWidget pointer to parent object. By default the value is NULL. + */ MeasureDialog::MeasureDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MeasureDialog) { ui->setupUi(this); + ui->labelInfo->setText("Accelerate to 100 km/h"); + time = 0; + speed = 0; + timer = new QTimer(); + + accelerometer = new Accelerometer(); + + measures = new Measures(); + this->initializeMeasures(); + + timer->setInterval(100); + timer->start(); + connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout())); } +/** + *Destructor of this class. Should be used to release all allocated resources. + */ MeasureDialog::~MeasureDialog() { delete ui; @@ -24,3 +53,129 @@ void MeasureDialog::changeEvent(QEvent *e) break; } } + +/** + * This slot function is called when timer gives timeout signal. Checks current speed + * and stores times in measure class. + */ +void MeasureDialog::after_timeout() +{ + QString timeString, speedString; + time++; + speed = speed +10; + + if (floor(speed) == 10) + { + measures->setTime10kmh(time); + } + + else if (floor(speed) == 20) + { + measures->setTime20kmh(time); + } + + else if (floor(speed) == 30) + { + measures->setTime30kmh(time); + } + + else if (floor(speed) == 40) + { + measures->setTime40kmh(time); + } + + else if (floor(speed) == 50) + { + measures->setTime50kmh(time); + } + + else if (floor(speed) == 60) + { + measures->setTime60kmh(time); + } + + else if (floor(speed) == 70) + { + measures->setTime70kmh(time); + } + + else if (floor(speed) == 80) + { + measures->setTime80kmh(time); + } + + else if (floor(speed) == 90) + { + measures->setTime90kmh(time); + } + + else if (floor(speed) == 100) + { + measures->setTime100kmh(time); + } + + else + { + + } + + // If speed is over 100 km/h emits speedAchieved() signal and close this dialog. + if (speed >= 40.0) + { + timer->stop(); + time = 0; + speed = 0; + emit this->speedAchieved(); + this->close(); + + } + + // Updates speed and time. + else + { + timeString.setNum(time); + speedString.setNum(speed); + ui->labelSpeed->setText(speedString); + ui->labelTime->setText(timeString); + timer->start(); + } + +} + +/** + * This slot function is called when Abort button is clicked. + */ +void MeasureDialog::on_pushButtonAbort_clicked() +{ + measures->setTime10kmh(0); + measures->setTime20kmh(0); + measures->setTime30kmh(0); + measures->setTime40kmh(0); + measures->setTime50kmh(0); + measures->setTime60kmh(0); + measures->setTime70kmh(0); + measures->setTime80kmh(0); + measures->setTime90kmh(0); + measures->setTime100kmh(0); + timer->stop(); + time = 0; + speed = 0; + this->close(); +} + +/** + * Initializes measures class's member variables. + */ +void MeasureDialog::initializeMeasures() +{ + measures->setTime10kmh(0); + measures->setTime20kmh(0); + measures->setTime30kmh(0); + measures->setTime40kmh(0); + measures->setTime50kmh(0); + measures->setTime60kmh(0); + measures->setTime70kmh(0); + measures->setTime80kmh(0); + measures->setTime90kmh(0); + measures->setTime100kmh(0); +}