2 * CarMainWindow main class
4 * @author Toni Jussila <toni.jussila@fudeco.com>
5 * @author Janne Änäkkälä <janne.anakkala@fudeco.com>
6 * @author Tiina Kivilinna-Korhola <tiina.kivilinna-korhola@fudeco.com>
7 * @author Olavi Pulkkinen <olavi.pulkkinen@fudeco.com>
8 * @copyright (c) 2010 Speed Freak team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 #include "carmainwindow.h"
16 *Constructor of this class.
17 *@param QWidget pointer to parent object. By default the value is NULL.
19 CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::CarMainWindow)
22 ui->tabWidget->setCurrentWidget(this->ui->StartTab);
23 //result = new ResultDialog();
24 //measure = new MeasureDialog();
25 welcomeDialog = new WelcomeDialog();
26 welcomeDialog->show();
28 initComboBoxStartTabUnits();
29 initListViewStartTabAccelerationCategories();
31 myLogin = new LoginWindow(this);
32 categorylist = new CategoryList();
33 myHttpClient = new HttpClient(this);
34 myRegistration = new Registration(this);
35 connect(myRegistration,SIGNAL(sendregistration()),this,SLOT(regUserToServer()));
36 connect(myLogin,SIGNAL(userNameChanged()),this,SLOT(userLogin()));
37 myRoute = new RouteDialog( this);
40 location = new Maemo5Location(this);
41 gpsData = new GPSData(location);
42 connect(location,SIGNAL(agnss()),this,SLOT(gpsStatus()));
48 accelerometer = new Accelerometer();
49 accelerometer->setSampleRate(100);
51 measures = new Measures();
52 this->initializeMeasures();
54 timer->setInterval(300);
56 connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
57 connect(myLogin, SIGNAL( userNameChanged()), this, SLOT(updateUserName()));
59 ui->labelMeasureTabResult->hide();
61 this->setWindowTitle("Speed Freak");
66 *Destructor of this class. Deletes all dynamic objects and sets them to NULL.
68 CarMainWindow::~CarMainWindow()
85 *This function is used to .
88 void CarMainWindow::changeEvent(QEvent *e)
90 QMainWindow::changeEvent(e);
92 case QEvent::LanguageChange:
93 ui->retranslateUi(this);
101 *This slot function is called when ever list view is update. Start-tab view.
103 void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelIndex index)
105 QString str = index.data().toString();
106 QStringList list = str.split("-");
107 QStringList list2 = list[1].split(" ");
109 ui->lineEditStartTabMin->setText(list[0]);
110 ui->lineEditStartTabMax->setText(list2[0]);
111 updateComboBoxStartTabUnits(list2[1]);
115 *This slot function is called when ever auto start button clicked. Start-tab view.
117 void CarMainWindow::on_autoStartButton_clicked()
122 //measure = new MeasureDialog();
123 // connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
124 accelerometer->start();
126 // Show measure dialog.
128 ui->tabWidget->setCurrentWidget(this->ui->tabMeasureResult);
132 *This slot function is called when ever list view is update. Start-tab view.
133 *@param QString unit.
135 void CarMainWindow::updateComboBoxStartTabUnits(QString unit)
137 ui->comboBoxStartTabUnits->setCurrentIndex(ui->comboBoxStartTabUnits->findText(unit, Qt::MatchExactly));
141 *This function is used to init unit combobox. Start-tab view.
143 void CarMainWindow::initComboBoxStartTabUnits()
145 units << "km/h" << "km" << "h" << "m" << "min" << "Mile" << "Mph" << "in" << "ft" << "yrd";
146 ui->comboBoxStartTabUnits->addItems(units);
150 *This function is used to set items to unit combobox. Start-tab view.
151 *@param QStringlist units
153 void CarMainWindow::setComboBoxStartTabUnits(QStringList units)
155 ui->comboBoxStartTabUnits->addItems(units);
159 *This function is used to init listViewStartTabAccelerationCategories. Start-tab view.
161 void CarMainWindow::initListViewStartTabAccelerationCategories()
163 accelerationCategoriesStartTab << "0-40 km/h" << "0-100 km/h"; //<< "0-1/4 Mile" << "0-1/8 Mile" << "0-50 km" << "50-100 Mile" << "0-60 Mph" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
164 QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
165 ui->listViewStartTabAccelerationCategories->setModel(model);
169 *This function is used to set items to listViewStartTabAccelerationCategories. Start-tab view.
170 *@param QStringlist accelerationCategoriesStartTab
172 void CarMainWindow::setListViewStartTabAccelerationCategories(QStringList accelerationCategoriesStartTab)
174 QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
175 ui->listViewStartTabAccelerationCategories->setModel(model);
179 *This function is used to set items to category combobox. Top-tab view.
182 void CarMainWindow::setCategoryCompoBox()
184 ui->comboBoxTopCategory->addItems(categorylist->getCategoryList());
188 *This function is used to set items to labelTopList. Top-tab view.
189 *@param QString category
191 void CarMainWindow::setListViewTopList(QString category, int size)
194 topList.append( categorylist->getTopList(category, size));
195 ui->labelTopList->setText(topList);
199 *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
201 void CarMainWindow::openResultView()
203 //result->saveMeasuresToArray(measure->measures);
204 // Show result dialog.
206 ui->pushButtonSendResult->setEnabled(true);
208 timeInteger.setNum(this->measures->getTime40kmh());
209 //time = "0 - 40 km/h: ";
210 //time.append(timeInteger);
211 //ui->labelResult40kmh->setText(time);
212 ui->labelMeasureTabResult->show();
213 ui->labelMeasureTabResult->setText(timeInteger);
214 //ui->tabWidget->setCurrentWidget(this->ui->tabMeasureResult);
218 *This slot function is called when registrate button is clicked.
220 void CarMainWindow::on_registratePushButton_clicked()
222 myRegistration->show();
226 *This slot function is called when ever refresh button clicked. Top-tab view.
228 void CarMainWindow::on_buttonTopRefresh_clicked()
230 myHttpClient->requestCategories();
231 setCategoryCompoBox();
235 *This slot function is called when ever category combobox current index changed. Top-tab view.
236 *@param QString category
237 *@todo Check where limitNr is taken.
239 void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
241 int limitNr = 5; //replace with real value?
242 QString limit = QString::number(limitNr);
243 category = "acceleration-0-100"; //replace with real value from category list/top window
244 myHttpClient->requestTopList(category, limit);
245 setListViewTopList(category,10);
249 *This slot function is called when ever category combobox activated. Top-tab view.
250 *@param QString category
252 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
254 setListViewTopList(category,10);
258 *This slot function is called when set/change user button is clicked.
260 void CarMainWindow::on_setUserPushButton_clicked()
266 *@brief Just for development, for the real button is not shown until
267 *measurin started and there are results.
268 *@todo Implement with real code and yet leave sendXml in the bottom in use.
270 void CarMainWindow::on_manualStartButton_clicked()
276 * This slot function is called when timer gives timeout signal. Checks current speed
277 * and stores times in measure class.
279 void CarMainWindow::after_timeout()
281 QString timeString, speedString;
283 time = accelerometer->getTotalTime();
284 speed = accelerometer->getCurrentSpeed();
287 if (floor(speed) == 10)
289 measures->setTime10kmh(time);
292 else if (floor(speed) == 20)
294 measures->setTime20kmh(time);
297 else if (floor(speed) == 30)
299 measures->setTime30kmh(time);
302 else if (floor(speed) == 40)
304 measures->setTime40kmh(time);
307 else if (floor(speed) == 50)
309 measures->setTime50kmh(time);
312 else if (floor(speed) == 60)
314 measures->setTime60kmh(time);
317 else if (floor(speed) == 70)
319 measures->setTime70kmh(time);
322 else if (floor(speed) == 80)
324 measures->setTime80kmh(time);
327 else if (floor(speed) == 90)
329 measures->setTime90kmh(time);
332 else if (floor(speed) == 100)
334 measures->setTime100kmh(time);
342 // If speed is over 40 km/h emits speedAchieved() signal and close this dialog.
346 accelerometer->stop();
349 //emit this->speedAchieved();
350 this->openResultView();
355 // Updates speed and time.
358 timeString.setNum(time);
359 speedString.setNum(speed);
360 ui->labelMeasureTabTime->setText(timeString);
361 ui->labelMeasureTabSpeed->setText(speedString);
369 * Initializes measures class's member variables.
371 void CarMainWindow::initializeMeasures()
373 measures->setTime10kmh(0);
374 measures->setTime20kmh(0);
375 measures->setTime30kmh(0);
376 measures->setTime40kmh(0);
377 measures->setTime50kmh(0);
378 measures->setTime60kmh(0);
379 measures->setTime70kmh(0);
380 measures->setTime80kmh(0);
381 measures->setTime90kmh(0);
382 measures->setTime100kmh(0);
386 * This slot function is called when Abort button is clicked.
388 void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
390 measures->setTime10kmh(0);
391 measures->setTime20kmh(0);
392 measures->setTime30kmh(0);
393 measures->setTime40kmh(0);
394 measures->setTime50kmh(0);
395 measures->setTime60kmh(0);
396 measures->setTime70kmh(0);
397 measures->setTime80kmh(0);
398 measures->setTime90kmh(0);
399 measures->setTime100kmh(0);
401 accelerometer->stop();
404 ui->tabWidget->setCurrentWidget(this->ui->StartTab);
408 void CarMainWindow::on_pushButtonSendResult_clicked()
410 myHttpClient->sendResultXml();
411 ui->pushButtonSendResult->setEnabled(false);
414 void CarMainWindow::updateUserName()
418 newUserName = myLogin->getUserName();
419 ui->userNameLabel->setText( "User: " + newUserName);
421 if (newUserName.length())
423 ui->setUserPushButton->setText( "Change User");
424 this->setWindowTitle("Speed freak - " + newUserName);
428 ui->setUserPushButton->setText( "Set User");
429 this->setWindowTitle("Speed freak");
433 void CarMainWindow::regUserToServer()
435 myHttpClient->requestRegistration();
439 void CarMainWindow::on_drawRoutePushButton_clicked()
444 void CarMainWindow::userLogin()
446 myHttpClient->checkLogin();
450 *This slot function is called when GPS on checkbox state changed. Route-tab view.
453 void CarMainWindow::on_gpsOnCheckBox_stateChanged(int GPSState)
457 ui->labelRouteTabGPSStatus->setText("GPS off");//testing
458 location->stopPollingGPS();
462 ui->labelRouteTabGPSStatus->setText("GPS on");//testing
463 location->startPollingGPS();
468 *This slot function is called when GPS status changed. Route-tab view.
470 void CarMainWindow::gpsStatus()
472 if (ui->gpsOnCheckBox->isChecked())
474 if (location->getSatellitesInUse() >= 4)
476 ui->labelRouteTabGPSStatus->setText("GPS ready");
481 ui->labelRouteTabGPSStatus->setText("Waiting for GPS");