28 #include <QMessageBox> |
28 #include <QMessageBox> |
29 #include <QStandardItemModel> |
29 #include <QStandardItemModel> |
30 #include <QDebug> |
30 #include <QDebug> |
31 #include "SquareLabel.h" |
31 #include "SquareLabel.h" |
32 #include "HWApplication.h" |
32 #include "HWApplication.h" |
|
33 #include "keybinder.h" |
33 |
34 |
34 #include "DataManager.h" |
35 #include "DataManager.h" |
35 #include "HatModel.h" |
36 #include "HatModel.h" |
36 |
37 |
37 #include "pageeditteam.h" |
38 #include "pageeditteam.h" |
38 |
39 |
39 QLayout * PageEditTeam::bodyLayoutDefinition() |
40 QLayout * PageEditTeam::bodyLayoutDefinition() |
40 { |
41 { |
41 QGridLayout * pageLayout = new QGridLayout(); |
42 QGridLayout * pageLayout = new QGridLayout(); |
42 QTabWidget * tbw = new QTabWidget(); |
43 tbw = new QTabWidget(); |
43 QWidget * page1 = new QWidget(this); |
44 QWidget * page1 = new QWidget(this); |
44 QWidget * page2 = new QWidget(this); |
45 binder = new KeyBinder(this, tr("Select an action to choose a custom key bind for this team"), tr("Use my default"), tr("Reset all binds")); |
|
46 connect(binder, SIGNAL(resetAllBinds()), this, SLOT(resetAllBinds())); |
45 tbw->addTab(page1, tr("General")); |
47 tbw->addTab(page1, tr("General")); |
46 tbw->addTab(page2, tr("Advanced")); |
48 tbw->addTab(binder, tr("Custom Controls")); |
47 pageLayout->addWidget(tbw, 0, 0, 1, 3); |
49 pageLayout->addWidget(tbw, 0, 0, 1, 3); |
48 |
50 |
49 QHBoxLayout * page1Layout = new QHBoxLayout(page1); |
51 QHBoxLayout * page1Layout = new QHBoxLayout(page1); |
50 page1Layout->setAlignment(Qt::AlignTop); |
52 page1Layout->setAlignment(Qt::AlignTop); |
51 QGridLayout * page2Layout = new QGridLayout(page2); |
|
52 |
53 |
53 // ====== Page 1 ====== |
54 // ====== Page 1 ====== |
54 QVBoxLayout * vbox1 = new QVBoxLayout(); |
55 QVBoxLayout * vbox1 = new QVBoxLayout(); |
55 QVBoxLayout * vbox2 = new QVBoxLayout(); |
56 QVBoxLayout * vbox2 = new QVBoxLayout(); |
56 page1Layout->addLayout(vbox1); |
57 page1Layout->addLayout(vbox1); |
155 vbox2->addWidget(GBoxFort); |
156 vbox2->addWidget(GBoxFort); |
156 |
157 |
157 vbox1->addStretch(); |
158 vbox1->addStretch(); |
158 vbox2->addStretch(); |
159 vbox2->addStretch(); |
159 |
160 |
160 // ====== Page 2 ====== |
|
161 GBoxBinds = new QGroupBox(this); |
|
162 GBoxBinds->setTitle(QGroupBox::tr("Key binds")); |
|
163 QGridLayout * GBBLayout = new QGridLayout(GBoxBinds); |
|
164 BindsBox = new QToolBox(GBoxBinds); |
|
165 BindsBox->setLineWidth(0); |
|
166 GBBLayout->addWidget(BindsBox); |
|
167 page2Layout->addWidget(GBoxBinds, 0, 0); |
|
168 |
|
169 quint16 i = 0; |
|
170 quint16 num = 0; |
|
171 QWidget * curW = NULL; |
|
172 QGridLayout * pagelayout = NULL; |
|
173 QLabel* l = NULL; |
|
174 while (i < BINDS_NUMBER) |
|
175 { |
|
176 if(cbinds[i].category != NULL) |
|
177 { |
|
178 if(curW != NULL) |
|
179 { |
|
180 l = new QLabel(curW); |
|
181 l->setText(""); |
|
182 pagelayout->addWidget(l, num++, 0, 1, 2); |
|
183 } |
|
184 curW = new QWidget(this); |
|
185 BindsBox->addItem(curW, HWApplication::translate("binds (categories)", cbinds[i].category)); |
|
186 pagelayout = new QGridLayout(curW); |
|
187 num = 0; |
|
188 } |
|
189 if(cbinds[i].description != NULL) |
|
190 { |
|
191 l = new QLabel(curW); |
|
192 l->setText((num > 0 ? QString("\n") : QString("")) + HWApplication::translate("binds (descriptions)", cbinds[i].description)); |
|
193 pagelayout->addWidget(l, num++, 0, 1, 2); |
|
194 } |
|
195 |
|
196 l = new QLabel(curW); |
|
197 l->setText(HWApplication::translate("binds", cbinds[i].name)); |
|
198 l->setAlignment(Qt::AlignRight); |
|
199 pagelayout->addWidget(l, num, 0); |
|
200 |
|
201 CBBind[i] = new QComboBox(curW); |
|
202 CBBind[i]->setModel(DataManager::instance().bindsModel()); |
|
203 pagelayout->addWidget(CBBind[i++], num++, 1); |
|
204 } |
|
205 |
|
206 return pageLayout; |
161 return pageLayout; |
207 } |
162 } |
208 |
163 |
209 QLayout * PageEditTeam::footerLayoutDefinition() |
164 QLayout * PageEditTeam::footerLayoutDefinition() |
210 { |
165 { |
429 CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack())); |
387 CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack())); |
430 |
388 |
431 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
389 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
432 for(int i = 0; i < BINDS_NUMBER; i++) |
390 for(int i = 0; i < BINDS_NUMBER; i++) |
433 { |
391 { |
|
392 if (team.keyBind(i).isEmpty()) continue; |
|
393 |
434 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, team.keyBind(i), 1, Qt::MatchExactly); |
394 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, team.keyBind(i), 1, Qt::MatchExactly); |
435 |
395 |
436 if(mdl.size() == 1) |
396 if(mdl.size() == 1) |
437 CBBind[i]->setCurrentIndex(mdl[0].row()); |
397 binder->setBindIndex(i, mdl[0].row()); |
438 else |
398 else |
439 qDebug() << "Binds: cannot find" << team.keyBind(i); |
399 qDebug() << "Binds: cannot find" << team.keyBind(i); |
440 } |
400 } |
441 } |
401 } |
442 |
402 |
463 team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString()); |
423 team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString()); |
464 |
424 |
465 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
425 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
466 for(int i = 0; i < BINDS_NUMBER; i++) |
426 for(int i = 0; i < BINDS_NUMBER; i++) |
467 { |
427 { |
468 team.bindKey(i, binds->index(CBBind[i]->currentIndex(), 0).data(Qt::UserRole + 1).toString()); |
428 team.bindKey(i, binds->index(binder->bindIndex(i), 0).data(Qt::UserRole + 1).toString()); |
469 } |
429 } |
470 |
430 |
471 return team; |
431 return team; |
472 } |
432 } |
473 |
433 |
474 void PageEditTeam::saveTeam() |
434 void PageEditTeam::saveTeam() |
475 { |
435 { |
476 data().saveToFile(); |
436 data().saveToFile(); |
477 } |
437 } |
|
438 |
|
439 // When the "Use default for all binds" is pressed... |
|
440 void PageEditTeam::resetAllBinds() |
|
441 { |
|
442 for (int i = 0; i < BINDS_NUMBER; i++) |
|
443 binder->setBindIndex(i, 0); |
|
444 } |