Small fixes mixed with formatting changes
authorunc0rr
Mon, 24 Nov 2008 13:27:31 +0000
changeset 1509 34f7dd4efe84
parent 1508 ef093f31ced1
child 1510 98c5799c851b
Small fixes mixed with formatting changes
QTfrontend/hwform.cpp
QTfrontend/selectWeapon.cpp
QTfrontend/selectWeapon.h
--- a/QTfrontend/hwform.cpp	Sun Nov 23 23:16:33 2008 +0000
+++ b/QTfrontend/hwform.cpp	Mon Nov 24 13:27:31 2008 +0000
@@ -92,10 +92,10 @@
 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	config, SLOT(SaveOptions()));
 	connect(ui.pageOptions->BtnSaveOptions,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 
-	connect(ui.pageOptions->WeaponEdit,	SIGNAL(clicked()),	this, SLOT(GoToSelectWeapon()));
-	connect(ui.pageOptions->WeaponsButt,	SIGNAL(clicked()),	this, SLOT(GoToSelectNewWeapon()));
-	connect(ui.pageSelectWeapon->pWeapons,       SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons()));
-	connect(ui.pageNetGame->pGameCFG,       SIGNAL(newWeaponsName(const QString&)), this, SLOT(NetWeaponNameChanged(const QString&)));
+	connect(ui.pageOptions->WeaponEdit, SIGNAL(clicked()), this, SLOT(GoToSelectWeapon()));
+	connect(ui.pageOptions->WeaponsButt, SIGNAL(clicked()), this, SLOT(GoToSelectNewWeapon()));
+	connect(ui.pageSelectWeapon->pWeapons, SIGNAL(weaponsChanged()), this, SLOT(UpdateWeapons()));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(newWeaponsName(const QString&)), this, SLOT(NetWeaponNameChanged(const QString&)));
 
 	connect(ui.pageNet->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
 	connect(ui.pageNet->BtnSpecifyServer, SIGNAL(clicked()), this, SLOT(NetConnect()));
@@ -174,8 +174,8 @@
 	for(QVector<QComboBox*>::iterator it=combos.begin(); it!=combos.end(); ++it) {
 		(*it)->clear();
 		(*it)->addItems(ui.pageSelectWeapon->pWeapons->getWeaponNames());
-		int pos=(*it)->findText("Default");
-		if (pos!=-1) {
+		int pos = (*it)->findText("Default");
+		if (pos != -1) {
 			(*it)->setCurrentIndex(pos);
 		}
 	}
@@ -183,18 +183,17 @@
 
 void HWForm::NetWeaponNameChanged(const QString& name)
 {
-	QString ammo = ui.pageSelectWeapon->pWeapons->getWeaponsString(
-			ui.pageNetGame->pGameCFG->WeaponsName->currentText()
-			);
+	QString ammo = ui.pageSelectWeapon->pWeapons->getWeaponsString(name);
 
-	hwnet->onWeaponsNameChanged(name, ammo);
+	if (hwnet)
+		hwnet->onWeaponsNameChanged(name, ammo);
 }
 
 void HWForm::UpdateTeamsLists(const QStringList* editable_teams)
 {
 	QStringList teamslist;
 	if(editable_teams) {
-	  teamslist=*editable_teams;
+	  teamslist =* editable_teams;
 	} else {
 	  teamslist = config->GetTeamsList();
 	}
@@ -231,13 +230,13 @@
 
 void HWForm::GoToSelectNewWeapon()
 {
-  ui.pageSelectWeapon->pWeapons->setWeaponsName("", false);
+	ui.pageSelectWeapon->pWeapons->setWeaponsName(tr("new"));
 	GoToPage(ID_PAGE_SELECTWEAPON);
 }
 
 void HWForm::GoToSelectWeapon()
 {
-  ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText(), true);
+	ui.pageSelectWeapon->pWeapons->setWeaponsName(ui.pageOptions->WeaponsName->currentText());
 	GoToPage(ID_PAGE_SELECTWEAPON);
 }
 
@@ -350,21 +349,23 @@
 
 void HWForm::IntermediateSetup()
 {
-  quint8 id=ui.Pages->currentIndex();
-  TeamSelWidget* curTeamSelWidget;
-  if(id == ID_PAGE_MULTIPLAYER) {
-    curTeamSelWidget=ui.pageMultiplayer->teamsSelect;
-  } else {
-    curTeamSelWidget=ui.pageNetGame->pNetTeamsWidget;
-  }
-  QList<HWTeam> teams=curTeamSelWidget->getDontPlayingTeams();
-  QStringList tmnames;
-  for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) {
-    tmnames+=it->TeamName;
-  }
-  UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
+	quint8 id=ui.Pages->currentIndex();
+	TeamSelWidget* curTeamSelWidget;
+	
+	if(id == ID_PAGE_MULTIPLAYER) {
+		curTeamSelWidget = ui.pageMultiplayer->teamsSelect;
+	} else {
+		curTeamSelWidget = ui.pageNetGame->pNetTeamsWidget;
+	}
+	
+	QList<HWTeam> teams = curTeamSelWidget->getDontPlayingTeams();
+	QStringList tmnames;
+	for(QList<HWTeam>::iterator it = teams.begin(); it != teams.end(); ++it) {
+		tmnames += it->TeamName;
+	}
+	UpdateTeamsLists(&tmnames); // FIXME: still need more work if teamname is updated while configuring
 
-  GoToPage(ID_PAGE_SETUP);
+	GoToPage(ID_PAGE_SETUP);
 }
 
 void HWForm::NewTeam()
@@ -536,7 +537,7 @@
 	if(!pnetserver->StartServer(ui.pageNetServer->sbPort->value()))
 	{
 		QMessageBox::critical(0, tr("Error"),
-					tr("Unable to start the server"));
+				tr("Unable to start the server"));
 		delete pnetserver;
 		pnetserver = 0;
 		return;
@@ -556,22 +557,22 @@
 
 void HWForm::NetDisconnect()
 {
-  if(hwnet) {
-    hwnet->Disconnect();
-    delete hwnet;
-    hwnet = 0;
-  }
-  if(pnetserver) {
-    if (pRegisterServer)
-    {
-      pRegisterServer->unregister();
-      pRegisterServer = 0;
-    }
+	if(hwnet) {
+		hwnet->Disconnect();
+		delete hwnet;
+		hwnet = 0;
+	}
+	if(pnetserver) {
+		if (pRegisterServer)
+		{
+			pRegisterServer->unregister();
+			pRegisterServer = 0;
+		}
 
-    pnetserver->StopServer();
-    delete pnetserver;
-    pnetserver = 0;
-  }
+		pnetserver->StopServer();
+		delete pnetserver;
+		pnetserver = 0;
+	}
 }
 
 void HWForm::ForcedDisconnect()
--- a/QTfrontend/selectWeapon.cpp	Sun Nov 23 23:16:33 2008 +0000
+++ b/QTfrontend/selectWeapon.cpp	Mon Nov 24 13:27:31 2008 +0000
@@ -15,7 +15,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
- 
+
 #include "selectWeapon.h"
 #include "weaponItem.h"
 #include "hwconsts.h"
@@ -31,153 +31,154 @@
 
 QImage getAmmoImage(int num)
 {
-  static QImage ammo(":Ammos.png");
-  return ammo.copy(0, num*32, 32, 32);
+	static QImage ammo(":Ammos.png");
+	return ammo.copy(0, num*32, 32, 32);
 }
 
 SelWeaponItem::SelWeaponItem(int iconNum, int wNum, QWidget* parent) :
-  QWidget(parent)
+	QWidget(parent)
 {
-  QHBoxLayout* hbLayout = new QHBoxLayout(this);
-  hbLayout->setSpacing(1);
-  hbLayout->setMargin(1);
-  
-  QLabel* lbl = new QLabel(this);
-  lbl->setPixmap(QPixmap::fromImage(getAmmoImage(iconNum)));
-  lbl->setMaximumWidth(30);
-  lbl->setGeometry(0, 0, 30, 30);
-  hbLayout->addWidget(lbl);
+	QHBoxLayout* hbLayout = new QHBoxLayout(this);
+	hbLayout->setSpacing(1);
+	hbLayout->setMargin(1);
+	
+	QLabel* lbl = new QLabel(this);
+	lbl->setPixmap(QPixmap::fromImage(getAmmoImage(iconNum)));
+	lbl->setMaximumWidth(30);
+	lbl->setGeometry(0, 0, 30, 30);
+	hbLayout->addWidget(lbl);
 
-  item=new WeaponItem(QImage(":/res/ammopic.png"), this);
-  item->setItemsNum(wNum);
-  item->setInfinityState(true);
-  hbLayout->addWidget(item);
+	item = new WeaponItem(QImage(":/res/ammopic.png"), this);
+	item->setItemsNum(wNum);
+	item->setInfinityState(true);
+	hbLayout->addWidget(item);
 
-  hbLayout->setStretchFactor(lbl, 1);
-  hbLayout->setStretchFactor(item, 99);
-  hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter);
-  hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
+	hbLayout->setStretchFactor(lbl, 1);
+	hbLayout->setStretchFactor(item, 99);
+	hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter);
+	hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
 }
 
 void SelWeaponItem::setItemsNum(const unsigned char num)
 {
-  item->setItemsNum(num);
+	item->setItemsNum(num);
 }
 
 unsigned char SelWeaponItem::getItemsNum() const
 {
-  return item->getItemsNum();
+	return item->getItemsNum();
 }
 
 SelWeaponWidget::SelWeaponWidget(int numItems, QWidget* parent) :
   m_numItems(numItems),
   QFrame(parent)
 {
-  wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this);
+	wconf = new QSettings(cfgdir->absolutePath() + "/weapons.ini", QSettings::IniFormat, this);
 
-  wconf->setValue("Default", cDefaultAmmoStore->mid(10));
+	wconf->setValue("Default", cDefaultAmmoStore->mid(10));
 
-  currentState=cDefaultAmmoStore->mid(10);
+	QString currentState = cDefaultAmmoStore->mid(10);
 
-  pLayout=new QGridLayout(this);
-  pLayout->setSpacing(1);
-  pLayout->setMargin(1);
+	pLayout = new QGridLayout(this);
+	pLayout->setSpacing(1);
+	pLayout->setMargin(1);
 
-  int j=-1;
-  int i=0, k=0;
-  for(; i<m_numItems; ++i) {
-    if(i==6) continue;
-    if (k%4==0) ++j;
-    weaponItems[i]=new SelWeaponItem(i, currentState[i].digitValue(), this);
-    pLayout->addWidget(weaponItems[i], j, k%4);
-    ++k;
-  }
+	int j = -1;
+	int i = 0, k = 0;
+	for(; i < m_numItems; ++i) {
+		if (i == 6) continue;
+		if (k % 4 == 0) ++j;
+		weaponItems[i] = new SelWeaponItem(i, currentState[i].digitValue(), this);
+		pLayout->addWidget(weaponItems[i], j, k % 4);
+		++k;
+	}
 
-  //pLayout->setRowStretch(5, 100);
-  m_name = new QLineEdit(this);
-  pLayout->addWidget(m_name, i, 0, 1, 5);
+	//pLayout->setRowStretch(5, 100);
+	m_name = new QLineEdit(this);
+	pLayout->addWidget(m_name, i, 0, 1, 5);
 }
 
 void SelWeaponWidget::setWeapons(const 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();
+	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));
+	setWeapons(cDefaultAmmoStore->mid(10));
 }
 
 void SelWeaponWidget::save()
 {
-  if (m_name->text()=="Default") {
-    QMessageBox impossible(QMessageBox::Warning, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not edit default weapon set"));
-    impossible.exec();
-    return;
-  }
-  if (m_name->text()=="") return;
-  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);
-  }
-  if (curWeaponsName!="") {
-    // remove old entry
-    wconf->remove(curWeaponsName);
-  }
-  wconf->setValue(m_name->text(), currentState);
-  emit weaponsChanged();
+	if (m_name->text() == "Default") {
+		QMessageBox impossible(QMessageBox::Warning, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not edit default weapon set"));
+		impossible.exec();
+		return;
+	}
+	
+	if (m_name->text() == "") return;
+	
+	QString 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);
+	}
+	if (curWeaponsName != "") {
+		// remove old entry
+		wconf->remove(curWeaponsName);
+	}
+	wconf->setValue(m_name->text(), currentState);
+	emit weaponsChanged();
 }
 
 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
 {
-  twi::const_iterator it=weaponItems.find(weaponIndex);
-  return it==weaponItems.end() ? 9 : it->second->getItemsNum();
+	twi::const_iterator it = weaponItems.find(weaponIndex);
+	return it == weaponItems.end() ? 9 : it->second->getItemsNum();
 }
 
 QString SelWeaponWidget::getWeaponsString(const QString& name) const
 {
-  return wconf->value(name).toString();
+	return wconf->value(name).toString();
 }
 
 void SelWeaponWidget::deleteWeaponsName()
 {
-  if (curWeaponsName=="") return;
-
-  if (curWeaponsName=="Default") {
-    QMessageBox impossible(QMessageBox::Warning, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not delete default weapon set"));
-    impossible.exec();
-    return;
-  }
+	if (curWeaponsName == "") return;
 
-  QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Weapons"), QMessageBox::tr("Really delete this weapon set?"),
-			   QMessageBox::Ok | QMessageBox::Cancel);
-  
-  if (reallyDelete.exec()==QMessageBox::Ok) {
-    wconf->remove(curWeaponsName);
-    emit weaponsDeleted();
-  }
+	if (curWeaponsName == "Default") {
+		QMessageBox impossible(QMessageBox::Warning, QMessageBox::tr("Weapons"), QMessageBox::tr("Can not delete default weapon set"));
+		impossible.exec();
+		return;
+	}
+
+	QMessageBox reallyDelete(QMessageBox::Question, QMessageBox::tr("Weapons"), QMessageBox::tr("Really delete this weapon set?"), QMessageBox::Ok | QMessageBox::Cancel);
+	
+	if (reallyDelete.exec() == QMessageBox::Ok) {
+		wconf->remove(curWeaponsName);
+		emit weaponsDeleted();
+	}
 }
 
-void SelWeaponWidget::setWeaponsName(const QString& name, bool editMode)
+void SelWeaponWidget::setWeaponsName(const QString& name)
 {
-  if(name!="" && wconf->contains(name)) {
-    setWeapons(wconf->value(name).toString());
-  }
+	if(name != "" && wconf->contains(name)) {
+		setWeapons(wconf->value(name).toString());
+	}
 
-  if(editMode) curWeaponsName=name;
-  else curWeaponsName="";
+	curWeaponsName = name;
 
-  m_name->setText(name);
+	m_name->setText(name);
 }
 
 QStringList SelWeaponWidget::getWeaponNames() const
 {
-  return wconf->allKeys();
+	return wconf->allKeys();
 }
--- a/QTfrontend/selectWeapon.h	Sun Nov 23 23:16:33 2008 +0000
+++ b/QTfrontend/selectWeapon.h	Mon Nov 24 13:27:31 2008 +0000
@@ -53,7 +53,7 @@
  public slots:
   void setDefault();
   void setWeapons(const QString& ammo);
-  void setWeaponsName(const QString& name, bool editMode);
+  void setWeaponsName(const QString& name);
   void deleteWeaponsName();
   void save();
 
@@ -62,7 +62,6 @@
   void weaponsDeleted();
 
  private:
-  QString currentState;
   QString curWeaponsName;
 
   QLineEdit* m_name;