# HG changeset patch # User displacer # Date 1198148082 0 # Node ID 57d624f71e65c825646391babe7a9f5b24da6c4e # Parent a37b6966de84e46c654337fd8a5e1f042e097644 select default and save weapons added diff -r a37b6966de84 -r 57d624f71e65 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Wed Dec 19 20:54:00 2007 +0000 +++ b/QTfrontend/hwform.cpp Thu Dec 20 10:54:42 2007 +0000 @@ -118,6 +118,8 @@ connect(ui.pageTraining->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); connect(ui.pageSelectWeapon->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack())); + connect(ui.pageSelectWeapon->BtnDefault, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(setDefault())); + connect(ui.pageSelectWeapon->BtnSave, SIGNAL(clicked()), ui.pageSelectWeapon->pWeapons, SLOT(save())); GoToPage(ID_PAGE_MAIN); } diff -r a37b6966de84 -r 57d624f71e65 QTfrontend/pages.cpp --- a/QTfrontend/pages.cpp Wed Dec 19 20:54:00 2007 +0000 +++ b/QTfrontend/pages.cpp Thu Dec 20 10:54:42 2007 +0000 @@ -708,12 +708,22 @@ //pageLayout->setColumnStretch(1, 2); //pageLayout->setColumnStretch(2, 1); - pWeapons=new SelWeaponWidget(this); - pageLayout->addWidget(pWeapons, 0, 0); + pWeapons=new SelWeaponWidget(20, this); + pageLayout->addWidget(pWeapons, 0, 0, 1, 3); BtnBack = new QPushButton(this); BtnBack->setFont(*font14); BtnBack->setText(QPushButton::tr("Back")); pageLayout->addWidget(BtnBack, 1, 0); + + BtnDefault = new QPushButton(this); + BtnDefault->setFont(*font14); + BtnDefault->setText(QPushButton::tr("Default")); + pageLayout->addWidget(BtnDefault, 1, 1); + + BtnSave = new QPushButton(this); + BtnSave->setFont(*font14); + BtnSave->setText(QPushButton::tr("Save")); + pageLayout->addWidget(BtnSave, 1, 2); } diff -r a37b6966de84 -r 57d624f71e65 QTfrontend/pages.h --- a/QTfrontend/pages.h Wed Dec 19 20:54:00 2007 +0000 +++ b/QTfrontend/pages.h Thu Dec 20 10:54:42 2007 +0000 @@ -270,6 +270,8 @@ public: PageSelectWeapon(QWidget* parent = 0); + QPushButton *BtnSave; + QPushButton *BtnDefault; QPushButton *BtnBack; SelWeaponWidget* pWeapons; }; diff -r a37b6966de84 -r 57d624f71e65 QTfrontend/selectWeapon.cpp --- a/QTfrontend/selectWeapon.cpp Wed Dec 19 20:54:00 2007 +0000 +++ b/QTfrontend/selectWeapon.cpp Thu Dec 20 10:54:42 2007 +0000 @@ -56,39 +56,68 @@ hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter); } +void SelWeaponItem::setItemsNum(const unsigned char num) +{ + item->setItemsNum(num); +} + unsigned char SelWeaponItem::getItemsNum() const { return item->getItemsNum(); } -SelWeaponWidget::SelWeaponWidget(QWidget* parent) : -QWidget(parent) +SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) : + m_numItems(numItems), + QWidget(parent) { + currentState=cDefaultAmmoStore->mid(10); + pLayout=new QGridLayout(this); pLayout->setSpacing(1); pLayout->setMargin(1); int j=-1; - for(int i=0, k=0; i<20; ++i) { + for(int i=0, k=0; iat(10+i).digitValue(), this); + weaponItems[i]=new SelWeaponItem(i, currentState[i].digitValue(), this); pLayout->addWidget(weaponItems[i], j, k%4); ++k; } } +void SelWeaponWidget::setWeapons(QString ammo) +{ + for(int i=0; isecond->setItemsNum(ammo[i].digitValue()); + } + update(); +} + +void SelWeaponWidget::setDefault() +{ + setWeapons(cDefaultAmmoStore->mid(10)); +} + +void SelWeaponWidget::save() +{ + currentState=""; + for(int i=0; i::const_iterator it=weaponItems.find(weaponIndex); + twi::const_iterator it=weaponItems.find(weaponIndex); return it==weaponItems.end() ? 9 : it->second->getItemsNum(); } QString SelWeaponWidget::getWeaponsString() const { - QString ammo; - for(int i=0; i<20; ++i) { - ammo += (*this)[i]; - } - return ammo; + return currentState; } diff -r a37b6966de84 -r 57d624f71e65 QTfrontend/selectWeapon.h --- a/QTfrontend/selectWeapon.h Wed Dec 19 20:54:00 2007 +0000 +++ b/QTfrontend/selectWeapon.h Thu Dec 20 10:54:42 2007 +0000 @@ -33,6 +33,7 @@ SelWeaponItem(int iconNum, int wNum, QWidget* parent=0); unsigned char getItemsNum() const; + void setItemsNum(const unsigned char num); private: WeaponItem* item; @@ -43,12 +44,21 @@ Q_OBJECT public: - SelWeaponWidget(QWidget* parent=0); - int operator [] (unsigned int weaponIndex) const; + SelWeaponWidget(int numItems, QWidget* parent=0); QString getWeaponsString() const; + void setWeapons(QString ammo); + + public slots: + void setDefault(); + void save(); private: - std::map weaponItems; + QString currentState; + const int m_numItems; + int operator [] (unsigned int weaponIndex) const; + + typedef std::map twi; + twi weaponItems; QGridLayout* pLayout; };