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