QTfrontend/ui/page/pageeditteam.cpp
branchflibqtfrontend
changeset 8363 0b4ac686fc44
parent 8103 c247346d296f
parent 8346 3443e0de2c9d
equal deleted inserted replaced
8306:50fe80adbfcb 8363:0b4ac686fc44
    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 {
   405     loadTeam(team);
   360     loadTeam(team);
   406 }
   361 }
   407 
   362 
   408 void PageEditTeam::loadTeam(const HWTeam & team)
   363 void PageEditTeam::loadTeam(const HWTeam & team)
   409 {
   364 {
       
   365     tbw->setCurrentIndex(0);
       
   366     binder->resetInterface();
       
   367     
   410     TeamNameEdit->setText(team.name());
   368     TeamNameEdit->setText(team.name());
   411     CBTeamLvl->setCurrentIndex(team.difficulty());
   369     CBTeamLvl->setCurrentIndex(team.difficulty());
   412 
   370 
   413     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
   371     for(int i = 0; i < HEDGEHOGS_PER_TEAM; i++)
   414     {
   372     {
   428     CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack()));
   386     CBVoicepack->setCurrentIndex(CBVoicepack->findText(team.voicepack()));
   429 
   387 
   430     QStandardItemModel * binds = DataManager::instance().bindsModel();
   388     QStandardItemModel * binds = DataManager::instance().bindsModel();
   431     for(int i = 0; i < BINDS_NUMBER; i++)
   389     for(int i = 0; i < BINDS_NUMBER; i++)
   432     {
   390     {
       
   391         if (team.keyBind(i).isEmpty()) continue;
       
   392         
   433         QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, team.keyBind(i), 1, Qt::MatchExactly);
   393         QModelIndexList mdl = binds->match(binds->index(0, 0), Qt::UserRole + 1, team.keyBind(i), 1, Qt::MatchExactly);
   434 
   394 
   435         if(mdl.size() == 1)
   395         if(mdl.size() == 1)
   436             CBBind[i]->setCurrentIndex(mdl[0].row());
   396             binder->setBindIndex(i, mdl[0].row());
   437         else
   397         else
   438             qDebug() << "Binds: cannot find" << team.keyBind(i);
   398             qDebug() << "Binds: cannot find" << team.keyBind(i);
   439     }
   399     }
   440 }
   400 }
   441 
   401 
   461     team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString());
   421     team.setFlag(CBFlag->itemData(CBFlag->currentIndex()).toString());
   462 
   422 
   463     QStandardItemModel * binds = DataManager::instance().bindsModel();
   423     QStandardItemModel * binds = DataManager::instance().bindsModel();
   464     for(int i = 0; i < BINDS_NUMBER; i++)
   424     for(int i = 0; i < BINDS_NUMBER; i++)
   465     {
   425     {
   466         team.bindKey(i, binds->index(CBBind[i]->currentIndex(), 0).data(Qt::UserRole + 1).toString());
   426         team.bindKey(i, binds->index(binder->bindIndex(i), 0).data(Qt::UserRole + 1).toString());
   467     }
   427     }
   468 
   428 
   469     return team;
   429     return team;
   470 }
   430 }
   471 
   431 
   472 void PageEditTeam::saveTeam()
   432 void PageEditTeam::saveTeam()
   473 {
   433 {
   474     data().saveToFile();
   434     data().saveToFile();
   475 }
   435 }
       
   436 
       
   437 // When the "Use default for all binds" is pressed...
       
   438 void PageEditTeam::resetAllBinds()
       
   439 {
       
   440     for (int i = 0; i < BINDS_NUMBER; i++)
       
   441         binder->setBindIndex(i, 0);
       
   442 }