Integrated registration & login dialogs to UI
[speedfreak] / Client / carmainwindow.cpp
1 #include "carmainwindow.h"
2 #include "ui_carmainwindow.h"
3 #include "stringlistmodel.h"
4 #include "loginwindow.h"
5 #include <QStandardItemModel>
6 #include <QStringList>
7 #include <QString>
8 #include <QNetworkRequest>
9
10 /**
11   *Constructor of this class.
12   *@param QWidget pointer to parent object. By default the value is NULL.
13   */
14 CarMainWindow::CarMainWindow(QWidget *parent):QMainWindow(parent), ui(new Ui::CarMainWindow)
15 {
16     ui->setupUi(this);
17     result = new ResultDialog();
18     measure = new MeasureDialog();
19
20     initUnitCompoBox();
21     initSpeedListView();
22     initCategoryCompoBox();
23
24     myLogin = new LoginWindow(this);
25     myRegistration = new Registration(this);
26     manager = new QNetworkAccessManager(this);
27     connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(networkResponse(QNetworkReply*)));
28
29 }
30
31 /**
32   *Destructor of this class. Should be used to release all allocated resources.
33   */
34 CarMainWindow::~CarMainWindow()
35 {
36     delete ui;
37     delete result;
38     delete measure;
39 }
40
41 /**
42   *This function is used to .
43   *@param
44   */
45 void CarMainWindow::changeEvent(QEvent *e)
46 {
47     QMainWindow::changeEvent(e);
48     switch (e->type()) {
49     case QEvent::LanguageChange:
50         ui->retranslateUi(this);
51         break;
52     default:
53         break;
54     }
55 }
56
57 /**
58   *This slot function is called when ever list view is update.
59   *@param QModelIndex index.
60   */
61 void CarMainWindow::on_listView_clicked(QModelIndex index)
62 {
63     QString str = index.data().toString();
64     QStringList list = str.split("-");
65     QStringList list2 = list[1].split(" ");
66
67     ui->minLineEdit->setText(list[0]);
68     ui->maxLineEdit->setText(list2[0]);
69     updateUnitCompoBox(list2[1]);
70 }
71
72 /**
73   *This slot function is called when ever auto start button clicked.
74   */
75 void CarMainWindow::on_autoStartButton_clicked()
76 {
77     if(measure)
78     {
79         delete measure;
80         measure = NULL;
81         measure = new MeasureDialog();
82     }
83
84     connect(measure, SIGNAL(speedAchieved()), this, SLOT(openResultView()));
85
86     // Show measure dialog.
87     measure->show();
88 }
89
90 /**
91   *This slot function is called when ever list view is update.
92   *@param QString unit.
93   */
94 void CarMainWindow::updateUnitCompoBox(QString unit)
95 {
96     ui->unitComboBox->setCurrentIndex(ui->unitComboBox->findText(unit, Qt::MatchExactly));
97 }
98
99 /**
100   *This function is used to init unit combobox.
101   */
102 void CarMainWindow::initUnitCompoBox()
103 {
104     units << "km/h" << "km" << "h" << "m" << "min" << "mil" << "in" << "ft" << "yrd";
105     ui->unitComboBox->addItems(units);
106 }
107
108 /**
109   *This function is used to set items to unit combobox.
110   *@param QStringlist numbers
111   */
112 void CarMainWindow::setUnitCompoBox(QStringList units)
113 {
114     ui->unitComboBox->addItems(units);
115 }
116
117 /**
118   *This function is used to init speed listview.
119   */
120 void CarMainWindow::initSpeedListView()
121 {
122     numbers << "0-100 km/h" << "0-1/4 mil" << "0-50 km" << "50-100 mil" << "0-100 m" << "0-50 ft" << "0-50 yrd" << "0-500 in";
123     QAbstractItemModel *model = new StringListModel(numbers);
124     ui->listView->setModel(model);
125 }
126
127 /**
128 <<<<<<< HEAD:Client/carmainwindow.cpp
129   *This function is used to set items to speed listview.
130   *@param QStringlist numbers
131   */
132 void CarMainWindow::setSpeedListView(QStringList numbers)
133 {
134     QAbstractItemModel *model = new StringListModel(numbers);
135     ui->listView->setModel(model);
136 }
137
138 /**
139   *This function is used to init category combobox.
140   */
141 void CarMainWindow::initCategoryCompoBox()
142 {
143     categories << "Top 10 1/4 mile" << "Top 10 0-100 km/h" << "Top 10 car";
144     ui->comboBoxTopCategory->addItems(categories);
145 }
146
147 /**
148   *This function is used to set items to category combobox.
149   *@param QStringlist categories
150   */
151 void CarMainWindow::setCategoryCompoBox(QStringList categories)
152 {
153     ui->comboBoxTopCategory->addItems(categories);
154 }
155
156 /**
157   *This slot function is called when ever categories combobox is update.
158   *@param QString category
159   */
160 void CarMainWindow::on_comboBoxTopCategory_activated(QString category)
161 {
162     //TODO: get top list
163
164     QStringList topList;
165     topList << "1. Pertti 7,5s" << "2. Ville 10,2s";
166
167     QAbstractItemModel *model = new StringListModel(topList);
168     ui->listViewTopList->setModel(model);
169 }
170
171 /**
172   *This slot function is called when speed is achieved in measure dialog. Opens result dialog.
173   */
174 void CarMainWindow::openResultView()
175 {
176     // Show result dialog.
177     result->show();
178 }
179
180 /**
181   *This slot function is called when the server has finished guery.
182   */
183 void CarMainWindow::networkResponse(QNetworkReply *reply)
184 {
185 }
186
187 /**
188   *This slot function is called when the user will to send data to server.
189   */
190 void CarMainWindow::on_pushButton_clicked()
191 {
192      QNetworkRequest postData;
193      postData.setUrl(QString("http://weather.yahooapis.com/forecastrss?p=FIXX0013&u=c"));
194      manager->get(postData);
195
196 }
197
198 /**
199   *This slot function is called when login/logout button is clicked.
200   */
201 void CarMainWindow::on_loginLogoutButton_clicked()
202 {
203     //LoginWindow myLogin;
204
205     myLogin->show();
206     //ui->loginLogoutButton->setText("logout");
207 }
208
209 /**
210   *This slot function is called when registrate button is clicked.
211   */
212 void CarMainWindow::on_registratePushButton_clicked()
213 {
214     myRegistration->show();
215 }