ab9198f205a65ba5c7586c21e6c0edab3bc67565
[speedfreak] / Client / accelerationstart.cpp
1 /*
2  * Acceleration start dialog
3  *
4  * @author      Jukka Kurttila <jukka.kurttila@fudeco.com>
5  * @copyright   (c) 2010 Speed Freak team
6  * @license     http://opensource.org/licenses/gpl-license.php GNU Public License
7  */
8 #include "accelerationstart.h"
9 #include "ui_accelerationstartdialog.h"
10 #include <QMessageBox>
11
12 accelerationstart::accelerationstart(QWidget *parent) :
13     QDialog(parent),
14     ui(new Ui::accelerationstart)
15 {
16     ui->setupUi(this);
17     ui->buttonStart->setDisabled(true);
18
19     accRealTimeDialog = NULL;
20
21     stopMeasureSpeed = 0;
22
23     ui->categorComboBox->addItem("Select category");
24     //ui->categorComboBox->addItem("-");
25     ui->categorComboBox->addItem("0 - 20 km/h",20);
26     ui->categorComboBox->addItem("0 - 40 km/h");
27     ui->categorComboBox->addItem("0 - 100 km/h");
28
29     //Button settings
30     ui->buttonCalib->setAutoFillBackground(true);
31     ui->buttonCalib->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
32     ui->buttonStart->setAutoFillBackground(true);
33     ui->buttonStart->setStyleSheet("background-color: rgb(0, 0, 0); color: rgb(255, 255, 255)");
34 }
35
36 accelerationstart::~accelerationstart()
37 {
38     delete ui;
39     if(accRealTimeDialog)
40         delete accRealTimeDialog;
41 }
42
43 void accelerationstart::changeEvent(QEvent *e)
44 {
45     QDialog::changeEvent(e);
46     switch (e->type()) {
47     case QEvent::LanguageChange:
48         ui->retranslateUi(this);
49         break;
50     default:
51         break;
52     }
53 }
54
55 void accelerationstart::on_buttonCalib_clicked()
56 {
57     if(accRealTimeDialog == NULL)
58         accRealTimeDialog = new AccRealTimeDialog(this);
59
60     connect(accRealTimeDialog, SIGNAL(sendresult(double)), this, SLOT(sendResult(double)));
61
62     accRealTimeDialog->Calibrate();
63
64     ui->buttonStart->setEnabled(true);
65 }
66
67 void accelerationstart::on_buttonStart_clicked()
68 {
69     if( stopMeasureSpeed == 0 )
70     {
71         QMessageBox msgBox;
72         msgBox.setWindowTitle("Can not start measure!");
73         msgBox.setText("Select category first!");
74         msgBox.setDefaultButton(QMessageBox::Ok);
75         msgBox.exec();
76         return;
77     }
78     accRealTimeDialog->SetStopMeasureSpeed( stopMeasureSpeed );
79     accRealTimeDialog->startAccelerationMeasure();
80     accRealTimeDialog->show();
81 }
82
83 void accelerationstart::on_categorComboBox_currentIndexChanged( int index )
84 {
85     stopMeasureSpeed = 0;
86     if( index == 1 ) {
87         stopMeasureSpeed = 20;
88         measureCategory = "acceleration-0-20";
89     }
90     else if( index == 2 ) {
91         stopMeasureSpeed = 40;
92         measureCategory = "acceleration-0-40";
93     }
94     else if( index == 3 ) {
95         stopMeasureSpeed = 100;
96         measureCategory = "acceleration-0-100";
97     }
98 }
99
100
101 QString accelerationstart::getMeasureCategory()
102 {
103     return measureCategory;
104 }
105
106 /**
107   *This slot function emit mainwindow sendresult.
108   *
109   **/
110 void accelerationstart::sendResult(double result)
111 {
112     emit sendresult(measureCategory, result);
113 }