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 "hatbutton.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); |
59 GBoxHedgehogs = new QGroupBox(this); |
60 GBoxHedgehogs = new QGroupBox(this); |
60 GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members")); |
61 GBoxHedgehogs->setTitle(QGroupBox::tr("Team Members")); |
61 GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
62 GBoxHedgehogs->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
62 QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs); |
63 QGridLayout * GBHLayout = new QGridLayout(GBoxHedgehogs); |
63 |
64 |
64 HatModel * hatModel = DataManager::instance().hatModel(); |
65 |
|
66 GBHLayout->addWidget(new QLabel(tr("Hat")), 0, 0); |
|
67 GBHLayout->addWidget(new QLabel(tr("Name")), 0, 1); |
65 |
68 |
66 for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
69 for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++) |
67 { |
70 { |
68 HHHats[i] = new QComboBox(GBoxHedgehogs); |
71 HHHats[i] = new HatButton(GBoxHedgehogs); |
69 HHHats[i]->setModel(hatModel); |
72 GBHLayout->addWidget(HHHats[i], i + 1, 0); |
70 HHHats[i]->setIconSize(QSize(32, 37)); |
|
71 //HHHats[i]->setSizeAdjustPolicy(QComboBox::AdjustToContents); |
|
72 //HHHats[i]->setModelColumn(1); |
|
73 //HHHats[i]->setMinimumWidth(132); |
|
74 GBHLayout->addWidget(HHHats[i], i, 0); |
|
75 |
73 |
76 HHNameEdit[i] = new QLineEdit(GBoxHedgehogs); |
74 HHNameEdit[i] = new QLineEdit(GBoxHedgehogs); |
77 HHNameEdit[i]->setMaxLength(64); |
75 HHNameEdit[i]->setMaxLength(64); |
78 HHNameEdit[i]->setMinimumWidth(120); |
76 HHNameEdit[i]->setMinimumWidth(120); |
79 GBHLayout->addWidget(HHNameEdit[i], i, 1); |
77 HHNameEdit[i]->setFixedHeight(36); |
80 |
78 HHNameEdit[i]->setWhatsThis(tr("This hedgehog's name")); |
81 btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i, 3, 1, 1, true); |
79 HHNameEdit[i]->setStyleSheet("padding: 6px;"); |
82 } |
80 GBHLayout->addWidget(HHNameEdit[i], i + 1, 1); |
83 |
81 |
84 btnRandomTeam = addButton(QPushButton::tr("Random Team"), GBHLayout, 9, 0); |
82 btnRandomHogName[i] = addButton(":/res/dice.png", GBHLayout, i + 1, 3, 1, 1, true); |
|
83 btnRandomHogName[i]->setFixedHeight(HHNameEdit[i]->height()); |
|
84 btnRandomHogName[i]->setWhatsThis(tr("Randomize this hedgehog's name")); |
|
85 } |
|
86 |
|
87 btnRandomTeam = new QPushButton(); |
|
88 btnRandomTeam->setText(tr("Random Team")); |
|
89 btnRandomTeam->setStyleSheet("padding: 6px 10px;"); |
|
90 GBHLayout->addWidget(btnRandomTeam, 9, 0, 1, 4, Qt::AlignCenter); |
|
91 btnRandomTeam->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); |
85 |
92 |
86 vbox1->addWidget(GBoxHedgehogs); |
93 vbox1->addWidget(GBoxHedgehogs); |
87 |
94 |
88 GBoxTeam = new QGroupBox(this); |
95 GBoxTeam = new QGroupBox(this); |
89 GBoxTeam->setTitle(QGroupBox::tr("Team Settings")); |
96 GBoxTeam->setTitle(QGroupBox::tr("Team Settings")); |
155 vbox2->addWidget(GBoxFort); |
162 vbox2->addWidget(GBoxFort); |
156 |
163 |
157 vbox1->addStretch(); |
164 vbox1->addStretch(); |
158 vbox2->addStretch(); |
165 vbox2->addStretch(); |
159 |
166 |
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; |
167 return pageLayout; |
207 } |
168 } |
208 |
169 |
209 QLayout * PageEditTeam::footerLayoutDefinition() |
170 QLayout * PageEditTeam::footerLayoutDefinition() |
210 { |
171 { |
211 return NULL; |
172 return NULL; |
212 } |
173 } |
213 |
174 |
214 void PageEditTeam::connectSignals() |
175 void PageEditTeam::connectSignals() |
215 { |
176 { |
216 connect(this, SIGNAL(goBack()), this, SLOT(saveTeam())); |
177 connect(this, SIGNAL(pageLeave()), this, SLOT(saveTeam())); |
217 |
178 |
218 signalMapper1 = new QSignalMapper(this); |
179 signalMapper1 = new QSignalMapper(this); |
219 signalMapper2 = new QSignalMapper(this); |
180 signalMapper2 = new QSignalMapper(this); |
220 |
181 |
221 connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int))); |
182 connect(signalMapper1, SIGNAL(mapped(int)), this, SLOT(fixHHname(int))); |
429 CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack())); |
393 CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack())); |
430 |
394 |
431 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
395 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
432 for(int i = 0; i < BINDS_NUMBER; i++) |
396 for(int i = 0; i < BINDS_NUMBER; i++) |
433 { |
397 { |
|
398 if (team.keyBind(i).isEmpty()) continue; |
|
399 |
434 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, team.keyBind(i), 1, Qt::MatchExactly); |
400 QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, team.keyBind(i), 1, Qt::MatchExactly); |
435 |
401 |
436 if(mdl.size() == 1) |
402 if(mdl.size() == 1) |
437 CBBind[i]->setCurrentIndex(mdl[0].row()); |
403 binder->setBindIndex(i, mdl[0].row()); |
438 else |
404 else |
439 qDebug() << "Binds: cannot find" << team.keyBind(i); |
405 qDebug() << "Binds: cannot find" << team.keyBind(i); |
440 } |
406 } |
441 } |
407 } |
442 |
408 |
463 team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString()); |
429 team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString()); |
464 |
430 |
465 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
431 QStandardItemModel * binds = DataManager::instance().bindsModel(); |
466 for(int i = 0; i < BINDS_NUMBER; i++) |
432 for(int i = 0; i < BINDS_NUMBER; i++) |
467 { |
433 { |
468 team.bindKey(i, binds->index(CBBind[i]->currentIndex(), 0).data(Qt::UserRole + 1).toString()); |
434 team.bindKey(i, binds->index(binder->bindIndex(i), 0).data(Qt::UserRole + 1).toString()); |
469 } |
435 } |
470 |
436 |
471 return team; |
437 return team; |
472 } |
438 } |
473 |
439 |
474 void PageEditTeam::saveTeam() |
440 void PageEditTeam::saveTeam() |
475 { |
441 { |
476 data().saveToFile(); |
442 data().saveToFile(); |
477 } |
443 } |
|
444 |
|
445 // When the "Use default for all binds" is pressed... |
|
446 void PageEditTeam::resetAllBinds() |
|
447 { |
|
448 for (int i = 0; i < BINDS_NUMBER; i++) |
|
449 binder->setBindIndex(i, 0); |
|
450 } |