QTfrontend/ui/widget/teamselhelper.cpp
changeset 6616 f77bb02b669f
parent 6060 fdfc01419815
child 6700 e04da46ee43c
equal deleted inserted replaced
6615:65602f1ef0f8 6616:f77bb02b669f
    27 #include "hwconsts.h"
    27 #include "hwconsts.h"
    28 #include "frameTeam.h"
    28 #include "frameTeam.h"
    29 
    29 
    30 void TeamLabel::teamButtonClicked()
    30 void TeamLabel::teamButtonClicked()
    31 {
    31 {
    32   emit teamActivated(text());
    32     emit teamActivated(text());
    33 }
    33 }
    34 
    34 
    35 TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) :
    35 TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) :
    36   QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0),
    36     QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0),
    37   colorButt(0)
    37     colorButt(0)
    38 {
    38 {
    39     QPalette newPalette = palette();
    39     QPalette newPalette = palette();
    40     newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00));
    40     newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00));
    41     setPalette(newPalette);
    41     setPalette(newPalette);
    42     setAutoFillBackground(true);
    42     setAutoFillBackground(true);
    44     mainLayout.setSpacing(3);
    44     mainLayout.setSpacing(3);
    45     mainLayout.setMargin(0);
    45     mainLayout.setMargin(0);
    46     this->setMaximumHeight(38);
    46     this->setMaximumHeight(38);
    47     this->setMinimumHeight(38);
    47     this->setMinimumHeight(38);
    48     QIcon difficultyIcon=team.isNetTeam() ?
    48     QIcon difficultyIcon=team.isNetTeam() ?
    49         QIcon(QString(":/res/botlevels/net%1.png").arg(m_team.difficulty()))
    49                          QIcon(QString(":/res/botlevels/net%1.png").arg(m_team.difficulty()))
    50         : QIcon(QString(":/res/botlevels/%1.png").arg(m_team.difficulty()));
    50                          : QIcon(QString(":/res/botlevels/%1.png").arg(m_team.difficulty()));
    51 
    51 
    52     butt = new QPushButton(difficultyIcon, team.name().replace("&","&&"), this);
    52     butt = new QPushButton(difficultyIcon, team.name().replace("&","&&"), this);
    53     butt->setFlat(true);
    53     butt->setFlat(true);
    54     butt->setToolTip(team.owner());
    54     butt->setToolTip(team.owner());
    55     mainLayout.addWidget(butt);
    55     mainLayout.addWidget(butt);
    56     butt->setStyleSheet("QPushButton{"
    56     butt->setStyleSheet("QPushButton{"
    57             "icon-size: 48px;"
    57                         "icon-size: 48px;"
    58             "text-align: left;"
    58                         "text-align: left;"
    59             "background-color: #0d0544;"
    59                         "background-color: #0d0544;"
    60             "color: orange;"
    60                         "color: orange;"
    61             "font: bold;"
    61                         "font: bold;"
    62             "border-width: 2px;"
    62                         "border-width: 2px;"
    63             "margin: 6px 0px 6px 0px;"
    63                         "margin: 6px 0px 6px 0px;"
    64             "}");
    64                         "}");
    65 
    65 
    66     if(m_isPlaying) {
    66     if(m_isPlaying)
       
    67     {
    67         // team color
    68         // team color
    68         colorButt = new QPushButton(this);
    69         colorButt = new QPushButton(this);
    69         colorButt->setMaximumWidth(26);
    70         colorButt->setMaximumWidth(26);
    70         colorButt->setMinimumHeight(26);
    71         colorButt->setMinimumHeight(26);
    71         colorButt->setGeometry(0, 0, 26, 26);
    72         colorButt->setGeometry(0, 0, 26, 26);
    76 
    77 
    77         phhoger = new CHedgehogerWidget(QImage(":/res/hh25x25.png"), QImage(":/res/hh25x25grey.png"), this);
    78         phhoger = new CHedgehogerWidget(QImage(":/res/hh25x25.png"), QImage(":/res/hh25x25grey.png"), this);
    78         connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged()));
    79         connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged()));
    79         phhoger->setHHNum(team.numHedgehogs());
    80         phhoger->setHHNum(team.numHedgehogs());
    80         mainLayout.addWidget(phhoger);
    81         mainLayout.addWidget(phhoger);
    81     } else {
    82     }
       
    83     else
       
    84     {
    82     }
    85     }
    83 
    86 
    84     QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam()));
    87     QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam()));
    85     //QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam()));
    88     //QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam()));
    86 }
    89 }
    87 
    90 
    88 void TeamShowWidget::setInteractivity(bool interactive)
    91 void TeamShowWidget::setInteractivity(bool interactive)
    89 {
    92 {
    90     if(m_team.isNetTeam()) {
    93     if(m_team.isNetTeam())
       
    94     {
    91         butt->setEnabled(interactive);
    95         butt->setEnabled(interactive);
    92     }
    96     }
    93 
    97 
    94     colorButt->setEnabled(interactive);
    98     colorButt->setEnabled(interactive);
    95     phhoger->setEnabled(interactive);
    99     phhoger->setEnabled(interactive);
    96 }
   100 }
    97 
   101 
    98 void TeamShowWidget::setHHNum(unsigned int num)
   102 void TeamShowWidget::setHHNum(unsigned int num)
    99 {
   103 {
   100   phhoger->setHHNum(num);
   104     phhoger->setHHNum(num);
   101 }
   105 }
   102 
   106 
   103 void TeamShowWidget::hhNumChanged()
   107 void TeamShowWidget::hhNumChanged()
   104 {
   108 {
   105   m_team.setNumHedgehogs(phhoger->getHedgehogsNum());
   109     m_team.setNumHedgehogs(phhoger->getHedgehogsNum());
   106   emit hhNmChanged(m_team);
   110     emit hhNmChanged(m_team);
   107 }
   111 }
   108 
   112 
   109 void TeamShowWidget::activateTeam()
   113 void TeamShowWidget::activateTeam()
   110 {
   114 {
   111   emit teamStatusChanged(m_team);
   115     emit teamStatusChanged(m_team);
   112 }
   116 }
   113 
   117 
   114 /*HWTeamTempParams TeamShowWidget::getTeamParams() const
   118 /*HWTeamTempParams TeamShowWidget::getTeamParams() const
   115 {
   119 {
   116   if(!phhoger) throw;
   120   if(!phhoger) throw;
   121 }*/
   125 }*/
   122 
   126 
   123 void TeamShowWidget::changeTeamColor(QColor color)
   127 void TeamShowWidget::changeTeamColor(QColor color)
   124 {
   128 {
   125     FrameTeams* pOurFrameTeams=dynamic_cast<FrameTeams*>(parentWidget());
   129     FrameTeams* pOurFrameTeams=dynamic_cast<FrameTeams*>(parentWidget());
   126     if(!color.isValid()) {
   130     if(!color.isValid())
   127         if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
   131     {
       
   132         if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end())
       
   133         {
   128             pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
   134             pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
   129         }
   135         }
   130         color=*pOurFrameTeams->currentColor;
   136         color=*pOurFrameTeams->currentColor;
   131     } else {
   137     }
       
   138     else
       
   139     {
   132         // set according color iterator
   140         // set according color iterator
   133         pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(),
   141         pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(),
   134                 pOurFrameTeams->availableColors.end(), color);
   142                                                pOurFrameTeams->availableColors.end(), color);
   135         if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
   143         if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end())
       
   144         {
   136             // error condition
   145             // error condition
   137             pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
   146             pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
   138         }
   147         }
   139     }
   148     }
   140 
   149 
   141     colorButt->setStyleSheet(QString("QPushButton{"
   150     colorButt->setStyleSheet(QString("QPushButton{"
   142             "background-color: %1;"
   151                                      "background-color: %1;"
   143             "border-width: 1px;"
   152                                      "border-width: 1px;"
   144             "border-radius: 2px;"
   153                                      "border-radius: 2px;"
   145             "}").arg(pOurFrameTeams->currentColor->name()));
   154                                      "}").arg(pOurFrameTeams->currentColor->name()));
   146 
   155 
   147     m_team.setColor(color);
   156     m_team.setColor(color);
   148     emit teamColorChanged(m_team);
   157     emit teamColorChanged(m_team);
   149 }
   158 }
   150 
   159 
   151 HWTeam TeamShowWidget::getTeam() const
   160 HWTeam TeamShowWidget::getTeam() const
   152 {
   161 {
   153   return m_team;
   162     return m_team;
   154 }
   163 }