2 * CarMainWindow main class
4 * @author Janne Änäkkälä <janne.anakkala@fudeco.com>
5 * @copyright (c) 2010 Speed Freak team
6 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 #include "resultdialog.h"
10 #include "ui_resultdialog.h"
13 const int DIAGRAM_WIDTH = 400;
14 const int DIAGRAM_HEIGHT = 300;
16 const int DIAGRAMGAP100KMH = 30;
17 const int DIAGRAMGAP40KMH = 75;
18 const int DIAGRAMGAP60KMH = 50;
19 const int DIAGRAMGAP50KMH = 60;
20 const double DIAGRAMGAP80KMH = 37.5;
22 const QPoint diagramStemStart(70, 330);
23 const QPoint diagramStemEnd(70, 30);
25 const QPoint diagramHorizontalStart(70, 330);
26 const QPoint diagramHorizontalEnd(470, 330);
28 const int diagramGap = 30;
30 // Test arrays for changing speeds and times to the points in diagram
31 static const int speedArray[11] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
32 //static const int timeArray[10] = {1, 2, 3, 4, 5, 6, 7, 8, 10, 12};
34 // Test point array for the diagram.
38 * Constructor of this class.
39 * @param QWidget pointer to parent object. By default the value is NULL.
41 ResultDialog::ResultDialog(QWidget *parent) :
43 ui(new Ui::ResultDialog)
46 speedList << "0" << "10" << "20" << "30" << "40" << "50" << "60" << "70" << "80" << "90" << "100" ;
47 timeList << "0" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "9" << "10" << "11"
48 << "12" << "13" << "14" << "15" << "16" << "17" << "18" << "19" << "20";
52 * Destructor of this class. Should be used to release all allocated resources.
54 ResultDialog::~ResultDialog()
59 void ResultDialog::changeEvent(QEvent *e)
61 QDialog::changeEvent(e);
63 case QEvent::LanguageChange:
64 ui->retranslateUi(this);
72 * Draws speed diagram to the UI
75 void ResultDialog::paintEvent(QPaintEvent *)
77 QPainter painter(this);
79 painter.setRenderHint(QPainter::Antialiasing, true);
80 painter.setPen(QPen((Qt::red),2));
82 font.setPixelSize(12);
83 painter.setFont(font);
84 painter.setBrush(QBrush((Qt::yellow), Qt::SolidPattern));
85 painter.drawLine(diagramStemStart, diagramStemEnd);
86 painter.drawLine(diagramHorizontalStart, diagramHorizontalEnd);
89 int currentY = diagramStemStart.y();
91 painter.setPen(QPen((Qt::blue),1));
92 // Draws diagram's X-axel
94 while (currentX <= DIAGRAM_WIDTH)
96 painter.drawLine(currentX + diagramStemStart.x(), currentY, currentX + diagramStemStart.x(), currentY - 300);
97 painter.drawText(currentX + diagramStemStart.x(), currentY + 20, timeList[i]);
98 currentX += this->diagramGapHorizontal;
102 currentX = diagramStemStart.x();
106 // Draws diagram's Y-axel
107 while (currentY >= -(DIAGRAM_HEIGHT))
109 painter.drawLine(currentX, diagramStemStart.y() + currentY, currentX+400, diagramStemStart.y() + currentY);
110 painter.drawText(currentX - 25, diagramStemStart.y() + currentY, speedList[i]);
111 currentY -= this->diagramGapStem;
115 painter.setPen(QPen((Qt::white),2));
117 // Draws result line to the diagram
118 if (this->diagramGapStem == DIAGRAMGAP100KMH)
120 painter.drawPolyline(points, 11);
123 else if (this->diagramGapStem == DIAGRAMGAP80KMH)
125 painter.drawPolyline(points, 9);
128 else if (this->diagramGapStem == DIAGRAMGAP60KMH)
130 painter.drawPolyline(points, 7);
133 else if (this->diagramGapStem == DIAGRAMGAP50KMH)
135 painter.drawPolyline(points, 6);
140 painter.drawPolyline(points, 5);
145 * Change the given speed and time to the point for the diagram.
146 * @param aSpeed is speed which need to change, aTime is time in seconds which need to change.
147 * @return point is calculated from aSpeed and aTime.
149 QPoint ResultDialog::changeMeasuresToDiagramPoint(int aSpeed, qreal aTime)
156 // Calculate speed and time to the point which can be drawn to the diagram
157 if (this->diagramGapStem == DIAGRAMGAP100KMH)
159 speedAsPixels = DIAGRAM_HEIGHT*aSpeed/100;
160 timeAsPixels = DIAGRAM_WIDTH*aTime/10;
163 else if (this->diagramGapStem == DIAGRAMGAP80KMH)
165 speedAsPixels = DIAGRAM_HEIGHT*aSpeed/80;
166 timeAsPixels = DIAGRAM_WIDTH*aTime/10;
169 else if (this->diagramGapStem == DIAGRAMGAP60KMH)
171 speedAsPixels = DIAGRAM_HEIGHT*aSpeed/60;
172 timeAsPixels = DIAGRAM_WIDTH*aTime/10;
175 else if (this->diagramGapStem == DIAGRAMGAP50KMH)
177 speedAsPixels = DIAGRAM_HEIGHT*aSpeed/50;
178 timeAsPixels = DIAGRAM_WIDTH*aTime/10;
183 speedAsPixels = DIAGRAM_HEIGHT*aSpeed/40;
184 timeAsPixels = DIAGRAM_WIDTH*aTime/10;
186 point.setY(diagramStemStart.y()-speedAsPixels);
187 point.setX(diagramStemStart.x()+timeAsPixels);
193 * Saves the given measures to array.
194 * @param pMeasures has information about acceleration.
196 void ResultDialog::saveMeasuresToArray(Measures *pMeasures)
199 timeArray[1] = pMeasures->getTime10kmh();
200 timeArray[2] = pMeasures->getTime20kmh();
201 timeArray[3] = pMeasures->getTime30kmh();
202 timeArray[4] = pMeasures->getTime40kmh();
203 timeArray[5] = pMeasures->getTime50kmh();
204 timeArray[6] = pMeasures->getTime60kmh();
205 timeArray[7] = pMeasures->getTime70kmh();
206 timeArray[8] = pMeasures->getTime80kmh();
207 timeArray[9] = pMeasures->getTime90kmh();
208 timeArray[10] = pMeasures->getTime100kmh();
210 for (int i = 0; i < 11; i++)
212 points[i] = changeMeasuresToDiagramPoint(speedArray[i], timeArray[i]);
215 setTimesIntoLabels();
218 for (int i = 0; i < 11; i++)
224 void ResultDialog::on_pushButtonSend_clicked()
230 * Saves the given diagram gap to the member variable.
231 * @param pDiagramGapStem has information about the right gap for diagram stem axel.
233 void ResultDialog::setDiagramGapStem(double pDiagramGapStem)
235 this->diagramGapStem = pDiagramGapStem;
239 * Saves the given diagram gap to the member variable.
240 * @param pDiagramGapHorizontal has information about the right gap for diagram horizontal axel.
242 void ResultDialog::setDiagramGapHorizontal(double pDiagramGapHorizontal)
244 this->diagramGapHorizontal = pDiagramGapHorizontal;
248 * Sets result times in to the labels and shows only wanted results and hides
251 void ResultDialog::setTimesIntoLabels()
253 QString time, timeInteger;
254 timeInteger.setNum(timeArray[4]);
255 time = "0 - 40 km/h: ";
256 time.append(timeInteger);
257 ui->labelResult40kmh->setText(time);
259 timeInteger.setNum(timeArray[3]);
260 time = "0 - 30 km/h: ";
261 time.append(timeInteger);
262 ui->labelResult30kmh->setText(time);
264 timeInteger.setNum(timeArray[2]);
265 time = "0 - 20 km/h: ";
266 time.append(timeInteger);
267 ui->labelResult20kmh->setText(time);
269 timeInteger.setNum(timeArray[1]);
270 time = "0 - 10 km/h: ";
271 time.append(timeInteger);
272 ui->labelResult10kmh->setText(time);
274 timeInteger.setNum(timeArray[6]);
275 time = "0 - 60 km/h: ";
276 time.append(timeInteger);
277 ui->labelResult60kmh->setText(time);
279 timeInteger.setNum(timeArray[5]);
280 time = "0 - 50 km/h: ";
281 time.append(timeInteger);
282 ui->labelResult50kmh->setText(time);
284 timeInteger.setNum(timeArray[7]);
285 time = "0 - 70 km/h: ";
286 time.append(timeInteger);
287 ui->labelResult70kmh->setText(time);
289 timeInteger.setNum(timeArray[8]);
290 time = "0 - 80 km/h: ";
291 time.append(timeInteger);
292 ui->labelResult80kmh->setText(time);
294 timeInteger.setNum(timeArray[9]);
295 time = "0 - 90 km/h: ";
296 time.append(timeInteger);
297 ui->labelResult90kmh->setText(time);
299 timeInteger.setNum(timeArray[10]);
300 time = "0 - 100 km/h: ";
301 time.append(timeInteger);
302 ui->labelResult100kmh->setText(time);
304 if (this->diagramGapStem == DIAGRAMGAP40KMH)
306 ui->labelResult50kmh->hide();
307 ui->labelResult60kmh->hide();
308 ui->labelResult70kmh->hide();
309 ui->labelResult80kmh->hide();
310 ui->labelResult90kmh->hide();
311 ui->labelResult100kmh->hide();
316 ui->labelResult50kmh->show();
317 ui->labelResult60kmh->show();
318 ui->labelResult70kmh->show();
319 ui->labelResult80kmh->show();
320 ui->labelResult90kmh->show();
321 ui->labelResult100kmh->show();
325 void ResultDialog::on_pushButtonSend_clicked()