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);
43 accelerometer = new Accelerometer();
44 accelerometer->setSampleRate(100);
46 measures = new Measures();
47 this->initializeMeasures();
49 timer->setInterval(300);
51 connect(this->timer, SIGNAL(timeout()), this, SLOT(after_timeout()));
52 connect(myLogin, SIGNAL( userNameChanged()), this, SLOT(updateUserName()));
54 ui->labelMeasureTabResult->hide();
56 this->setWindowTitle("Speed Freak");
61 *Destructor of this class. Should be used to release all allocated resources.
63 CarMainWindow::~CarMainWindow()
74 *This function is used to .
77 void CarMainWindow::changeEvent(QEvent *e)
79 QMainWindow::changeEvent(e);
81 case QEvent::LanguageChange:
82 ui->retranslateUi(this);
90 *This slot function is called when ever list view is update. Start-tab view.
92 void CarMainWindow::on_listViewStartTabAccelerationCategories_clicked(QModelIndex index)
94 QString str = index.data().toString();
95 QStringList list = str.split("-");
96 QStringList list2 = list[1].split(" ");
98 ui->lineEditStartTabMin->setText(list[0]);
99 ui->lineEditStartTabMax->setText(list2[0]);
100 updateComboBoxStartTabUnits(list2[1]);
104 *This slot function is called when ever auto start button clicked. Start-tab view.
106 void CarMainWindow::on_autoStartButton_clicked()
111 //measure = new MeasureDialog();
112 // connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
113 accelerometer->start();
115 // Show measure dialog.
117 ui->tabWidget->setCurrentWidget(this->ui->tabMeasureResult);
121 *This slot function is called when ever list view is update. Start-tab view.
122 *@param QString unit.
124 void CarMainWindow::updateComboBoxStartTabUnits(QString unit)
126 ui->comboBoxStartTabUnits->setCurrentIndex(ui->comboBoxStartTabUnits->findText(unit, Qt::MatchExactly));
130 *This function is used to init unit combobox. Start-tab view.
132 void CarMainWindow::initComboBoxStartTabUnits()
134 units << "km/h" << "km" << "h" << "m" << "min" << "Mile" << "Mph" << "in" << "ft" << "yrd";
135 ui->comboBoxStartTabUnits->addItems(units);
139 *This function is used to set items to unit combobox. Start-tab view.
140 *@param QStringlist units
142 void CarMainWindow::setComboBoxStartTabUnits(QStringList units)
144 ui->comboBoxStartTabUnits->addItems(units);
148 *This function is used to init listViewStartTabAccelerationCategories. Start-tab view.
150 void CarMainWindow::initListViewStartTabAccelerationCategories()
152 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";
153 QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
154 ui->listViewStartTabAccelerationCategories->setModel(model);
158 *This function is used to set items to listViewStartTabAccelerationCategories. Start-tab view.
159 *@param QStringlist accelerationCategoriesStartTab
161 void CarMainWindow::setListViewStartTabAccelerationCategories(QStringList accelerationCategoriesStartTab)
163 QAbstractItemModel *model = new StringListModel(accelerationCategoriesStartTab);
164 ui->listViewStartTabAccelerationCategories->setModel(model);
168 *This function is used to set items to category combobox. Top-tab view.
171 void CarMainWindow::setCategoryCompoBox()
173 ui->comboBoxTopCategory->addItems(categorylist->getCategoryList());
177 *This function is used to set items to labelTopList. Top-tab view.
178 *@param QString category
180 void CarMainWindow::setListViewTopList(QString category, int size)
183 topList.append( categorylist->getTopList(category, size));
184 ui->labelTopList->setText(topList);
188 *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
190 void CarMainWindow::openResultView()
192 //result->saveMeasuresToArray(measure->measures);
193 // Show result dialog.
195 ui->pushButtonSendResult->setEnabled(true);
197 timeInteger.setNum(this->measures->getTime40kmh());
198 //time = "0 - 40 km/h: ";
199 //time.append(timeInteger);
200 //ui->labelResult40kmh->setText(time);
201 ui->labelMeasureTabResult->show();
202 ui->labelMeasureTabResult->setText(timeInteger);
203 //ui->tabWidget->setCurrentWidget(this->ui->tabMeasureResult);
207 *This slot function is called when registrate button is clicked.
209 void CarMainWindow::on_registratePushButton_clicked()
211 myRegistration->show();
215 *This slot function is called when ever refresh button clicked. Top-tab view.
217 void CarMainWindow::on_buttonTopRefresh_clicked()
219 myHttpClient->requestCategories();
220 setCategoryCompoBox();
224 *This slot function is called when ever category combobox current index changed. Top-tab view.
225 *@param QString category
226 *@todo Check where limitNr is taken.
228 void CarMainWindow::on_comboBoxTopCategory_currentIndexChanged(QString category)
230 int limitNr = 5; //replace with real value?
231 QString limit = QString::number(limitNr);
232 category = "acceleration-0-100"; //replace with real value from category list/top window
233 myHttpClient->requestTopList(category, limit);
234 setListViewTopList(category,10);
238 *This slot function is called when ever category combobox activated. Top-tab view.
239 *@param QString category
241 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
243 setListViewTopList(category,10);
247 *This slot function is called when set/change user button is clicked.
249 void CarMainWindow::on_setUserPushButton_clicked()
255 *@brief Just for development, for the real button is not shown until
256 *measurin started and there are results.
257 *@todo Implement with real code and yet leave sendXml in the bottom in use.
259 void CarMainWindow::on_manualStartButton_clicked()
265 * This slot function is called when timer gives timeout signal. Checks current speed
266 * and stores times in measure class.
268 void CarMainWindow::after_timeout()
270 QString timeString, speedString;
272 time = accelerometer->getTotalTime();
273 speed = accelerometer->getCurrentSpeed();
276 if (floor(speed) == 10)
278 measures->setTime10kmh(time);
281 else if (floor(speed) == 20)
283 measures->setTime20kmh(time);
286 else if (floor(speed) == 30)
288 measures->setTime30kmh(time);
291 else if (floor(speed) == 40)
293 measures->setTime40kmh(time);
296 else if (floor(speed) == 50)
298 measures->setTime50kmh(time);
301 else if (floor(speed) == 60)
303 measures->setTime60kmh(time);
306 else if (floor(speed) == 70)
308 measures->setTime70kmh(time);
311 else if (floor(speed) == 80)
313 measures->setTime80kmh(time);
316 else if (floor(speed) == 90)
318 measures->setTime90kmh(time);
321 else if (floor(speed) == 100)
323 measures->setTime100kmh(time);
331 // If speed is over 40 km/h emits speedAchieved() signal and close this dialog.
335 accelerometer->stop();
338 //emit this->speedAchieved();
339 this->openResultView();
344 // Updates speed and time.
347 timeString.setNum(time);
348 speedString.setNum(speed);
349 ui->labelMeasureTabTime->setText(timeString);
350 ui->labelMeasureTabSpeed->setText(speedString);
358 * Initializes measures class's member variables.
360 void CarMainWindow::initializeMeasures()
362 measures->setTime10kmh(0);
363 measures->setTime20kmh(0);
364 measures->setTime30kmh(0);
365 measures->setTime40kmh(0);
366 measures->setTime50kmh(0);
367 measures->setTime60kmh(0);
368 measures->setTime70kmh(0);
369 measures->setTime80kmh(0);
370 measures->setTime90kmh(0);
371 measures->setTime100kmh(0);
375 * This slot function is called when Abort button is clicked.
377 void CarMainWindow::on_pushButtonMeasureTabAbort_clicked()
379 measures->setTime10kmh(0);
380 measures->setTime20kmh(0);
381 measures->setTime30kmh(0);
382 measures->setTime40kmh(0);
383 measures->setTime50kmh(0);
384 measures->setTime60kmh(0);
385 measures->setTime70kmh(0);
386 measures->setTime80kmh(0);
387 measures->setTime90kmh(0);
388 measures->setTime100kmh(0);
390 accelerometer->stop();
393 ui->tabWidget->setCurrentWidget(this->ui->StartTab);
397 void CarMainWindow::on_pushButtonSendResult_clicked()
399 myHttpClient->sendResultXml();
400 ui->pushButtonSendResult->setEnabled(false);
403 void CarMainWindow::updateUserName()
407 newUserName = myLogin->getUserName();
408 ui->userNameLabel->setText( "User: " + newUserName);
410 if (newUserName.length())
412 ui->setUserPushButton->setText( "Change User");
413 this->setWindowTitle("Speed freak - " + newUserName);
417 ui->setUserPushButton->setText( "Set User");
418 this->setWindowTitle("Speed freak");
422 void CarMainWindow::regUserToServer()
424 myHttpClient->requestRegistration();
428 void CarMainWindow::on_drawRoutePushButton_clicked()
433 void CarMainWindow::userLogin()
435 myHttpClient->checkLogin();