Пример #1
0
void MainWindow::addTeam()
{
    int tc = teams.count();
    if (tc) {
        teams.last()->button->disconnect();
        teams.last()->button->setIcon(QIcon(":/images/images/remove.png"));
        connect(teams.last()->button, SIGNAL(clicked()),
                this, SLOT(removeTeam()));
    }
    team *n = new team;
    n->number = new QLabel;
    n->number->setText(QString::number(teams.count() + 1) + ")");
    n->name = new QLineEdit;
    n->button = new QToolButton;
    teams.append(n);
    QGridLayout *layout = static_cast <QGridLayout *> (ui->list->layout());
    layout->addWidget(n->number, lli, 0);
    connect(n->name, SIGNAL(returnPressed()), this, SLOT(drawCouples()));
    QShortcut *sh = new QShortcut(QKeySequence("Ctrl+Return"), n->name);
    sh->setContext(Qt::WidgetShortcut);
    connect(sh, SIGNAL(activated()), this, SLOT(ctrlEnterPressed()));
    QShortcut *sh1 = new QShortcut(QKeySequence("Tab"), n->name);
    sh1->setContext(Qt::WidgetShortcut);
    connect(sh1, SIGNAL(activated()), this, SLOT(tabPressed()));
    QShortcut *sh2 = new QShortcut(QKeySequence("Shift+Tab"), n->name);
    sh2->setContext(Qt::WidgetShortcut);
    connect(sh2, SIGNAL(activated()), this, SLOT(shiftTabPressed()));
    layout->addWidget(n->name, lli, 1);
    n->button->setIcon(QIcon(":/images/images/add.png"));
    connect(n->button, SIGNAL(clicked()), this, SLOT(addTeam()));
    layout->addWidget(n->button, lli, 2);
    ++lli;
    n->name->setFocus();
}
Пример #2
0
void TeamSelector::loadTeams(const QString& filename, bool overwrite)
{
  if(overwrite)
  {
    size_t teamCount = teams.size();
    for(size_t i = 0; i < teamCount; ++i)
      removeTeam(teams[i]);
  }

  std::vector<Team> loadedTeams = Team::getTeams(toString(filename));
  for(size_t i = 0; i < loadedTeams.size(); ++i)
    addTeam(new Team(loadedTeams[i]));
}