QTfrontend/selectWeapon.cpp
changeset 5029 97c650500991
parent 4976 088d40d8aba2
child 5051 7b5fa8d3c904
equal deleted inserted replaced
5028:3c43f00b0743 5029:97c650500991
    28 #include <QBitmap>
    28 #include <QBitmap>
    29 #include <QLineEdit>
    29 #include <QLineEdit>
    30 #include <QSettings>
    30 #include <QSettings>
    31 #include <QMessageBox>
    31 #include <QMessageBox>
    32 #include <QTabWidget>
    32 #include <QTabWidget>
       
    33 #include <QDebug>
    33 #include <math.h>
    34 #include <math.h>
    34 
    35 
    35 QImage getAmmoImage(int num)
    36 QImage getAmmoImage(int num)
    36 {
    37 {
    37     static QImage ammo(":Ammos.png");
    38     static QImage ammo(":Ammos.png");
   248     }
   249     }
   249 }
   250 }
   250 
   251 
   251 void SelWeaponWidget::newWeaponsName()
   252 void SelWeaponWidget::newWeaponsName()
   252 {
   253 {
   253     setWeaponsName(tr("new"));
   254     QString newName = tr("new");
       
   255     if(wconf->contains(newName)) {
       
   256         //name already used -> look for an appropriate name:
       
   257         int i=2;
       
   258         while(wconf->contains(newName = tr("new")+QString::number(i++)));
       
   259     }
       
   260     setWeaponsName(newName);
   254 }
   261 }
   255 
   262 
   256 void SelWeaponWidget::setWeaponsName(const QString& name)
   263 void SelWeaponWidget::setWeaponsName(const QString& name)
   257 {
   264 {
   258     m_name->setText(name);
   265     m_name->setText(name);
   271     return wconf->allKeys();
   278     return wconf->allKeys();
   272 }
   279 }
   273 
   280 
   274 void SelWeaponWidget::copy()
   281 void SelWeaponWidget::copy()
   275 {
   282 {
   276     QString ammo = getWeaponsString(curWeaponsName);
   283     if(wconf->contains(curWeaponsName)) {
   277     setWeaponsName(tr("copy of") + " " + curWeaponsName);
   284         QString ammo = getWeaponsString(curWeaponsName);
   278     setWeapons(ammo);
   285         QString newName = tr("copy of") + " " + curWeaponsName;
   279 }
   286         if(wconf->contains(newName)) {
       
   287             //name already used -> look for an appropriate name:
       
   288             int i=2;
       
   289             while(wconf->contains(newName = tr("copy of") + " " + curWeaponsName+QString::number(i++)));
       
   290         }
       
   291         setWeaponsName(newName);
       
   292         setWeapons(ammo);
       
   293     }
       
   294 }