// RAN 2015-06-26 - Added Zulu Zone label // - Removed the onclick functions for the buttons that are no longer used #include "mainwindow.h" #include "ui_mainwindow.h" #include "secondwindow.cpp" #include #include #include #include #include "functions.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //These are the size of the arrays of widgets 'line-edit', //'label' and 'button' buttonSize = 2; lineSize = 7; labelSize = 8; // We set every pointer member to point NULL because we // when we delete every pointer we dont want to delete a // pointer that was already deleted in other moment or // was never used layout = NULL; for (int i = 0; iclear(); } } score1 = score2 = 0; } void MainWindow::callOneOfTheSorts(){ QString a = line[0]->text(); QString b = line[1]->text(); QString c = line[2]->text(); if (!validateSorts(a,b,c)) { QMessageBox::warning(this, "Alert", "Please provide the three non-empty strings"); return; } if (option == "Version Alpha"){ mySortAlpha(a,b,c); } else if (option == "Version Beta"){ mySortBeta(a,b,c); } else if (option == "Version Gamma"){ mySortGamma(a,b,c); } else{ mySortDelta(a,b,c); } line[3]->setText(a); line[4]->setText(b); line[5]->setText(c); } void MainWindow::callOneOfTheRPS(){ QString p1 = this->cmbPlayer01->currentText(); QString p2 = this->cmbPlayer02->currentText(); if (p1.length() * p2.length() == 0) { QMessageBox::warning(this, "Alert", "Please provide a play for both players and the number of games to win"); return; } int winnerNum; if (option == "Version Alpha") winnerNum = RPSDelta(p1.toStdString()[0], p2.toStdString()[0]); else if (option == "Version Beta") winnerNum = RPSBeta(p1.toStdString()[0], p2.toStdString()[0]); else if (option == "Version Gamma") winnerNum = RPSGamma(p1.toStdString()[0], p2.toStdString()[0]); else winnerNum = RPSDelta(p1.toStdString()[0], p2.toStdString()[0]); QString st; switch(winnerNum) { case 1: st = "Player 1"; break; case 2: st = "Player 2"; break; case 0: st = "Tie"; break; default: st = "Error"; } line[0]->setText(st); } void MainWindow::paintDice() { this->timerCounter++; int a, b; a = rand()%6; b = rand()%6; label[3]->setPixmap(QPixmap::fromImage(diceImages[a])); label[4]->setPixmap(QPixmap::fromImage(diceImages[b])); if (this->timerCounter == 10) { aTimer->stop(); diceFinal01 = a; diceFinal02 = b; if (option == "Version Alpha") diceBeta(); else if (option == "Version Beta") diceGamma(); else if (option == "Version Gamma") diceAlpha(); else diceAlpha(); } } void MainWindow::callOneOfTheDices(){ for (int i = 1; i <= 6; i++) this->diceImages.push_back(QImage(":/images/resources/d" + QString::number(i) + ".png")); aTimer = new QTimer; aTimer->setInterval(100); aTimer->setSingleShot(false); aTimer->start(); timerCounter = 0; QObject::connect(aTimer,&QTimer::timeout, this, &MainWindow::paintDice); //[&](){ birth(w, juana, avelardo, piolin);}); } //======================================================== // Functions for the dice roller //======================================================== void MainWindow::diceAlpha(){ int total = diceFinal01 + diceFinal02 + 2; line[0]->setText(QString::number(total)); } void MainWindow::diceBeta(){ int total = diceFinal01 + diceFinal01 + 2; line[0]->setText(QString::number(total)); } void MainWindow::diceGamma(){ int total = diceFinal01 - diceFinal02; line[0]->setText(QString::number(total)); } void MainWindow::diceDelta(){ int total = diceFinal01 + diceFinal02; line[0]->setText(QString::number(total)); } void MainWindow::callOneOfTheChecks(){ unsigned int qty; if (!validateCheckQty(line[0]->text(),qty)) { QMessageBox::warning(this, "Alert", "Enter a valid amount!"); } if (option == "Version Alpha") line[1]->setText( checkWAlpha(qty) ); else if (option == "Version Beta") line[1]->setText( checkWBeta(qty) ); else if (option == "Version Gamma") line[1]->setText( checkWGamma(qty) ); else line[1]->setText( checkWDelta(qty) ); } void MainWindow::callOneOfTheZulus(){ QString zuluTime = line[0]->text(); QString zuluZone = line[1]->text(); int hours, minutes; if (!validZuluTime(zuluTime, zuluZone, hours, minutes) ) { QMessageBox::warning(this, "Alert", "Either Zulu Time or Zone is not valid."); line[2]->setText("Error"); return; } if (option == "Version Alpha") line[2]->setText( zuluAlpha(hours, minutes, zuluZone.toStdString()[0]) ); else if (option == "Version Beta") line[2]->setText( zuluBeta(hours, minutes, zuluZone.toStdString()[0]) ); else if (option == "Version Gamma") line[2]->setText( zuluGamma(hours, minutes, zuluZone.toStdString()[0]) ); else line[2]->setText( zuluDelta(hours, minutes, zuluZone.toStdString()[0]) ); } void MainWindow::on_SortsButton_clicked() { //Create a new QComboBox and add the items in it method = new QComboBox; method->addItem("Version Alpha"); method->addItem("Version Beta"); method->addItem("Version Gamma"); method->addItem("Version Delta"); option = "Version Alpha"; //Default option is alpha //We create a new layout and insert the comboBox to it layout = new QGridLayout; layout->addWidget(method, 0, 0, 1, -1); //The buttons needed are sort and clear so we create them button[0] = new QPushButton("Sort"); button[1] = new QPushButton("Clear"); //3 lines for input and 3 for output for (int i = 0; i<6 ; i++){ line[i] = new QLineEdit; } //The user is not able to write on the output lines line[3]->setEnabled(false); line[4]->setEnabled(false); line[5]->setEnabled(false); //Labels to let the user understand the app label[0] = new QLabel("Input"); label[1] = new QLabel("Output"); //Here we insert the widgets on the layout layout->addWidget(label[0], 1, 0); layout->addWidget(label[1], 1, 2); layout->addWidget(line[0], 2, 0); layout->addWidget(line[1], 3, 0); layout->addWidget(line[2], 4, 0); layout->addWidget(button[0], 1, 1, 2, 1); layout->addWidget(button[1], 3, 1, 2, 1); layout->addWidget(line[3], 2, 2); layout->addWidget(line[4], 3, 2); layout->addWidget(line[5], 4, 2); //Here we connect the signals of the widgets generated //by code to their respective functions connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(setOption(QString))); connect(button[0], SIGNAL(clicked()), this, SLOT(callOneOfTheSorts())); connect(button[1], SIGNAL(clicked()), this, SLOT(clearLines())); //Now that we have set our new window, we hide the main-window //and show the new one. The new-window has a signal that //notify when it was closed so we can shor the main-window window->setLayout(layout); showMW(false); window->show(); } void MainWindow::on_DiceButton_clicked() { //Create a new QComboBox and add the items in it method = new QComboBox; method->addItem("Version Alpha"); method->addItem("Version Beta"); method->addItem("Version Gamma"); method->addItem("Version Delta"); option = "Version Alpha"; //Default option is alpha //We create a new layout and insert the comboBox to it layout = new QGridLayout; layout->addWidget(method, 0, 0, 1, -1); //Labels to let the user understand the app label[0] = new QLabel("Dice 1"); label[1] = new QLabel("Dice 2"); label[2] = new QLabel("Total"); //The user is not able to write on the output line line[0] = new QLineEdit; line[0]->setEnabled(false); //Here we just need one button to roll the dices button[0] = new QPushButton("Roll them!"); //Labels to put the dices' images on them label[3] = new QLabel; label[4] = new QLabel; label[3]->setPixmap(QPixmap::fromImage(dice1)); label[4]->setPixmap(QPixmap::fromImage(dice2)); //Here we insert the widgets on the layout layout->addWidget(label[0], 1, 0); layout->addWidget(label[3], 1, 1); layout->addWidget(label[1], 2, 0); layout->addWidget(label[4], 2, 1); layout->addWidget(label[2], 3, 0); layout->addWidget(line[0], 3, 1); layout->addWidget(button[0], 1, 2, 2, 1); //Here we connect the signals of the widgets generated //by code to their respective functions connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(setOption(QString))); connect(button[0], SIGNAL(clicked()), this, SLOT(callOneOfTheDices())); //Now that we have set our new window, we hide the main-window //and show the new one. The new-window has a signal that //notify when it was closed so we can shor the main-window window->setLayout(layout); showMW(false); window->show(); } void MainWindow::on_RPSButton_clicked() { //Create a new QComboBox and add the items in it method = new QComboBox; method->addItem("Version Alpha"); method->addItem("Version Beta"); method->addItem("Version Gamma"); method->addItem("Version Delta"); option = "Version Alpha"; //Default option is alpha cmbPlayer01 = new QComboBox; cmbPlayer02 = new QComboBox; cmbPlayer01->addItem("rock"); cmbPlayer02->addItem("rock"); cmbPlayer01->addItem("paper"); cmbPlayer02->addItem("paper"); cmbPlayer01->addItem("scisors"); cmbPlayer02->addItem("scisors"); //The buttons needed here are the 'play' and 'clear' buttons button[0] = new QPushButton("Play"); line[0] = new QLineEdit; //The user is not able to write on the output line line[0]->setEnabled(false); //Labels to let the user understand the app label[0] = new QLabel("Player 1's moves"); label[1] = new QLabel("Player 2's moves"); label[2] = new QLabel("Winner:"); //We create a new layout and insert the comboBox to it int row = 0; layout = new QGridLayout; layout->addWidget(method, row++, 0); layout->addWidget(label[0], row, 0); layout->addWidget(cmbPlayer01, row++, 1); layout->addWidget(label[1], row, 0); layout->addWidget(cmbPlayer02, row++, 1); layout->addWidget(button[0], row++, 1); layout->addWidget(line[0], row, 1); layout->addWidget(label[2], row++, 0); //Here we connect the signals of the widgets generated //by code to their respective functions connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(setOption(QString))); connect(button[0], SIGNAL(clicked()), this, SLOT(callOneOfTheRPS())); //Now that we have set our new window, we hide the main-window //and show the new one. The new-window has a signal that //notify when it was closed so we can shor the main-window window->setLayout(layout); showMW(false); window->show(); } void MainWindow::on_ZuluButton_clicked() { //Create a new QComboBox and add the items in it method = new QComboBox; method->addItem("Version Alpha"); method->addItem("Version Beta"); method->addItem("Version Gamma"); method->addItem("Version Delta"); option = "Version Alpha"; //Default option is alpha //We create a new layout and insert the comboBox to it layout = new QGridLayout; layout->addWidget(method, 0, 0, 1, -1); //Labels to let the user understand the app label[0] = new QLabel("Zulu time:"); label[1] = new QLabel("Standard time"); label[2] = new QLabel("Zulu zone:"); //Just the buttons to clear and convert the time button[0] = new QPushButton("Clear"); button[1] = new QPushButton("Convert"); //2 inputs and 1 output for (int i = 0; i<3; i++){ line[i] = new QLineEdit; } //The user is not able to write on the output line line[2]->setEnabled(false); //Here we insert the widgets on the layout layout->addWidget(label[0], 1, 0); layout->addWidget(label[2], 1, 1); layout->addWidget(line[0], 2, 0); layout->addWidget(line[1], 2, 1); layout->addWidget(button[0], 3, 0); layout->addWidget(button[1], 3, 1); layout->addWidget(label[1], 4, 0); layout->addWidget(line[2], 4, 1); //Here we connect the signals of the widgets generated //by code to their respective functions connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(setOption(QString))); connect(button[0], SIGNAL(clicked()), this, SLOT(clearLines())); connect(button[1], SIGNAL(clicked()), this, SLOT(callOneOfTheZulus())); // Rafa 2014-09-16 - Validation will be done when button is clicked // connect(line[0], SIGNAL(textEdited(QString)), this, SLOT(Zulunormalizer1(QString))); // connect(line[1], SIGNAL(textEdited(QString)), this, SLOT(Zulunormalizer2(QString))); //Now that we have set our new window, we hide the main-window //and show the new one. The new-window has a signal that //notify when it was closed so we can shor the main-window window->setLayout(layout); showMW(false); window->show(); }