QTfrontend/teamselhelper.cpp
changeset 207 287077789132
parent 184 f97a7a3dc8f6
child 225 8907889e3101
equal deleted inserted replaced
206:32fa6282efe2 207:287077789132
    18 
    18 
    19 #include "teamselhelper.h"
    19 #include "teamselhelper.h"
    20 #include "hwconsts.h"
    20 #include "hwconsts.h"
    21 
    21 
    22 #include <QPixmap>
    22 #include <QPixmap>
    23 #include <QPushButton>
       
    24 #include <QPainter>
    23 #include <QPainter>
       
    24 
       
    25 #include "frameTeam.h"
    25 
    26 
    26 void TeamLabel::teamButtonClicked()
    27 void TeamLabel::teamButtonClicked()
    27 {
    28 {
    28   emit teamActivated(text());
    29   emit teamActivated(text());
    29 }
    30 }
    30 
    31 
    31 TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) :
    32 TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) :
    32   QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0)
    33   QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0), colorButt(0)
    33 {
    34 {
    34   mainLayout.setSpacing(1);
    35   mainLayout.setSpacing(1);
    35   mainLayout.setMargin(2);
    36   mainLayout.setMargin(2);
    36   this->setMaximumHeight(35);
    37   this->setMaximumHeight(35);
    37   QPixmap* px=new QPixmap(QPixmap(datadir->absolutePath() + "/Forts/" + m_team.Fort + "L.png").scaled(40, 40));
    38   QPixmap* px=new QPixmap(QPixmap(datadir->absolutePath() + "/Forts/" + m_team.Fort + "L.png").scaled(40, 40));
    38 
    39 
    39   QPalette newPalette = palette();
    40   QPalette newPalette = palette();
    40   newPalette.setColor(QPalette::Button, palette().color(backgroundRole()));
    41   newPalette.setColor(QPalette::Button, palette().color(backgroundRole()));
    41 
    42 
       
    43   // team fort
    42   QPushButton* butt=new QPushButton(*px, "", this);
    44   QPushButton* butt=new QPushButton(*px, "", this);
    43   butt->setFlat(true);
    45   butt->setFlat(true);
    44   butt->setGeometry(0, 0, 30, 30);
    46   butt->setGeometry(0, 0, 30, 30);
    45   butt->setMaximumWidth(30);
    47   butt->setMaximumWidth(30);
    46   butt->setPalette(newPalette);
    48   butt->setPalette(newPalette);
    47   mainLayout.addWidget(butt);
    49   mainLayout.addWidget(butt);
    48   butt->setIconSize(butt->size());
    50   butt->setIconSize(butt->size());
    49 
    51 
       
    52   // team name
    50   QPushButton* bText=new QPushButton(team.TeamName, this);
    53   QPushButton* bText=new QPushButton(team.TeamName, this);
    51   bText->setPalette(newPalette);
    54   bText->setPalette(newPalette);
    52   bText->setFlat(true);
    55   bText->setFlat(true);
    53   mainLayout.addWidget(bText);
    56   mainLayout.addWidget(bText);
    54 
    57 
    55   if(m_isPlaying) {
    58   if(m_isPlaying) {
       
    59     // team color
       
    60     colorButt=new QPushButton(this);
       
    61     colorButt->setMaximumWidth(30);
       
    62     colorButt->setGeometry(0, 0, 30, 30);
       
    63     changeTeamColor();
       
    64     connect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor()));
       
    65     mainLayout.addWidget(colorButt);
       
    66 
       
    67     // hedgehogs num
    56     phhoger=new CHedgehogerWidget(this);
    68     phhoger=new CHedgehogerWidget(this);
    57     mainLayout.addWidget(phhoger);
    69     mainLayout.addWidget(phhoger);
    58   }
    70   }
    59 
    71 
    60   QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam()));
    72   QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam()));
    64 void TeamShowWidget::activateTeam()
    76 void TeamShowWidget::activateTeam()
    65 {
    77 {
    66   emit teamStatusChanged(m_team);
    78   emit teamStatusChanged(m_team);
    67 }
    79 }
    68 
    80 
    69 unsigned char TeamShowWidget::getHedgehogsNum() const
    81 HWTeamTempParams TeamShowWidget::getTeamParams() const
    70 {
    82 {
    71   return phhoger ? phhoger->getHedgehogsNum() : 0;
    83   if(!phhoger) throw;
       
    84   HWTeamTempParams params;
       
    85   params.numHedgehogs=phhoger->getHedgehogsNum();
       
    86   params.teamColor=colorButt->palette().color(QPalette::Button);
       
    87   return params;
    72 }
    88 }
       
    89 
       
    90 void TeamShowWidget::changeTeamColor()
       
    91 {
       
    92   FrameTeams* pOurFrameTeams=dynamic_cast<FrameTeams*>(parentWidget());
       
    93   if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
       
    94     pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
       
    95   }
       
    96   
       
    97   QPalette newPalette = palette();
       
    98   newPalette.setColor(QPalette::Button, QColor(*pOurFrameTeams->currentColor));
       
    99   colorButt->setPalette(newPalette);
       
   100 }