QTfrontend/ui/widget/teamselhelper.cpp
changeset 6060 fdfc01419815
parent 6015 daffc14a518a
child 6616 f77bb02b669f
equal deleted inserted replaced
6059:ddf020d0941a 6060:fdfc01419815
       
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com>
       
     4  * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com>
       
     5  *
       
     6  * This program is free software; you can redistribute it and/or modify
       
     7  * it under the terms of the GNU General Public License as published by
       
     8  * the Free Software Foundation; version 2 of the License
       
     9  *
       
    10  * This program is distributed in the hope that it will be useful,
       
    11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13  * GNU General Public License for more details.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
       
    18  */
       
    19 
       
    20 #include <QPixmap>
       
    21 #include <QPainter>
       
    22 #include <QStyleFactory>
       
    23 
       
    24 #include <algorithm>
       
    25 
       
    26 #include "teamselhelper.h"
       
    27 #include "hwconsts.h"
       
    28 #include "frameTeam.h"
       
    29 
       
    30 void TeamLabel::teamButtonClicked()
       
    31 {
       
    32   emit teamActivated(text());
       
    33 }
       
    34 
       
    35 TeamShowWidget::TeamShowWidget(HWTeam team, bool isPlaying, QWidget * parent) :
       
    36   QWidget(parent), mainLayout(this), m_team(team), m_isPlaying(isPlaying), phhoger(0),
       
    37   colorButt(0)
       
    38 {
       
    39     QPalette newPalette = palette();
       
    40     newPalette.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00));
       
    41     setPalette(newPalette);
       
    42     setAutoFillBackground(true);
       
    43 
       
    44     mainLayout.setSpacing(3);
       
    45     mainLayout.setMargin(0);
       
    46     this->setMaximumHeight(38);
       
    47     this->setMinimumHeight(38);
       
    48     QIcon difficultyIcon=team.isNetTeam() ?
       
    49         QIcon(QString(":/res/botlevels/net%1.png").arg(m_team.difficulty()))
       
    50         : QIcon(QString(":/res/botlevels/%1.png").arg(m_team.difficulty()));
       
    51 
       
    52     butt = new QPushButton(difficultyIcon, team.name().replace("&","&&"), this);
       
    53     butt->setFlat(true);
       
    54     butt->setToolTip(team.owner());
       
    55     mainLayout.addWidget(butt);
       
    56     butt->setStyleSheet("QPushButton{"
       
    57             "icon-size: 48px;"
       
    58             "text-align: left;"
       
    59             "background-color: #0d0544;"
       
    60             "color: orange;"
       
    61             "font: bold;"
       
    62             "border-width: 2px;"
       
    63             "margin: 6px 0px 6px 0px;"
       
    64             "}");
       
    65 
       
    66     if(m_isPlaying) {
       
    67         // team color
       
    68         colorButt = new QPushButton(this);
       
    69         colorButt->setMaximumWidth(26);
       
    70         colorButt->setMinimumHeight(26);
       
    71         colorButt->setGeometry(0, 0, 26, 26);
       
    72 
       
    73         changeTeamColor();
       
    74         connect(colorButt, SIGNAL(clicked()), this, SLOT(changeTeamColor()));
       
    75         mainLayout.addWidget(colorButt);
       
    76 
       
    77         phhoger = new CHedgehogerWidget(QImage(":/res/hh25x25.png"), QImage(":/res/hh25x25grey.png"), this);
       
    78         connect(phhoger, SIGNAL(hedgehogsNumChanged()), this, SLOT(hhNumChanged()));
       
    79         phhoger->setHHNum(team.numHedgehogs());
       
    80         mainLayout.addWidget(phhoger);
       
    81     } else {
       
    82     }
       
    83 
       
    84     QObject::connect(butt, SIGNAL(clicked()), this, SLOT(activateTeam()));
       
    85     //QObject::connect(bText, SIGNAL(clicked()), this, SLOT(activateTeam()));
       
    86 }
       
    87 
       
    88 void TeamShowWidget::setInteractivity(bool interactive)
       
    89 {
       
    90     if(m_team.isNetTeam()) {
       
    91         butt->setEnabled(interactive);
       
    92     }
       
    93 
       
    94     colorButt->setEnabled(interactive);
       
    95     phhoger->setEnabled(interactive);
       
    96 }
       
    97 
       
    98 void TeamShowWidget::setHHNum(unsigned int num)
       
    99 {
       
   100   phhoger->setHHNum(num);
       
   101 }
       
   102 
       
   103 void TeamShowWidget::hhNumChanged()
       
   104 {
       
   105   m_team.setNumHedgehogs(phhoger->getHedgehogsNum());
       
   106   emit hhNmChanged(m_team);
       
   107 }
       
   108 
       
   109 void TeamShowWidget::activateTeam()
       
   110 {
       
   111   emit teamStatusChanged(m_team);
       
   112 }
       
   113 
       
   114 /*HWTeamTempParams TeamShowWidget::getTeamParams() const
       
   115 {
       
   116   if(!phhoger) throw;
       
   117   HWTeamTempParams params;
       
   118   params.numHedgehogs=phhoger->getHedgehogsNum();
       
   119   params.teamColor=colorButt->palette().color(QPalette::Button);
       
   120   return params;
       
   121 }*/
       
   122 
       
   123 void TeamShowWidget::changeTeamColor(QColor color)
       
   124 {
       
   125     FrameTeams* pOurFrameTeams=dynamic_cast<FrameTeams*>(parentWidget());
       
   126     if(!color.isValid()) {
       
   127         if(++pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
       
   128             pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
       
   129         }
       
   130         color=*pOurFrameTeams->currentColor;
       
   131     } else {
       
   132         // set according color iterator
       
   133         pOurFrameTeams->currentColor=std::find(pOurFrameTeams->availableColors.begin(),
       
   134                 pOurFrameTeams->availableColors.end(), color);
       
   135         if(pOurFrameTeams->currentColor==pOurFrameTeams->availableColors.end()) {
       
   136             // error condition
       
   137             pOurFrameTeams->currentColor=pOurFrameTeams->availableColors.begin();
       
   138         }
       
   139     }
       
   140 
       
   141     colorButt->setStyleSheet(QString("QPushButton{"
       
   142             "background-color: %1;"
       
   143             "border-width: 1px;"
       
   144             "border-radius: 2px;"
       
   145             "}").arg(pOurFrameTeams->currentColor->name()));
       
   146 
       
   147     m_team.setColor(color);
       
   148     emit teamColorChanged(m_team);
       
   149 }
       
   150 
       
   151 HWTeam TeamShowWidget::getTeam() const
       
   152 {
       
   153   return m_team;
       
   154 }