MaFenetre.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * MaFenetre.cpp
  3. * This file is part of ChronoCheckMate
  4. *
  5. * Copyright (C) 2010 - François Drouhard
  6. *
  7. * ChronoCheckMate is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * ChronoCheckMate is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with ChronoCheckMate; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301 USA
  21. */
  22. #include "MaFenetre.h"
  23. MaFenetre::MaFenetre() : QWidget () {
  24. setFixedSize (400,150);
  25. marche = false;
  26. chrono1 = new Chronometre("Joueur 1" , this);
  27. chrono2 = new Chronometre("Joueur 2" , this);
  28. ////////////////// Groupe Définition de la classe ///////////////////////////
  29. layoutChrono = new QHBoxLayout;
  30. layoutChrono->addWidget(chrono1);
  31. layoutChrono->addWidget(chrono2);
  32. /*groupChrono = new QGroupBox ("Chronomètre d'échecs");
  33. groupChrono->setLayout (layoutChrono);*/
  34. ///////////////////////////// Boutons /////////////////////////////
  35. boutonDemarrer = new QPushButton ("Commencer");
  36. boutonSwitch = new QPushButton ("Changer");
  37. boutonArreter = new QPushButton ("Arrêter");
  38. boutonInit = new QPushButton ("Remettre à Zéro");
  39. boutonArreter->setFocusPolicy (Qt::NoFocus);
  40. boutonSwitch->setFocusPolicy (Qt::NoFocus);
  41. boutonInit->setFocusPolicy (Qt::NoFocus);
  42. etatBoutons (true , false , false , false);
  43. layoutBoutonSwitch = new QHBoxLayout;
  44. layoutBoutonSwitch->addWidget (boutonDemarrer);
  45. layoutBoutonSwitch->addWidget (boutonSwitch);
  46. layoutBoutonSwitch->addWidget (boutonArreter);
  47. layoutBoutonSwitch->addWidget (boutonInit);
  48. ///////////////////////////// Bouton Quitter ///////////////////////////
  49. boutonQuitter = new QPushButton ("Quitter");
  50. boutonQuitter->setFocusPolicy (Qt::NoFocus);
  51. layoutBoutons = new QHBoxLayout;
  52. layoutBoutons->addWidget (boutonQuitter);
  53. /////////////////////////////Mise en page finale ///////////////////////////
  54. layoutComplet = new QVBoxLayout;
  55. layoutComplet->addLayout (layoutChrono);
  56. layoutComplet->addLayout (layoutBoutonSwitch);
  57. layoutComplet->addLayout (layoutBoutons);
  58. setLayout (layoutComplet);
  59. setWindowTitle ("ChronoCheckMate");
  60. ///////////////////////////// connections ///////////////////////////
  61. QObject::connect (boutonQuitter , SIGNAL(clicked ()) , qApp , SLOT(quit ())) ;
  62. QObject::connect (boutonDemarrer , SIGNAL (clicked () ) , this , SLOT (demarrer () ));
  63. QObject::connect (boutonSwitch , SIGNAL (clicked() ) , this , SLOT (switcher() ));
  64. QObject::connect (boutonArreter , SIGNAL (clicked() ) , this , SLOT (arreter() ));
  65. QObject::connect (boutonInit , SIGNAL (clicked () ) , this , SLOT (init () ));
  66. }
  67. ///////////////// Méthodes ////////////////////
  68. void MaFenetre::etatBoutons (bool bouton1, bool bouton2 , bool bouton3 , bool bouton4) {
  69. boutonDemarrer->setEnabled (bouton1);
  70. boutonSwitch->setEnabled (bouton2);
  71. boutonArreter->setEnabled (bouton3);
  72. boutonInit->setEnabled (bouton4);
  73. }
  74. ////////////////// SLOTS ////////////////////////
  75. void MaFenetre::demarrer () {
  76. if (marche == false ) {
  77. chrono1->reinit ();
  78. chrono2->reinit ();
  79. chrono1->start ();
  80. marche = true;
  81. etatBoutons (false , true , true , false);
  82. }
  83. }
  84. void MaFenetre::switcher () {
  85. if (marche == true) {
  86. chrono1->basculer ();
  87. chrono2->basculer ();
  88. }
  89. }
  90. void MaFenetre::arreter () {
  91. chrono1->stop();
  92. chrono2->stop();
  93. marche = false;
  94. etatBoutons (true , false , false , true);
  95. }
  96. void MaFenetre::init () {
  97. if (marche == false) {
  98. chrono1->reinit();
  99. chrono2->reinit();
  100. etatBoutons (true , false , false , false);
  101. }
  102. }
  103. void MaFenetre::keyReleaseEvent (QKeyEvent * evenement) {
  104. if (evenement->key() == Qt::Key_Space) {
  105. switcher();
  106. }
  107. if (evenement->key() == Qt::Key_Return) {
  108. arreter();
  109. }
  110. }