void MainWindow::openRecent() { if (recentDBsListWidget->currentIndex().isValid()) { addRecent(recentDBsListWidget->currentItem()->text()); openDB(recentDBsListWidget->currentItem()->text()); } }
void MainWindow::loadRecent(int index) { QString file(slRecent[index-1]); addRecent(file); sFileName = file; on_action_Reload_triggered(); }
void MainWindow::on_action_Load_triggered() { /* if (!bModified || (QMessageBox::question(this,QApplication::translate("mainWindow","Confirmation",0),QApplication::translate("mainWindow","The game has been modified since the last save. If you continue, these changes will be discarded. Are you sure you want to continue?",0),QMessageBox::Yes|QMessageBox::No,QMessageBox::No)==QMessageBox::Yes)) {*/ QString file = QFileDialog::getOpenFileName(this,QApplication::translate("mainWindow","Select the file to open",0),QDir::current().path(),QApplication::translate("mainWindow","GM-Assistant files (*.gma);;XML files (*.xml)",0)); if (!file.isEmpty()) { try { // changing current directory QDir::setCurrent(QFileInfo(file).dir().path()); eGame.fromFile(file.toStdString()); updateDisplay(); bModified = false; addRecent(file); sFileName = file; } catch (xmlpp::exception &xml) { QMessageBox::critical(this,QApplication::translate("mainWindow","Error",0),xml.what()); } catch (std::exception &e) { QMessageBox::critical(this,QApplication::translate("mainWindow","Error",0),QString(e.what()) + "\nThe game cannot be loaded."); } } // } }
void MainWindow::openFile(const QString &file) { QFileInfo file_info(file); if (file_info.exists() && !saveChangesBeforeProceeding(tr("Open database"), true)) { addRecent(file_info.absoluteFilePath()); openDB(file_info.absoluteFilePath()); } }
void MainWindow::on_actionOpenFolder_triggered() { QUrl folder = QFileDialog::getExistingDirectoryUrl(this, "Open Folder", history.lastFileOpenDir()); history.setFileOpenDir(QFileInfo(folder.path()).dir().path()); addRecent(folder); mp_self->play(folder); }
void MainWindow::saveAs() { QString saveDBName = QFileDialog::getSaveFileName(this, tr("Save database"), QFileInfo(current_db_file).fileName(), tr("iTest databases (*.itdb)")); if (!saveDBName.isNull() || !saveDBName.isEmpty()) { addRecent(saveDBName); saveDB(saveDBName); } }
void MainWindow::on_action_New_triggered() { /* if (!bModified || (QMessageBox::question(this,QApplication::translate("mainWindow","Confirmation",0),QApplication::translate("mainWindow","The game has been modified since the last save. If you continue, these changes will be discarded. Are you sure you want to continue?",0),QMessageBox::Yes|QMessageBox::No,QMessageBox::No)==QMessageBox::Yes)) {*/ eGame.clear(); updateDisplay(); bModified = false; addRecent(""); sFileName = ""; // } }
void MainWindow::open() { // Save changes before proceeding? bool cancelled = saveChangesBeforeProceeding(tr("Open database"), true); if (!cancelled) { // Opening database -------------------------------------------------------- QString openDBName = QFileDialog::getOpenFileName(this, tr("Open database file"), "", tr("iTest databases (*.itdb);;All files (*.*)")); if (!openDBName.isNull()) { addRecent(openDBName); openDB(openDBName); } } }
void MainWindow::on_actionOpenFile_triggered() { QUrl url = QFileDialog::getOpenFileUrl(this, "Open File", history.lastFileOpenDir()); if (url.isEmpty()) return; QString p = QFileInfo(url.toLocalFile()).dir().path(); qDebug() << "Path:" << p; history.setFileOpenDir(p); addRecent(url); mp_self->play(url); }
void MainWindow::loadState() { QSettings config; config.beginGroup("MainWindow"); setGeometry(config.value("geometry", geometry()).toRect()); if (config.value("maximised", false).toBool()) setWindowState(windowState() | Qt::WindowMaximized); // Recent files ui->actionClearRecent->setParent(this); ui->menuRecent->clear(); for (QString file : history.recentFiles()) addRecent(file, true); ui->menuRecent->addSeparator(); ui->menuRecent->addAction(ui->actionClearRecent); }
MainWindow::MainWindow(): QMainWindow(), bModified(false), pAboutDial(new AboutDialog(this)), timer(new QTimer(this)), iTimerCount(0), smMapper(new QSignalMapper(this)), dDuration(0.0) { setupUi(this); updateDisplay(); timer->setInterval(100); timer->setSingleShot(false); connect(timer,SIGNAL(timeout()),this,SLOT(onTimer_timeout())); connect(treeMusic,SIGNAL(fileToPlay(std::string,double)),this,SLOT(playMusic(std::string,double))); connect(treeFX,SIGNAL(fileToPlay(std::string,double)),this,SLOT(playSound(std::string))); connect(smMapper,SIGNAL(mapped(int)),this,SLOT(loadRecent(int))); // setting widgets treeFX->setSizeLimited(true); // loading settings QSettings settings; settings.beginGroup("directories"); QDir::setCurrent(settings.value("work").toString()); settings.endGroup(); settings.beginGroup("mainWindow"); resize(settings.value("size",size()).toSize()); if (settings.value("maximized",false).toBool()) { setWindowState(windowState() | Qt::WindowMaximized); } settings.endGroup(); settings.beginGroup("files"); slRecent = settings.value("recent").toStringList(); // display the recently opened games in the menu actionR_ecent->setMenu(new QMenu); addRecent(""); sFileName = settings.value("last").toString(); if (!sFileName.isEmpty()) { // we load the game opened when GMA was closed on_action_Reload_triggered(); setWindowTitle(QString("GM-Assistant - ")+QFileInfo(sFileName).fileName()); } settings.endGroup(); // recently opened files update connect(actionR_ecent->menu(),SIGNAL(aboutToShow()),this,SLOT(updateRecent())); }
void MainWindow::saveCopy() { if (this->isWindowModified()) { switch (QMessageBox::information(this, tr("Save a copy"), tr("It is necessary to save any changes you have made to the database before proceeding."), tr("&Save"), tr("Cancel"), 0, 1)) { case 0: // Save save(); break; case 1: // Cancel return; break; } } QString saveDBName = QFileDialog::getSaveFileName(this, tr("Save a copy"), QFileInfo(current_db_file).fileName(), tr("iTest databases (*.itdb);;iTest 1.3 databases (*.it13.itdb)")); if (!saveDBName.isNull() || !saveDBName.isEmpty()) { addRecent(saveDBName); saveDB(saveDBName, true); } }
void MainWindow::on_actionS_ave_as_triggered() { eGame.notes() = textNotes->toPlainText().toStdString(); QString file = QFileDialog::getSaveFileName(this,QApplication::translate("mainWindow","Select the file to save",0),QDir::current().path(),QApplication::translate("mainWindow","GM-Assistant files (*.gma);;XML files (*.xml)",0)); if (!file.isEmpty()) { try { eGame.toFile(file.toStdString()); // action_Save->setEnabled(false); bModified = false; addRecent(file); sFileName = file; QDir::setCurrent(QFileInfo(sFileName).dir().path()); } catch (xmlpp::exception &xml) { QMessageBox::critical(this,QApplication::translate("mainWindow","Error",0),xml.what()); } } }
void MainWindow::newDB() { this->setEnabled(false); // Save changes before proceeding? bool cancelled = saveChangesBeforeProceeding(tr("New database"), true); if (cancelled) { this->setEnabled(true); return; } // Creating database ------------------------------------------------------- bool ok; QString db_name = QInputDialog::getText(this, tr("New database"), tr("Database name:"), QLineEdit::Normal, tr("Untitled database"), &ok); QString saveDBName; if (!ok) { this->setEnabled(true); return; } if (!db_name.isEmpty()) { saveDBName = QFileDialog::getSaveFileName(this, tr("Create database file"), tr("%1.itdb").arg(db_name), tr("iTest databases (*.itdb)")); } else { saveDBName = QFileDialog::getSaveFileName(this, tr("Create database file"), tr("untitled.itdb"), tr("iTest databases (*.itdb)")); } if (saveDBName.isNull() || saveDBName.isEmpty()) { this->setEnabled(true); return; } QFile file(saveDBName); if (!file.open(QFile::WriteOnly | QFile::Text)) { QMessageBox::critical(this, tr("Create database file"), tr("Cannot write file %1:\n%2.").arg(saveDBName).arg(file.errorString())); this->setWindowTitle(tr("iTestServer")); this->setEnabled(true); return; } bool itdb1_3 = saveDBName.endsWith(".it13.itdb"); clearAll(); setProgress(10); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> QTextStream sfile(&file); sfile.setCodec("UTF-8"); sfile << "[ITEST_VERSION]\n" << F_ITEST_VERSION << endl; sfile << "[ITEST_DB_VERSION]\n" << (itdb1_3 ? 1.3 : F_ITDB_VERSION) << endl; sfile << "[DB_NAME]\n" << db_name << endl; sfile << "[DB_DATE]\n" << endl; sfile << "[DB_DATE_ULSD]\ntrue" << endl; sfile << "[DB_COMMENTS]\n" << endl; sfile << "[DB_QNUM]\n0" << endl; sfile << "[DB_SNUM]\n0" << endl; if (!itdb1_3) sfile << "[DB_CNUM]\n0" << endl; sfile << "[DB_FLAGS]" << endl; sfile << "--------------------\n"; for (int i = 0; i < current_db_categories.size(); ++i) { sfile << "[DB_F" << i << "]\n" << endl; } sfile << "[DB_FLAGS_END]"; setProgress(50); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // APPLY setAllEnabled(true); current_db_file = saveDBName; current_db_open = true; addRecent(saveDBName); #ifdef Q_OS_MAC this->setWindowTitle(QString("%1[*]").arg(currentDatabaseName())); #else this->setWindowTitle(QString("%1[*] - iTestServer").arg(currentDatabaseName())); #endif this->setWindowModified(false); statusBar()->showMessage(tr("Ready"), 10000); setProgress(100); setProgress(-1); // PROGRESS >>>>>>>>>>>>>>>>>>>>>>>>>>>>> actionEdit_questions->setChecked(true); setPage(actionEdit_questions); this->setEnabled(true); // ------------------------------------------------------------------------- }
void MainWindow::openRecent(QListWidgetItem *item) { QString buffer = item->text(); addRecent(buffer); openDB(buffer); }