#include "mainwindow.h" #include "ui_mainwindow.h" #include "qmconfteams.h" #include "qmconfclass.h" #include "qmconfwinners.h" #include "qmteamdisplay.h" #include "QMessageBox" #include "QInputDialog" #include "QTime" #include "qmdialoglegstarttimes.h" #include "qmdisqualified.h" #include "qmdatacheck.h" #include "qmdialogloadexternalteams.h" #include "QFileDialog" #include "qmdialoguploadlegtimes.h" #include "qmreportwindow.h" #include "QTabWidget" #include "QLayout" #include "qmeventstatus.h" #include "qmdownloadlegtimes.h" #include "qmdialogabout.h" #include "qmhttppath.h" #include "qmdialogchangeteamnumber.h" #include "qmfulldata.h" #include "consts.h" #include "structs.h" #include "proto.h" MainWindow *mw = NULL; bool MainWindow::shutDown = false; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); mw = this; setWindowTitle("Mara"); tabWidget = new QTabWidget(); setCentralWidget(tabWidget); tabWidget->addTab( new QmConfTeams, "Configure"); tabWidget->addTab( new QmConfClass, "Class"); tabWidget->addTab( new QmConfWinners, "Winners"); tabWidget->addTab( new QmEventStatus, "Status"); tabWidget->addTab( new qmTeamDisplay, "Team Data"); tabWidget->addTab( new qmDisqualified, "Disqual"); tabWidget->addTab( new qmDataCheck, "Data Check"); tabWidget->addTab( new qmFullData, "Full Data"); tabWidget->addTab( reportWindow = new QmReportWindow, "Reports"); QMenu *m0 = new QMenu ("Team"); ui->menuBar->addMenu(m0); m0->addAction("Reset All Team Data", this, SLOT(resetTeamData())); m0->addAction("Generate dummy team names", this, SLOT(generateDummyTeamNames())); m0->addAction("Copy/Move/Swap Team Data", this, SLOT(changeTeamNumber())); QMenu *m1 = new QMenu ("Leg Time Setup"); ui->menuBar->addMenu(m1); m1->addAction("Clear ALL Leg Times", this, SLOT(clearLegTimes())); m1->addAction("Clear single leg start times", this, SLOT(ClearOneLegTimes())); m1->addSeparator(); m1->addAction("Set Start Times", this, SLOT(setStartTimes())); m1->addSeparator(); m1->addAction("Set calculated leg start", this, SLOT(setCalcLegStart())); m1->addAction("Set ordered incremental leg start", this, SLOT(setOrderedIncLegStart())); m1->addAction("Set staggered start time", this, SLOT(setStaggeredLegStart())); m1->addAction("Set fixed start time", this, SLOT(setFixedLegStart())); m1->addSeparator(); m1->addAction("Recalculate elapsed times", this, SLOT(recalcLegTimes())); QMenu *m2 = new QMenu ("Upload"); ui->menuBar->addMenu(m2); m2->addAction("Load team information from external file", this, SLOT(loadExternalTeams())); m2->addAction("Load team information from Web Page", this, SLOT(loadExternalHtmlTeams())); m2->addAction("Upload time information", this, SLOT(uploadLegData())); QMenu *m3 = new QMenu ("Export"); ui->menuBar->addMenu(m3); m3->addAction("Store team information to external file", this, SLOT(storeExternalTeams())); //m3->addAction("Store basic team info to external file", this, SLOT(storeTeamInfo())); m3->addAction("Create external leg data file", this, SLOT(storeLegData())); QMenu *m4 = new QMenu ("Reports"); ui->menuBar->addMenu(m4); m4->addAction("Generate All Reports", this, SLOT(generateReports())); ui->menuBar->addAction("About", this, SLOT(showAbout())); } MainWindow::~MainWindow() { delete ui; } void MainWindow::showMessage( const QString & msg, int timeout) { if ( mw ) { mw->ui->statusBar->showMessage(msg, timeout); } } void MainWindow::registerReport(const QString &report, const QString &name) { if (mw && mw->reportWindow) { mw->reportWindow->addReport(report, name); } } void MainWindow::changeEvent(QEvent *e) { QMainWindow::changeEvent(e); switch (e->type()) { case QEvent::LanguageChange: ui->retranslateUi(this); break; default: break; } } void MainWindow::setStartTimes(void) { if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"), tr("This will reset the start times for all teams based on the Category configuration.\n" "Are you sure you want to do this?"), QMessageBox::Cancel, QMessageBox::Ok)) { leg_start(); } } void MainWindow::clearLegTimes(void) { if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"), tr("This will clear ALL leg times for ALL teams.\n" "Are you sure you want to do this?"), QMessageBox::Cancel, QMessageBox::Ok)) { leg_ini(); } } void MainWindow::resetTeamData(void) { if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"), tr("This will clear ALL team information.\n" "Are you sure you want to do this?"), QMessageBox::Cancel, QMessageBox::Ok)) { tm_init(); } } void MainWindow::generateDummyTeamNames(void) { if ( QMessageBox::Ok == QMessageBox::warning(this, tr("Mara"), tr("This will generate DUMMY team names.\n" "Are you sure you want to do this?"), QMessageBox::Cancel, QMessageBox::Ok)) { tm_gen(); } } void MainWindow::changeTeamNumber(void) { QmDialogChangeTeamNumber dialog("Copy/Move/Swap Team Data",this); dialog.exec(); } void MainWindow::ClearOneLegTimes(void) { bool ok; int leg = QInputDialog::getInt(this, tr("Clear One Leg Start Time"), tr("Leg:"), 0, 0, config.num_legs, 1, &ok); if ( ok && leg) { tm_clearleg_specified(leg, FALSE); } } void MainWindow::setCalcLegStart(void) { QmDialogLegStartTimes dialog("Calculate Leg Start Time",this); dialog.setDeltaTimeLabel("Delta Time"); dialog.setDescription("The start time is based on the end time of the previous leg with a constant Delta time added"); qDebug ("Must disable stuff"); if ( QDialog::Accepted == dialog.exec() ) { if ( dialog.getLeg() ) { tm_lgs(dialog.getLeg(), dialog.getDeltaTime(), dialog.getReport(), dialog.getClear() ); } } } void MainWindow::setOrderedIncLegStart(void) { QmDialogLegStartTimes dialog("Ordered Incremental Leg Start Time",this); dialog.setTimeLabel("Start Time"); dialog.setDeltaTimeLabel("Delta Time"); dialog.setDescription("The specified start time is given to the fastest team. Teams are then set at specified Delta from that time."); if ( QDialog::Accepted == dialog.exec() ) { if ( dialog.getLeg() ) { tm_lgs1(dialog.getLeg(), dialog.getTime(), dialog.getDeltaTime(), dialog.getReport(), dialog.getClear() ); } } } void MainWindow::setStaggeredLegStart(void) { QmDialogLegStartTimes dialog("Staggered Leg Start Time",this); dialog.setTimeLabel("Start Time"); dialog.setDeltaTimeLabel("Stagger Time"); dialog.setDescription("The lowest numbered team is given the start time. The teams are then starggered by team number from that time."); if ( QDialog::Accepted == dialog.exec() ) { if ( dialog.getLeg() ) { tm_staggered(dialog.getLeg(), dialog.getTime(), dialog.getDeltaTime(), dialog.getReport(), dialog.getClear() ); } } } void MainWindow::setFixedLegStart(void) { QmDialogLegStartTimes dialog("Fixed Leg Start Time",this); dialog.setTimeLabel("Start Time"); dialog.setDescription("The specified start time is given to all teams."); if ( QDialog::Accepted == dialog.exec() ) { if ( dialog.getLeg() ) { tm_fixedstart(dialog.getLeg(), dialog.getTime(), //dialog.getDeltaTime(), dialog.getReport(), dialog.getClear() ); } } } void MainWindow::recalcLegTimes(void) { QmDialogLegStartTimes dialog("Recalc Elesped Times",this); dialog.setDescription("The elasped times for all teams is recaclulated. This should not be neeed."); if ( QDialog::Accepted == dialog.exec() ) { if ( dialog.getLeg() ) { tm_recalcElapsed(dialog.getLeg()); } } } void MainWindow::loadExternalTeams(void) { QString fileName = QFileDialog::getOpenFileName( this, tr("Load File"), appSettings->value("Recent/ExternalTeams",filepath).toString(), tr("Data (*.csv);;All (*.*)"), 0, QFileDialog::ReadOnly); if ( fileName.isEmpty() ) { return; } appSettings->setValue("Recent/ExternalTeams", fileName); QmDialogLoadExternalTeams dialog(fileName,this); dialog.exec(); } void MainWindow::loadExternalHtmlTeams(void) { Qmhttppath msgBox; int rv = msgBox.exec(); if (rv == QDialog::Accepted) { QmDialogLoadExternalTeams dialog( msgBox.urlLineEdit->text(), &msgBox.allData ,this); dialog.exec(); } else { MainWindow::showMessage("No Web Address selected. No teams uploaded"); } } void MainWindow::storeExternalTeams(void) { QString fileName = QFileDialog::getSaveFileName( this, tr("Store File"), appSettings->value("Recent/storeExternalTeams",filepath).toString(), tr("Data (*.csv);;All (*.*)"), 0 ); if ( fileName.isEmpty() ) { return; } appSettings->setValue("Recent/storeExternalTeams", fileName); MainWindow::showMessage("Writing external data"); QmDialogLoadExternalTeams::storeData(fileName); MainWindow::showMessage("Writing external data completed"); } void MainWindow::storeTeamInfo(void) { QString fileName = QFileDialog::getSaveFileName( this, tr("Store Team Info File"), appSettings->value("Recent/storeTeamInfo",filepath).toString(), tr("Data (*.txt);;All (*.*)"), 0 ); if ( fileName.isEmpty() ) { return; } appSettings->setValue("Recent/storeTeamInfo", fileName); MainWindow::showMessage("Writing team info"); QmDialogLoadExternalTeams::storeTeamInfo(fileName); MainWindow::showMessage("Writing team info completed"); } void MainWindow::storeLegData(void) { QmDownloadLegTimes dialog(this); dialog.exec(); } void MainWindow::uploadLegData(void) { QmDialogUploadLegTimes dialog(this); dialog.exec(); } void MainWindow::generateReports(void) { if( load_report_data() ) { pri_all_reports(); } } void MainWindow::showAbout(void) { QmDialogAbout dialog(this); dialog.setText(QString("Build Date: ") + __DATE__ + " " + __TIME__ + "\nProgram Version: " + VERSION + "\nQT Version: " + QT_VERSION_STR); dialog.setPath(filepath); dialog.exec(); } void MainWindow::disableAllMenus(QMenu *menu) { if (menu) { foreach (QAction *action, menu->actions() ) { if (action->isSeparator()) { } else if (action->menu()) { //qDebug(">>> this action is associated with a submenu, iterating it recursively..."); mw->disableAllMenus(action->menu()); } else { action->setDisabled(true); } } } } void MainWindow::disableAllTabs(void) { MainWindow::showMessage ("Number of legs has changed - Restart application"); shutDown = true; for(int ii = 0; ii < mw->tabWidget->count() ; ii++) { mw->tabWidget->setTabEnabled(ii, false); } foreach (QAction *action, mw->ui->menuBar->actions() ) { mw->disableAllMenus(action->menu()); } }