QTfrontend/teamselect.cpp
author unc0rr
Sat, 21 Jan 2006 16:18:19 +0000
changeset 55 e09f7c952a40
parent 50 9ab4067dabec
child 61 505691a09dee
permissions -rw-r--r--
Send run parameters by cmd line, game parameters by IPC... breaks network game
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     1
#include <QLabel>
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     2
#include <QPixmap>
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     3
#include <QPushButton>
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     4
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     5
#include <algorithm>
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     6
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     7
#include "teamselect.h"
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     8
#include "teamselhelper.h"
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
     9
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    10
void TeamSelWidget::addTeam(tmprop team)
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    11
{
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    12
  curDontPlayingTeams.push_back(team);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    13
  TeamShowWidget* pTeamShowWidget =new TeamShowWidget(team);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    14
  dontPlayingLayout.addWidget(pTeamShowWidget);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    15
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    16
  teamToWidget.insert(make_pair(team, pTeamShowWidget));
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    17
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    18
  QObject::connect(pTeamShowWidget, SIGNAL(teamStatusChanged(tmprop)), this, SLOT(changeTeamStatus(tmprop)));
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    19
}
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    20
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    21
void TeamSelWidget::removeTeam(tmprop team)
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    22
{
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    23
  curDontPlayingTeams.erase(std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team));
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    24
}
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    25
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    26
void TeamSelWidget::changeTeamStatus(tmprop team)
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    27
{
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    28
  list<tmprop>::iterator itDontPlay=std::find(curDontPlayingTeams.begin(), curDontPlayingTeams.end(), team);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    29
  list<tmprop>::iterator itPlay=std::find(curPlayingTeams.begin(), curPlayingTeams.end(), team);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    30
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    31
  if(itDontPlay==curDontPlayingTeams.end()) {
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    32
    // playing team => dont playing
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    33
    curDontPlayingTeams.push_back(*itPlay);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    34
    curPlayingTeams.erase(itPlay);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    35
  } else {
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    36
    // dont playing team => playing
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    37
    curPlayingTeams.push_back(*itDontPlay);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    38
    curDontPlayingTeams.erase(itDontPlay);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    39
  }
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    40
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    41
  QGridLayout* pRemoveGrid = itDontPlay==curDontPlayingTeams.end() ? &playingLayout : &dontPlayingLayout;
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    42
  QGridLayout* pAddGrid = itDontPlay==curDontPlayingTeams.end() ? &dontPlayingLayout : &playingLayout;
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    43
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    44
  pRemoveGrid->removeWidget(teamToWidget[team]);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    45
  pAddGrid->addWidget(teamToWidget[team]);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    46
}
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    47
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    48
TeamSelWidget::TeamSelWidget(const vector<QString>& teams, QWidget* parent) :
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    49
  QWidget(parent), mainLayout(this)
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    50
{
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    51
  mainLayout.addLayout(&playingLayout);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    52
  mainLayout.addLayout(&dontPlayingLayout);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    53
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    54
  for(vector<QString>::const_iterator it=teams.begin(); it!=teams.end(); ++it) {
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    55
    addTeam(*it);
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    56
  }
9ab4067dabec TeamSelect widget alpha added
displacer
parents:
diff changeset
    57
}