Нема описа

mainwindow.cpp 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include "secondwindow.cpp"
  4. #include <QDebug>
  5. #include <QtCore/qmath.h>
  6. #include <QMessageBox>
  7. #include "functions.h"
  8. MainWindow::MainWindow(QWidget *parent) :
  9. QMainWindow(parent),
  10. ui(new Ui::MainWindow)
  11. {
  12. ui->setupUi(this);
  13. //These are the size of the arrays of widgets 'line-edit',
  14. //'label' and 'button'
  15. buttonSize = 2;
  16. lineSize = 7;
  17. labelSize = 8;
  18. // We set every pointer member to point NULL because we
  19. // when we delete every pointer we dont want to delete a
  20. // pointer that was already deleted in other moment or
  21. // was never used
  22. layout = NULL;
  23. for (int i = 0; i<buttonSize ; i++){
  24. button[i] = 0;
  25. }
  26. for (int i = 0; i < lineSize ; i++){
  27. line[i] = 0;
  28. }
  29. for (int i = 0; i<labelSize ; i++){
  30. label[i] = 0;
  31. }
  32. window = new secondwindow;
  33. // We need to know whenever the second window is closed to show the
  34. // main window, or to hide when the second one is showed
  35. connect(window, SIGNAL(cerrado(bool)), this, SLOT(mostrar(bool)));
  36. if(!dice1.load(":/images/resources/d1.png") || !dice2.load(":/images/resources/d1.png")){
  37. qDebug() << "Error1 Loading image";
  38. }
  39. initCheckWMaps();
  40. }
  41. MainWindow::~MainWindow()
  42. {
  43. delete ui;
  44. }
  45. //This function show the main window and delete all the items created on the closed one or hide the mainwindow
  46. void MainWindow::mostrar(bool si){
  47. if (si==true){
  48. show();
  49. // Deleting pointers and point them to NULL
  50. for (int i = 0; i<buttonSize ; i++){
  51. delete button[i];
  52. button[i] = NULL;
  53. }
  54. for (int i = 0; i<lineSize ; i++){
  55. delete line[i];
  56. line[i] = NULL;
  57. }
  58. for (int i = 0; i<labelSize ; i++){
  59. delete label[i];
  60. label[i] = NULL;
  61. }
  62. delete layout;
  63. layout = NULL;
  64. delete window;
  65. // Create the new window and connecting it again with the signal
  66. window = new secondwindow;
  67. connect(window, SIGNAL(cerrado(bool)), this, SLOT(mostrar(bool)));
  68. }
  69. else hide();
  70. }
  71. //It is a slot that reads what item of the combo box was selected and save it
  72. //into a member
  73. void MainWindow::whatOption(QString str){
  74. option = str;
  75. }
  76. //Clear all the lines that are used
  77. void MainWindow::clearLines(){
  78. for (int i = 0; i < lineSize; i++){
  79. if (line[i] != NULL){
  80. line[i]->clear();
  81. }
  82. }
  83. score1 = score2 = 0;
  84. }
  85. //It forces the input 1 to be valid
  86. void MainWindow::RPSnormalizer1(QString str){
  87. //For every character in the string only allow
  88. //the character 'R' for rock, 'P' for paper and
  89. //'S' for scissors. Delete all the other characters
  90. //different from this three, and if is 'r', 'p' or 's'
  91. //make it uppercase.
  92. for (int i = 0; i< str.size(); i++){
  93. if (str[i] == 'r'){
  94. str[i] = 'R';
  95. }
  96. else if (str[i] == 'p'){
  97. str[i] = 'P';
  98. }
  99. else if (str[i] == 's'){
  100. str[i] = 'S';
  101. }
  102. else if (str[i] == 'R' || str[i] == 'P' ||
  103. str[i] == 'S');//then its ok, do nothing
  104. else{
  105. str = str.mid(0,i).append(str.mid(i+1));
  106. }
  107. }
  108. line[0]->setText(str);
  109. }
  110. //It forces the input 2 to be valid
  111. void MainWindow::RPSnormalizer2(QString str){
  112. for (int i = 0; i< str.size(); i++){
  113. if (str[i] == 'r'){
  114. str[i] = 'R';
  115. }
  116. else if (str[i] == 'p'){
  117. str[i] = 'P';
  118. }
  119. else if (str[i] == 's'){
  120. str[i] = 'S';
  121. }
  122. else if (str[i] == 'R' || str[i] == 'P' ||
  123. str[i] == 'S');//then its ok, do nothing
  124. else{
  125. str = str.mid(0,i).append(str.mid(i+1));
  126. }
  127. }
  128. line[1]->setText(str);
  129. }
  130. //It forces the input 3 to be valid
  131. void MainWindow::RPSnormalizer3(QString str){
  132. //Verify that the string do not contains other thing than
  133. //numbers
  134. for (int i = 0; i< str.size(); i++){
  135. if (!str[i].isDigit()){
  136. str = str.mid(0,i).append(str.mid(i+1));
  137. }
  138. }
  139. //Left zeros do not count, delete them
  140. while (str[0] == '0'){
  141. str = str.mid(1);
  142. }
  143. //If the player exagerates the number of games to win
  144. //change the string to the maximum number allowed
  145. if (str.toInt() > 150){
  146. str = "150";
  147. }
  148. line[2]->setText(str);
  149. }
  150. //It forces the input to be valid
  151. void MainWindow::CheckWnormalizer(QString str){
  152. //Just allow numbers
  153. for (int i = 0; i< str.size(); i++){
  154. if (!str[i].isDigit()){
  155. str = str.mid(0,i).append(str.mid(i+1));
  156. }
  157. }
  158. //Zeros on the left side do not count (delete them)
  159. while (str[0] == '0'){
  160. str = str.mid(1);
  161. }
  162. //The maximum is 999,999,999
  163. if (str.toDouble() > 999999999){
  164. str = "999999999";
  165. }
  166. line[0]->setText(str);
  167. }
  168. //It forces the first input of Zulu to be valid
  169. void MainWindow::Zulunormalizer1(QString str){
  170. //Just allow numbers to be written
  171. for (int i = 0; i< str.size(); i++){
  172. if (!str[i].isDigit()){
  173. str = str.mid(0,i).append(str.mid(i+1));
  174. }
  175. }
  176. //The maximum here is 2359, so force it to be the
  177. //maximum when the user write a larger number
  178. if (str.toInt() > 2359){
  179. str = "2359";
  180. }
  181. line[0]->setText(str);
  182. }
  183. //It forces the second input of Zulu to be valid
  184. void MainWindow::Zulunormalizer2(QString str){
  185. //Just allow one character to be written
  186. if (str.size() > 1){
  187. str = str[1];
  188. }
  189. //If that only character is 'e', 'c', 'm' or 'p'
  190. //the uppercase it
  191. if (str[0] == 'e' || str[0] == 'c' ||
  192. str[0] == 'm' || str[0] == 'p'){
  193. str = str[0].toUpper();
  194. }
  195. //If we get here is because the character is not
  196. //the lowercase letters allowed... so if they are
  197. //not the uppercase letters that we admit we have
  198. //to delete it.
  199. else if (str[0] != 'E' || str[0] != 'C' ||
  200. str[0] != 'M' || str[0] != 'P'){
  201. str = "";
  202. }
  203. line[1]->setText(str);
  204. }
  205. //It forces the first input of APFT to be valid
  206. void MainWindow::APFTnormalizer1(QString str){
  207. //Just admit numbers, delete the other type of
  208. //characters
  209. for (int i = 0; i< str.size(); i++){
  210. if (!str[i].isDigit()){
  211. str = str.mid(0,i).append(str.mid(i+1));
  212. }
  213. }
  214. //Left zeros are not valid
  215. while (str[0] == '0'){
  216. str = str.mid(1);
  217. }
  218. line[0]->setText(str);
  219. }
  220. //It forces the second input of APFT to be valid
  221. void MainWindow::APFTnormalizer2(QString str){
  222. //Just allow the numbers to be written
  223. for (int i = 0; i< str.size(); i++){
  224. if (!str[i].isDigit()){
  225. str = str.mid(0,i).append(str.mid(i+1));
  226. }
  227. }
  228. //Left-hand zeros? Delete them
  229. while (str[0] == '0'){
  230. str = str.mid(1);
  231. }
  232. line[1]->setText(str);
  233. }
  234. //It forces the third input of APFT to be valid
  235. void MainWindow::APFTnormalizer3(QString str){
  236. //Allow just numbers on the string only if the
  237. //character is not in the position 2
  238. for (int i = 0; i< str.size(); i++){
  239. if (!str[i].isDigit() && i != 2){
  240. str = str.mid(0,i).append(str.mid(i+1));
  241. }
  242. }
  243. //Then if there is a character in the position 2
  244. //and it is not ':', then add it between the
  245. //position 1 and 3
  246. if (str.size() > 2 && str[2] != ':'){
  247. while (str.size()>2 && !str[2].isDigit()){
  248. str = str.mid(0,2).append(str.mid(3));
  249. }
  250. str = str.mid(0, 2).append(':').append(str.mid(2));
  251. }
  252. //If the size exceeds 5, then take the first five
  253. //so then we will have the format mm:ss
  254. if (str.size() > 5){
  255. str = str.mid(0, 5);
  256. }
  257. line[2]->setText(str);
  258. }
  259. //Checks which version of sort is selected and call it
  260. void MainWindow::sorts(){
  261. QString a = line[0]->text();
  262. QString b = line[1]->text();
  263. QString c = line[2]->text();
  264. if (!validateSorts(a,b,c)) {
  265. QMessageBox::warning(this, "Alert",
  266. "Please provide the three non-empty strings");
  267. return;
  268. }
  269. if (option == "Version Alpha"){
  270. mySortAlpha(a,b,c);
  271. }
  272. else if (option == "Version Beta"){
  273. mySortBeta(a,b,c);
  274. }
  275. else if (option == "Version Gamma"){
  276. mySortGamma(a,b,c);
  277. }
  278. else{
  279. mySortDelta(a,b,c);
  280. }
  281. line[3]->setText(a);
  282. line[4]->setText(b);
  283. line[5]->setText(c);
  284. }
  285. //Checks which version of RPS is selected and call it
  286. void MainWindow::RPSs(){
  287. QString p1 = line[0]->text();
  288. QString p2 = line[1]->text();
  289. QString gamesToWin = line[2]->text();
  290. if (p1.length() * p2.length() * gamesToWin.length() == 0) {
  291. QMessageBox::warning(this, "Alert",
  292. "Please provide a play for both players and the number of games to win");
  293. return;
  294. }
  295. int winnerNum;
  296. if (option == "Version Alpha")
  297. winnerNum = RPSAlpha(p1.toStdString()[0], p2.toStdString()[0], score1, score2);
  298. else if (option == "Version Beta")
  299. winnerNum = RPSBeta(p1.toStdString()[0], p2.toStdString()[0], score1, score2);
  300. else if (option == "Version Gamma")
  301. winnerNum = RPSGamma(p1.toStdString()[0], p2.toStdString()[0], score1, score2);
  302. else
  303. winnerNum = RPSDelta(p1.toStdString()[0], p2.toStdString()[0], score1, score2);
  304. QString st;
  305. switch(winnerNum) {
  306. case 1: st = "Player 1"; break;
  307. case 2: st = "Player 2"; break;
  308. case 0: st = "Tie"; break;
  309. default: st = "Error";
  310. }
  311. line[3]->setText(st);
  312. line[4]->setText(QString::number(score1) + " to " + QString::number(score2));
  313. if (score1 == gamesToWin.toInt() || score2 == gamesToWin.toInt() ) {
  314. QMessageBox::warning(this, "Alert",
  315. "Game won by " + st + "!!!");
  316. score1 = score2 = 0;
  317. }
  318. }
  319. //Checks which version of dice is selected and call it
  320. void MainWindow::dices(){
  321. if (option == "Version Alpha")
  322. diceAlpha();
  323. else if (option == "Version Beta")
  324. diceBeta();
  325. else if (option == "Version Gamma")
  326. diceGamma();
  327. else
  328. diceDelta();
  329. }
  330. //Checks which version of check-writer is selected and call it
  331. void MainWindow::checkWs(){
  332. unsigned int qty;
  333. if (!validateCheckQty(line[0]->text(),qty)) {
  334. QMessageBox::warning(this, "Alert",
  335. "Enter a valid amount!");
  336. }
  337. if (option == "Version Alpha")
  338. line[1]->setText( checkWAlpha(qty) );
  339. else if (option == "Version Beta")
  340. line[1]->setText( checkWBeta(qty) );
  341. else if (option == "Version Gamma")
  342. line[1]->setText( checkWGamma(qty) );
  343. else
  344. line[1]->setText( checkWDelta(qty) );
  345. }
  346. //Checks which version of zulu is selected and call it
  347. void MainWindow::zulus(){
  348. QString zuluTime = line[0]->text();
  349. QString zuluZone = line[1]->text();
  350. int hours, minutes;
  351. if (!validZuluTime(zuluTime, zuluZone, hours, minutes) ) {
  352. QMessageBox::warning(this, "Alert",
  353. "Either Zulu Time or Zone is not valid");
  354. line[2]->setText("Error");
  355. return;
  356. }
  357. if (option == "Version Alpha")
  358. line[2]->setText( zuluAlpha(hours, minutes, zuluZone.toStdString()[0]) );
  359. else if (option == "Version Beta")
  360. line[2]->setText( zuluBeta(hours, minutes, zuluZone.toStdString()[0]) );
  361. else if (option == "Version Gamma")
  362. line[2]->setText( zuluGamma(hours, minutes, zuluZone.toStdString()[0]) );
  363. else
  364. line[2]->setText( zuluDelta(hours, minutes, zuluZone.toStdString()[0]) );
  365. }
  366. //Checks which version of APFT is selected and call it
  367. void MainWindow::APFTs(){
  368. if (option == "Version Alpha"){
  369. APFTAlpha();
  370. }
  371. else if (option == "Version Beta"){
  372. APFTBeta();
  373. }
  374. else if (option == "Version Gamma"){
  375. APFTGamma();
  376. }
  377. else{
  378. APFTDelta();
  379. }
  380. }
  381. //Here is what happend when Sort-button is clicked
  382. void MainWindow::on_SortsButton_clicked()
  383. {
  384. //Create a new QComboBox and add the items in it
  385. method = new QComboBox;
  386. method->addItem("Version Alpha");
  387. method->addItem("Version Beta");
  388. method->addItem("Version Gamma");
  389. method->addItem("Version Delta");
  390. option = "Version Alpha"; //Default option is alpha
  391. //We create a new layout and insert the comboBox to it
  392. layout = new QGridLayout;
  393. layout->addWidget(method, 0, 0, 1, -1);
  394. //The buttons needed are sort and clear so we create them
  395. button[0] = new QPushButton("Sort");
  396. button[1] = new QPushButton("Clear");
  397. //3 lines for input and 3 for output
  398. for (int i = 0; i<6 ; i++){
  399. line[i] = new QLineEdit;
  400. }
  401. //The user is not able to write on the output lines
  402. line[3]->setEnabled(false);
  403. line[4]->setEnabled(false);
  404. line[5]->setEnabled(false);
  405. //Labels to let the user understand the app
  406. label[0] = new QLabel("Input");
  407. label[1] = new QLabel("Output");
  408. //Here we insert the widgets on the layout
  409. layout->addWidget(label[0], 1, 0);
  410. layout->addWidget(label[1], 1, 2);
  411. layout->addWidget(line[0], 2, 0);
  412. layout->addWidget(line[1], 3, 0);
  413. layout->addWidget(line[2], 4, 0);
  414. layout->addWidget(button[0], 1, 1, 2, 1);
  415. layout->addWidget(button[1], 3, 1, 2, 1);
  416. layout->addWidget(line[3], 2, 2);
  417. layout->addWidget(line[4], 3, 2);
  418. layout->addWidget(line[5], 4, 2);
  419. //Here we connect the signals of the widgets generated
  420. //by code to their respective functions
  421. connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(whatOption(QString)));
  422. connect(button[0], SIGNAL(clicked()), this, SLOT(sorts()));
  423. connect(button[1], SIGNAL(clicked()), this, SLOT(clearLines()));
  424. //Now that we have set our new window, we hide the main-window
  425. //and show the new one. The new-window has a signal that
  426. //notify when it was closed so we can shor the main-window
  427. window->setLayout(layout);
  428. mostrar(false);
  429. window->show();
  430. }
  431. //Here is what happend when Dice-button is clicked
  432. void MainWindow::on_DiceButton_clicked()
  433. {
  434. //Create a new QComboBox and add the items in it
  435. method = new QComboBox;
  436. method->addItem("Version Alpha");
  437. method->addItem("Version Beta");
  438. method->addItem("Version Gamma");
  439. method->addItem("Version Delta");
  440. option = "Version Alpha"; //Default option is alpha
  441. //We create a new layout and insert the comboBox to it
  442. layout = new QGridLayout;
  443. layout->addWidget(method, 0, 0, 1, -1);
  444. //Labels to let the user understand the app
  445. label[0] = new QLabel("Dice 1");
  446. label[1] = new QLabel("Dice 2");
  447. label[2] = new QLabel("Total");
  448. //The user is not able to write on the output line
  449. line[0] = new QLineEdit;
  450. line[0]->setEnabled(false);
  451. //Here we just need one button to roll the dices
  452. button[0] = new QPushButton("Roll them!");
  453. //Labels to put the dices' images on them
  454. label[3] = new QLabel;
  455. label[4] = new QLabel;
  456. label[3]->setPixmap(QPixmap::fromImage(dice1));
  457. label[4]->setPixmap(QPixmap::fromImage(dice2));
  458. //Here we insert the widgets on the layout
  459. layout->addWidget(label[0], 1, 0);
  460. layout->addWidget(label[3], 1, 1);
  461. layout->addWidget(label[1], 2, 0);
  462. layout->addWidget(label[4], 2, 1);
  463. layout->addWidget(label[2], 3, 0);
  464. layout->addWidget(line[0], 3, 1);
  465. layout->addWidget(button[0], 1, 2, 2, 1);
  466. //Here we connect the signals of the widgets generated
  467. //by code to their respective functions
  468. connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(whatOption(QString)));
  469. connect(button[0], SIGNAL(clicked()), this, SLOT(dices()));
  470. //Now that we have set our new window, we hide the main-window
  471. //and show the new one. The new-window has a signal that
  472. //notify when it was closed so we can shor the main-window
  473. window->setLayout(layout);
  474. mostrar(false);
  475. window->show();
  476. }
  477. //Here is what happend when RPS-button is clicked
  478. void MainWindow::on_RPSButton_clicked()
  479. {
  480. //Create a new QComboBox and add the items in it
  481. method = new QComboBox;
  482. method->addItem("Version Alpha");
  483. method->addItem("Version Beta");
  484. method->addItem("Version Gamma");
  485. method->addItem("Version Delta");
  486. option = "Version Alpha"; //Default option is alpha
  487. //We create a new layout and insert the comboBox to it
  488. layout = new QGridLayout;
  489. layout->addWidget(method, 0, 0, 1, -1);
  490. //The buttons needed here are the 'play' and 'clear' buttons
  491. button[0] = new QPushButton("Play");
  492. button[1] = new QPushButton("Clear");
  493. //3 inputs and 1 output
  494. for (int i = 0; i<4; i++){
  495. line[i] = new QLineEdit;
  496. }
  497. //The user is not able to write on the output line
  498. line[3]->setEnabled(false);
  499. //Labels to let the user understand the app
  500. label[0] = new QLabel("Player 1's moves");
  501. label[1] = new QLabel("Player 2's moves");
  502. label[2] = new QLabel("How many games to win:");
  503. label[3] = new QLabel("Winner:");
  504. label[4] = new QLabel("Tournament:");
  505. //lines for score
  506. line[4] = new QLineEdit;
  507. line[4]->setEnabled(false);
  508. //Here we insert the widgets on the layout
  509. layout->addWidget(label[0], 1, 0);
  510. layout->addWidget(line[0], 2, 0);
  511. layout->addWidget(label[1], 3, 0);
  512. layout->addWidget(line[1], 4, 0);
  513. layout->addWidget(label[2], 5, 0);
  514. layout->addWidget(line[2], 5, 1);
  515. layout->addWidget(label[3], 6, 0);
  516. layout->addWidget(line[3], 6, 1);
  517. layout->addWidget(button[0], 2, 1);
  518. layout->addWidget(button[1], 3, 1);
  519. layout->addWidget(line[4],7 ,1 );
  520. layout->addWidget(label[4],7 ,0 );
  521. //Here we connect the signals of the widgets generated
  522. //by code to their respective functions
  523. connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(whatOption(QString)));
  524. connect(button[0], SIGNAL(clicked()), this, SLOT(RPSs()));
  525. connect(button[1], SIGNAL(clicked()), this, SLOT(clearLines()));
  526. connect(line[0], SIGNAL(textEdited(QString)), this, SLOT(RPSnormalizer1(QString)));
  527. connect(line[1], SIGNAL(textEdited(QString)), this, SLOT(RPSnormalizer2(QString)));
  528. connect(line[2], SIGNAL(textEdited(QString)), this, SLOT(RPSnormalizer3(QString)));
  529. //Now that we have set our new window, we hide the main-window
  530. //and show the new one. The new-window has a signal that
  531. //notify when it was closed so we can shor the main-window
  532. window->setLayout(layout);
  533. mostrar(false);
  534. window->show();
  535. score1 = score2 = 0;
  536. }
  537. //Here is what happend when CheckWritter-button is clicked
  538. void MainWindow::on_CheckWriterButton_clicked()
  539. {
  540. //Create a new QComboBox and add the items in it
  541. method = new QComboBox;
  542. method->addItem("Version Alpha");
  543. method->addItem("Version Beta");
  544. method->addItem("Version Gamma");
  545. method->addItem("Version Delta");
  546. option = "Version Alpha"; //Default option is alpha
  547. //We create a new layout and insert the comboBox to it
  548. layout = new QGridLayout;
  549. layout->addWidget(method, 0, 0, 1, -1);
  550. //Label to let the user understand the app
  551. label[0] = new QLabel("Number to convert");
  552. //We just need two buttons to clear or convert
  553. button[0] = new QPushButton("Convert");
  554. button[1] = new QPushButton("Clear");
  555. //1 output and 1 input
  556. for (int i = 0; i<2; i++){
  557. line[i] = new QLineEdit;
  558. }
  559. //The user is not able to write on the output line
  560. line[1]->setEnabled(false);
  561. //Here we insert the widgets on the layout
  562. layout->addWidget(label[0], 1, 0, 1, 2);
  563. layout->addWidget(line[0], 2, 0, 1, 2);
  564. layout->addWidget(button[0], 3, 0);
  565. layout->addWidget(button[1], 3, 1);
  566. layout->addWidget(line[1], 4, 0, 1, 2);
  567. //Here we connect the signals of the widgets generated
  568. //by code to their respective functions
  569. connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(whatOption(QString)));
  570. connect(button[0], SIGNAL(clicked()), this, SLOT(checkWs()));
  571. connect(button[1], SIGNAL(clicked()), this, SLOT(clearLines()));
  572. //connect(line[0], SIGNAL(textEdited(QString)), this, SLOT(CheckWnormalizer(QString)));
  573. //Now that we have set our new window, we hide the main-window
  574. //and show the new one. The new-window has a signal that
  575. //notify when it was closed so we can shor the main-window
  576. window->setLayout(layout);
  577. mostrar(false);
  578. window->show();
  579. }
  580. //Here is what happend when Zulu-button is clicked
  581. void MainWindow::on_ZuluButton_clicked()
  582. {
  583. //Create a new QComboBox and add the items in it
  584. method = new QComboBox;
  585. method->addItem("Version Alpha");
  586. method->addItem("Version Beta");
  587. method->addItem("Version Gamma");
  588. method->addItem("Version Delta");
  589. option = "Version Alpha"; //Default option is alpha
  590. //We create a new layout and insert the comboBox to it
  591. layout = new QGridLayout;
  592. layout->addWidget(method, 0, 0, 1, -1);
  593. //Labels to let the user understand the app
  594. label[0] = new QLabel("Zulu time:");
  595. label[1] = new QLabel("Standard time");
  596. //Just the buttons to clear and convert the time
  597. button[0] = new QPushButton("Clear");
  598. button[1] = new QPushButton("Convert");
  599. //2 inputs and 1 output
  600. for (int i = 0; i<3; i++){
  601. line[i] = new QLineEdit;
  602. }
  603. //The user is not able to write on the output line
  604. line[2]->setEnabled(false);
  605. //Here we insert the widgets on the layout
  606. layout->addWidget(label[0], 1, 0);
  607. layout->addWidget(line[0], 2, 0);
  608. layout->addWidget(line[1], 2, 1);
  609. layout->addWidget(button[0], 3, 0);
  610. layout->addWidget(button[1], 3, 1);
  611. layout->addWidget(label[1], 4, 0);
  612. layout->addWidget(line[2], 4, 1);
  613. //Here we connect the signals of the widgets generated
  614. //by code to their respective functions
  615. connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(whatOption(QString)));
  616. connect(button[0], SIGNAL(clicked()), this, SLOT(clearLines()));
  617. connect(button[1], SIGNAL(clicked()), this, SLOT(zulus()));
  618. // Rafa 2014-09-16 - Validation will be done when button is clicked
  619. // connect(line[0], SIGNAL(textEdited(QString)), this, SLOT(Zulunormalizer1(QString)));
  620. // connect(line[1], SIGNAL(textEdited(QString)), this, SLOT(Zulunormalizer2(QString)));
  621. //Now that we have set our new window, we hide the main-window
  622. //and show the new one. The new-window has a signal that
  623. //notify when it was closed so we can shor the main-window
  624. window->setLayout(layout);
  625. mostrar(false);
  626. window->show();
  627. }
  628. //Here is what happend when APFT-button is clicked
  629. void MainWindow::on_APFTButton_clicked()
  630. {
  631. //Create a new QComboBox and add the items in it
  632. method = new QComboBox;
  633. method->addItem("Version Alpha");
  634. method->addItem("Version Beta");
  635. method->addItem("Version Gamma");
  636. method->addItem("Version Delta");
  637. option = "Version Alpha"; //Default option is alpha
  638. //We create a new layout and insert the comboBox to it
  639. layout = new QGridLayout;
  640. layout->addWidget(method, 0, 0, 1, -1);
  641. //3 inputs and 4 outputs
  642. for (int i = 0; i<7; i++){
  643. line[i] = new QLineEdit;
  644. }
  645. //The user is not able to write on the output lines
  646. line[3]->setEnabled(false);
  647. line[4]->setEnabled(false);
  648. line[5]->setEnabled(false);
  649. line[6]->setEnabled(false);
  650. //Labels to let the user understand the app
  651. label[0] = new QLabel("Sit-Ups");
  652. label[1] = new QLabel("Push-Ups");
  653. label[2] = new QLabel("2 Mile Run");
  654. label[3] = new QLabel("Sit-Ups Score");
  655. label[4] = new QLabel("Push-Ups Score");
  656. label[5] = new QLabel("2 Mile Run Score");
  657. label[6] = new QLabel("Total Score");
  658. label[7] = new QLabel("----");
  659. //Just the buttons to calculate it and clear the lines
  660. button[0] = new QPushButton("Calculate");
  661. button[1] = new QPushButton("Clear");
  662. //Here we insert the widgets on the layout
  663. layout->addWidget(label[0], 1, 0);
  664. layout->addWidget(label[1], 2, 0);
  665. layout->addWidget(label[2], 3, 0);
  666. layout->addWidget(button[0], 4, 0);
  667. layout->addWidget(line[0], 1, 1);
  668. layout->addWidget(line[1], 2, 1);
  669. layout->addWidget(line[2], 3, 1);
  670. layout->addWidget(button[1], 4, 1);
  671. layout->addWidget(label[3], 1, 2);
  672. layout->addWidget(label[4], 2, 2);
  673. layout->addWidget(label[5], 3, 2);
  674. layout->addWidget(label[6], 4, 2);
  675. layout->addWidget(line[3], 1, 3);
  676. layout->addWidget(line[4], 2, 3);
  677. layout->addWidget(line[5], 3, 3);
  678. layout->addWidget(line[6], 4, 3);
  679. layout->addWidget(label[7], 4, 4);
  680. //Here we connect the signals of the widgets generated
  681. //by code to their respective functions
  682. connect(method, SIGNAL(currentIndexChanged(QString)), this, SLOT(whatOption(QString)));
  683. connect(button[0], SIGNAL(clicked()), this, SLOT(APFTs()));
  684. connect(button[1], SIGNAL(clicked()), this, SLOT(clearLines()));
  685. connect(line[0], SIGNAL(textEdited(QString)), this, SLOT(APFTnormalizer1(QString)));
  686. connect(line[1], SIGNAL(textEdited(QString)), this, SLOT(APFTnormalizer2(QString)));
  687. connect(line[2], SIGNAL(textEdited(QString)), this, SLOT(APFTnormalizer3(QString)));
  688. //Now that we have set our new window, we hide the main-window
  689. //and show the new one. The new-window has a signal that
  690. //notify when it was closed so we can shor the main-window
  691. window->setLayout(layout);
  692. mostrar(false);
  693. window->show();
  694. }