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(); }
bool DatumTextItem::eventFilter(QObject* obj, QEvent* event) { if (obj == this && event->type() == QEvent::KeyPress) { QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event); if (keyEvent->key() == Qt::Key_Tab) emit tabPressed(this); else if (keyEvent->key() == Qt::Key_Backtab) emit shiftTabPressed(this); else if (keyEvent->matches(QKeySequence::Undo)) App::instance()->undo(); else if (keyEvent->matches(QKeySequence::Redo)) App::instance()->redo(); else return false; return true; } return false; }