/* * MaFenetre.cpp * This file is part of ChronoCheckMate * * Copyright (C) 2010 - François Drouhard * * ChronoCheckMate is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ChronoCheckMate is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ChronoCheckMate; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include "MaFenetre.h" #include "Chronometre.h" #include #include #include #include #include MaFenetre::MaFenetre() : QWidget () { setFixedSize (400,150); marche = false; chrono1 = new Chronometre("Joueur 1" , this); chrono2 = new Chronometre("Joueur 2" , this); ////////////////// Groupe Définition de la classe /////////////////////////// layoutChrono = new QHBoxLayout; layoutChrono->addWidget(chrono1); layoutChrono->addWidget(chrono2); /*groupChrono = new QGroupBox ("Chronomètre d'échecs"); groupChrono->setLayout (layoutChrono);*/ ///////////////////////////// Boutons ///////////////////////////// boutonDemarrer = new QPushButton ("Commencer"); boutonSwitch = new QPushButton ("Changer"); boutonArreter = new QPushButton ("Arrêter"); boutonInit = new QPushButton ("Remettre à Zéro"); boutonArreter->setFocusPolicy (Qt::NoFocus); boutonSwitch->setFocusPolicy (Qt::NoFocus); boutonInit->setFocusPolicy (Qt::NoFocus); etatBoutons (true , false , false , false); layoutBoutonSwitch = new QHBoxLayout; layoutBoutonSwitch->addWidget (boutonDemarrer); layoutBoutonSwitch->addWidget (boutonSwitch); layoutBoutonSwitch->addWidget (boutonArreter); layoutBoutonSwitch->addWidget (boutonInit); ///////////////////////////// Bouton Quitter /////////////////////////// boutonQuitter = new QPushButton ("Quitter"); boutonQuitter->setFocusPolicy (Qt::NoFocus); layoutBoutons = new QHBoxLayout; layoutBoutons->addWidget (boutonQuitter); /////////////////////////////Mise en page finale /////////////////////////// layoutComplet = new QVBoxLayout; layoutComplet->addLayout (layoutChrono); layoutComplet->addLayout (layoutBoutonSwitch); layoutComplet->addLayout (layoutBoutons); setLayout (layoutComplet); setWindowTitle ("ChronoCheckMate"); ///////////////////////////// connections /////////////////////////// QObject::connect (boutonQuitter , SIGNAL(clicked ()) , qApp , SLOT(quit ())) ; QObject::connect (boutonDemarrer , SIGNAL (clicked () ) , this , SLOT (demarrer () )); QObject::connect (boutonSwitch , SIGNAL (clicked() ) , this , SLOT (switcher() )); QObject::connect (boutonArreter , SIGNAL (clicked() ) , this , SLOT (arreter() )); QObject::connect (boutonInit , SIGNAL (clicked () ) , this , SLOT (init () )); } ///////////////// Méthodes //////////////////// void MaFenetre::etatBoutons (bool bouton1, bool bouton2 , bool bouton3 , bool bouton4) { boutonDemarrer->setEnabled (bouton1); boutonSwitch->setEnabled (bouton2); boutonArreter->setEnabled (bouton3); boutonInit->setEnabled (bouton4); } ////////////////// SLOTS //////////////////////// void MaFenetre::demarrer () { if (marche == false ) { chrono1->reinit (); chrono2->reinit (); chrono1->start (); marche = true; etatBoutons (false , true , true , false); } } void MaFenetre::switcher () { if (marche == true) { chrono1->basculer (); chrono2->basculer (); } } void MaFenetre::arreter () { chrono1->stop(); chrono2->stop(); marche = false; etatBoutons (true , false , false , true); } void MaFenetre::init () { if (marche == false) { chrono1->reinit(); chrono2->reinit(); etatBoutons (true , false , false , false); } } void MaFenetre::keyReleaseEvent (QKeyEvent * evenement) { if (evenement->key() == Qt::Key_Space) { if (marche == true) { switcher(); } if (marche == false) { demarrer(); } } if (evenement->key() == Qt::Key_Return) { arreter(); } }