--- 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);
}
--- 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);
}
--- 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;
};
--- 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; i<m_numItems; ++i) {
if(i==6) continue;
if (k%4==0) ++j;
- weaponItems[i]=new SelWeaponItem(i, cDefaultAmmoStore->at(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; i<m_numItems; ++i) {
+ twi::iterator it=weaponItems.find(i);
+ if (it==weaponItems.end()) continue;
+ it->second->setItemsNum(ammo[i].digitValue());
+ }
+ update();
+}
+
+void SelWeaponWidget::setDefault()
+{
+ setWeapons(cDefaultAmmoStore->mid(10));
+}
+
+void SelWeaponWidget::save()
+{
+ currentState="";
+ for(int i=0; i<m_numItems; ++i) {
+ twi::const_iterator it=weaponItems.find(i);
+ int num = it==weaponItems.end() ? 9 : (*this)[i];
+ currentState = QString("%1%2").arg(currentState).arg(num);
+ }
+}
+
int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
{
- std::map<int, SelWeaponItem*>::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;
}
--- 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<int, SelWeaponItem*> weaponItems;
+ QString currentState;
+ const int m_numItems;
+ int operator [] (unsigned int weaponIndex) const;
+
+ typedef std::map<int, SelWeaponItem*> twi;
+ twi weaponItems;
QGridLayout* pLayout;
};