QTfrontend/selectWeapon.cpp
changeset 681 7a20c50988ec
parent 644 45454744f240
child 682 a37b6966de84
equal deleted inserted replaced
680:8ef26c8e8aa7 681:7a20c50988ec
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17  */
    18  
    18  
    19 #include "selectWeapon.h"
    19 #include "selectWeapon.h"
    20 #include "weaponItem.h"
    20 #include "weaponItem.h"
       
    21 #include "hwconsts.h"
    21 
    22 
    22 #include <QPushButton>
    23 #include <QPushButton>
    23 #include <QGridLayout>
    24 #include <QGridLayout>
    24 #include <QHBoxLayout>
    25 #include <QHBoxLayout>
    25 #include <QLabel>
    26 #include <QLabel>
    29 {
    30 {
    30   static QImage ammo(":Ammos.png");
    31   static QImage ammo(":Ammos.png");
    31   return ammo.copy(0, num*32, 32, 32);
    32   return ammo.copy(0, num*32, 32, 32);
    32 }
    33 }
    33 
    34 
    34 SelWeaponItem::SelWeaponItem(int num, QWidget* parent) :
    35 SelWeaponItem::SelWeaponItem(int iconNum, int wNum, QWidget* parent) :
    35   QWidget(parent)
    36   QWidget(parent)
    36 {
    37 {
    37   QHBoxLayout* hbLayout = new QHBoxLayout(this);
    38   QHBoxLayout* hbLayout = new QHBoxLayout(this);
    38   hbLayout->setSpacing(1);
    39   hbLayout->setSpacing(1);
    39   hbLayout->setMargin(1);
    40   hbLayout->setMargin(1);
    40   
    41   
    41   QLabel* lbl = new QLabel(this);
    42   QLabel* lbl = new QLabel(this);
    42   lbl->setPixmap(QPixmap::fromImage(getAmmoImage(num)));
    43   lbl->setPixmap(QPixmap::fromImage(getAmmoImage(iconNum)));
    43   lbl->setMaximumWidth(30);
    44   lbl->setMaximumWidth(30);
    44   lbl->setGeometry(0, 0, 30, 30);
    45   lbl->setGeometry(0, 0, 30, 30);
    45   hbLayout->addWidget(lbl);
    46   hbLayout->addWidget(lbl);
    46 
    47 
    47   WeaponItem* item=new WeaponItem(QImage(":/res/M2Round2.jpg"), this);
    48   item=new WeaponItem(QImage(":/res/hh25x25.png"), this);
       
    49   item->setItemsNum(wNum);
    48   item->setInfinityState(true);
    50   item->setInfinityState(true);
    49   hbLayout->addWidget(item);
    51   hbLayout->addWidget(item);
    50 
    52 
    51   hbLayout->setStretchFactor(lbl, 1);
    53   hbLayout->setStretchFactor(lbl, 1);
    52   hbLayout->setStretchFactor(item, 99);
    54   hbLayout->setStretchFactor(item, 99);
    53   hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter);
    55   hbLayout->setAlignment(lbl, Qt::AlignLeft | Qt::AlignVCenter);
    54   hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
    56   hbLayout->setAlignment(item, Qt::AlignLeft | Qt::AlignVCenter);
       
    57 }
       
    58 
       
    59 unsigned char SelWeaponItem::getItemsNum() const
       
    60 {
       
    61   return item->getItemsNum();
    55 }
    62 }
    56 
    63 
    57 SelWeaponWidget::SelWeaponWidget(QWidget* parent) :
    64 SelWeaponWidget::SelWeaponWidget(QWidget* parent) :
    58 QWidget(parent)
    65 QWidget(parent)
    59 {
    66 {
    60   pLayout=new QGridLayout(this);
    67   pLayout=new QGridLayout(this);
    61   pLayout->setSpacing(1);
    68   pLayout->setSpacing(1);
    62   pLayout->setMargin(1);
    69   pLayout->setMargin(1);
    63 
    70 
    64   int j=-1;
    71   int j=-1;
    65   for(int i=0; i<19; ++i) {
    72   for(int i=0, k=0; i<20; ++i) {
    66     if (i%4==0) ++j;
    73     if(i==6) continue;
    67     SelWeaponItem* swi = new SelWeaponItem(i, this);
    74     if (k%4==0) ++j;
    68     pLayout->addWidget(swi, j, i%4);
    75     weaponItems[i]=new SelWeaponItem(i, cDefaultAmmoStore->at(10+i).digitValue(), this);
       
    76     pLayout->addWidget(weaponItems[i], j, k%4);
       
    77     ++k;
    69   }
    78   }
    70 }
    79 }
       
    80 
       
    81 int SelWeaponWidget::operator [] (unsigned int weaponIndex) const
       
    82 {
       
    83   std::map<int, SelWeaponItem*>::const_iterator it=weaponItems.find(weaponIndex);
       
    84   return it==weaponItems.end() ? 9 : it->second->getItemsNum();
       
    85 }
       
    86 
       
    87 QString SelWeaponWidget::getWeaponsString() const
       
    88 {
       
    89   QString ammo("eammstore ");
       
    90   for(int i=0; i<20; ++i) {
       
    91     ammo=QString("%1%2").arg(ammo).arg((*this)[i]);
       
    92   }
       
    93   return ammo;
       
    94 }