void MainWindow::on_btnLoad_clicked() { LoadDialog* dialog = new LoadDialog(this); if (dialog->exec() == QDialog::Accepted) { Player *p1, *p2; ui->P1Name->setEnabled(false); ui->P2Name->setEnabled(false); QFile game("games/" + dialog->filename); if (game.open(QIODevice::ReadOnly)) { QTextStream stream(&game); QString name = stream.readLine(); int score = stream.readLine().toInt(); p1 = new Player(name, 'r'); p1->setscore(score); ui->P1Name->setText(name); ui->Score1->setText(QString::number(score)); name = stream.readLine(); score = stream.readLine().toInt(); p2 = new Player(name, 'b'); p2->setscore(score); ui->P2Name->setText(name); ui->Score2->setText(QString::number(score)); gameOrganizer = new Organizer(p1,p2); startGame(); while (!stream.atEnd()) { int x = stream.readLine().toInt(); columnClicked(x); } game.close(); } } delete dialog; }
/*! * \brief QucsApp::slotLoadModule launches the dialog to select dynamic modueles */ void QucsApp::slotLoadModule() { qDebug() << "slotLoadModule"; LoadDialog *ld = new LoadDialog(this); ld->setApp(this); // fech list of _symbol.json // \todo fetch timestamp of VA, JSON, if VA newer, need to reload. QDir projDir = QucsSettings.QucsWorkDir.absolutePath(); QStringList files; QString fileSuffix = "*_symbol.json"; files = projDir.entryList(QStringList(fileSuffix), QDir::Files | QDir::NoSymLinks); // no JSON files or no a project? if (!files.size()){ QMessageBox::critical(this, tr("Error"), tr("Symbol files not found in: %1\n\n" "Is the project open?\n" "Have you saved the Verilog-A symbols?") .arg(QString(projDir.absolutePath()))); return; } // initialize dialog // pass list of potential symbol files ld->symbolFiles << files; ld->projDir = projDir; ld->initDialog(); // \todo check what is already loaded, offer skip, reload //pass stuff to ld dialog // run, let user do the selections if (ld->exec() == QDialog::Accepted) { Module::vaComponents = ld->selectedComponents; // dialog write new bitmap into JSON // load, unload, reload // inform if symbol changed // populate Module::vaComponents // vaComponents are selected with the dialog // dialog should populate acording to checkboxes // build vaComponents QMap // remove all previously registered modules QMutableHashIterator<QString, Module *> it( Module::Modules ); while(it.hasNext()) { it.next(); if (it.value()->category == QObject::tr("verilog-a user devices")) { it.remove(); } } if (! Module::vaComponents.isEmpty()) { // Register whatever is in Module::vaComponents Module::registerDynamicComponents(); // update the combobox, set new category in view // pick up new category 'verilog-a user components' from `Module::category` //set new category into view QucsApp::fillComboBox(true); CompChoose->setCurrentIndex(CompChoose->count()-1); slotSetCompView(CompChoose->count()-1); // icons of dynamically registered components ready to be dragged } else { // remove any previously registerd icons from the listview int foundCat = CompChoose->findText(QObject::tr("verilog-a user devices")); if (foundCat != -1) { CompChoose->setCurrentIndex(foundCat); CompComps->clear(); } } } delete ld; }