void TeamHolder::load() { QSettings s; m_teams.clear(); if (!s.contains("Teams/Locations")) { addTeam(); setCurrent(0); } else { QStringList l = s.value("Teams/Locations").toStringList(); for (int i = 0; i < l.length(); i++) { addTeam(); team(i).loadFromFile(l[i]); } if (count() == 0) { addTeam(); setCurrent(0); } else { if (currentTeam() >= count()) { setCurrent(count()-1); } } } if (!team().path().isEmpty()) { s.setValue("Teams/Folder", team().folder()); } profile().loadFromFile(s.value("Profile/Current").toString()); }
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(); }
void MainWindow::removeTeam() { QToolButton *bt = static_cast <QToolButton *> (sender()); int tc = teams.count(); for (int i = 0; i < tc; ++i) { if (teams.at(i)->button == bt) { team *t = teams.at(i); t->button->deleteLater(); t->name->deleteLater(); t->number->deleteLater(); delete t; teams.removeAt(i); if (i == (tc - 1)) { teams.last()->button->disconnect(); teams.last()->button->setIcon(QIcon(":/images/images/add.png")); connect(teams.last()->button, SIGNAL(clicked()), this, SLOT(addTeam())); } else { for (int j = i; j < (tc - 1); ++j) { teams.at(j)->number->setText(QString::number(j + 1) + ")"); } } return; } } }
RegistrationApp::RegistrationApp(QWidget* parent) : m_team_table_wnd( new Ui::team_table_wnd ), m_user_table_wnd(new Ui::user_table_wnd), m_user_edit_wnd(new Ui::user_edit_wnd), m_sql(SqlUtil::getInstance()) { bool ok; QString text = QInputDialog::getText(this, tr("Database Directory"), tr("Database Path:"), QLineEdit::Normal, QDir::home().dirName(), &ok); if (!text.isEmpty()) m_sql.init(text); this->hide(); m_team_table_w = new QDialog(this); m_team_table_wnd->setupUi(m_team_table_w); m_team_table_w->show(); m_user_table_w = new QDialog(this); m_user_table_wnd->setupUi(m_user_table_w); m_user_table_w->hide(); m_user_edit_w = new QDialog(this); m_user_edit_wnd->setupUi(m_user_edit_w); m_user_edit_w->hide(); //network? //connecting stuff //connections for the buttons //team table connect(m_team_table_wnd->add_team_btn, SIGNAL(clicked()), this, SLOT(addTeam())); connect(m_team_table_wnd->team_edit_btn, SIGNAL(clicked()), this, SLOT(goToEditTeam())); connect(m_team_table_wnd->team_delete_btn, SIGNAL(clicked()), this, SLOT(deleteTeam())); //user table connect(m_user_table_wnd->edit_school_btn, SIGNAL(clicked()), this, SLOT(editTeamSchool())); connect(m_user_table_wnd->add_user_btn, SIGNAL(clicked()), this, SLOT(addUser())); connect(m_user_table_wnd->edit_user_btn, SIGNAL(clicked()), this, SLOT(editUser())); connect(m_user_table_wnd->delete_user_btn, SIGNAL(clicked()), this, SLOT(deleteUser())); connect(m_user_table_wnd->backtoteams_btn, SIGNAL(clicked()), this, SLOT(backToTeam())); //user edit connect(m_user_edit_wnd->save_userchange_btn, SIGNAL(clicked()), this, SLOT(saveUserEdit())); connect(m_user_edit_wnd->backtouser_btn, SIGNAL(clicked()), this, SLOT(backToUser())); bool result = SqlUtil::getInstance().init ( text ); if ( !result ) { QMessageBox msg ( this ); msg.setText ( "Failed to load database" ); msg.exec(); } }
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])); }
void MainWindow::ctrlEnterPressed() { QShortcut *sh = static_cast <QShortcut *> (sender()); QLineEdit *le = static_cast <QLineEdit *> (sh->parent()); int tc = teams.count(); for (int i = 0; i < (tc - 1); ++i) { if (teams.at(i)->name == le) { teams.at(i + 1)->name->setFocus(); return; } } addTeam(); }
QMenuBar *TeamBuilder::createMenuBar(MainEngine *w) { QMenuBar *menuBar = new QMenuBar(); menuBar->setObjectName("TeamBuilder"); QMenu *fileMenu = menuBar->addMenu(tr("&File")); fileMenu->addAction(tr("&New"),this,SLOT(newTeam()),tr("Ctrl+N", "New")); fileMenu->addAction(tr("&Save all"),this,SLOT(saveAll()),tr("Ctrl+S", "Save all")); fileMenu->addAction(tr("&Load all"),this,SLOT(openLoadWindow()),tr("Ctrl+L", "Load all")); fileMenu->addSeparator(); fileMenu->addAction(tr("&Quit"),qApp,SLOT(quit()),tr("Ctrl+Q", "Quit")); QMenu *teamMenu = menuBar->addMenu(tr("&Team")); if (currentWidget() && currentWidget() == this->teamMenu) { teamMenu->addAction(tr("Choose pokemon"), this->teamMenu, SLOT(choosePokemon()), tr("Alt+E", "Choose Pokemon")); } teamMenu->addAction(tr("Trainer Menu"), this, SLOT(switchToTrainer()), tr("Ctrl+B", "Trainer Menu")); teamMenu->addSeparator(); teamMenu->addAction(tr("&Add team"), this, SLOT(addTeam()), tr("Ctrl+A", "Add team")); teamMenu->addAction(tr("&Load team"), this, SLOT(openTeam()), tr("Ctrl+Shift+L", "Load team")); teamMenu->addAction(tr("&Save team"), this, SLOT(saveTeam()), tr("Ctrl+Shift+S", "Save team")); teamMenu->addAction(tr("&Import team"), this, SLOT(importTeam()), tr("Ctrl+I", "Import team")); teamMenu->addAction(tr("&Export team"), this, SLOT(exportTeam()), tr("Ctrl+E", "Export team")); teamMenu->addSeparator(); teamMenu->addAction(tr("Import from Android"), this, SLOT(importAndroid()), tr("Ctrl+Shift+I", "Import from Android")); teamMenu->addAction(tr("Export to Android"), this, SLOT(exportAndroid()), tr("Ctrl+Shift+E", "Export to Android")); currentWidget()->addMenus(menuBar); /* Loading mod menu */ QMenu *menuMods = menuBar->addMenu(tr("&Mods")); QActionGroup *group = new QActionGroup(menuMods); QString currentMod = PokemonInfoConfig::currentMod(); // No mod option. QAction *noMod = menuMods->addAction(tr("&No mod"), this, SLOT(setNoMod())); noMod->setCheckable(true); noMod->setChecked(currentMod.length()==0); group->addAction(noMod); menuMods->addSeparator(); QStringList mods = PokemonInfoConfig::availableMods(); foreach(QString smod, mods) { QAction *mod = menuMods->addAction(smod, this, SLOT(changeMod())); mod->setProperty("name", smod); mod->setCheckable(true); mod->setChecked(currentMod == smod); group->addAction(mod); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->do_this, SIGNAL(clicked()), this, SLOT(drawCouples())); connect(ui->saveCouplesToFileButton, SIGNAL(clicked()), this, SLOT(saveCouplesToFile())); //there is a dirty hack below QGridLayout *layout = static_cast <QGridLayout *> (ui->list->layout()); layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Maximum, QSizePolicy::MinimumExpanding), 999, 0, 1, 3); //end of dirty hack //never do like above lli = 0; qsrand(QTime::currentTime().msec()); addTeam(); }