|
@@ -22,6 +22,7 @@
|
|
|
|
|
|
#include "MaFenetre.h"
|
|
|
#include "Chronometre.h"
|
|
|
+#include <QMenuBar>
|
|
|
#include <QHBoxLayout>
|
|
|
#include <QVBoxLayout>
|
|
|
#include <QPushButton>
|
|
@@ -33,47 +34,45 @@
|
|
|
#include <QDialogButtonBox>
|
|
|
|
|
|
MaFenetre::MaFenetre() :
|
|
|
- QWidget (),
|
|
|
+ QMainWindow (),
|
|
|
nomJoueur1 ("Joueur 1"),
|
|
|
nomJoueur2 ("Joueur 2")
|
|
|
{
|
|
|
- marche = false;
|
|
|
+ QWidget *centralWidget = new QWidget;
|
|
|
+
|
|
|
+ marche = false;
|
|
|
chrono1 = new Chronometre(nomJoueur1 , this);
|
|
|
chrono2 = new Chronometre(nomJoueur2 , this);
|
|
|
boutonInverser = new QPushButton ("<->");
|
|
|
+
|
|
|
////////////////// Groupe Définition de la classe ///////////////////////////
|
|
|
layoutChrono = new QHBoxLayout;
|
|
|
layoutChrono->addWidget(chrono1);
|
|
|
layoutChrono->addWidget(boutonInverser);
|
|
|
layoutChrono->addWidget(chrono2);
|
|
|
|
|
|
- /*groupChrono = new QGroupBox ("Chronomètre d'échecs");
|
|
|
- groupChrono->setLayout (layoutChrono);*/
|
|
|
+ ///////////////////////////// Menus ////////////////////////////
|
|
|
+ QMenu *menuFichier = menuBar()->addMenu("&Fichier");
|
|
|
+ QAction *actionNouveau = new QAction ("&Nouveau" , this);
|
|
|
+ QAction *actionChangerNom = new QAction ("&Changer nom des joueurs...", this);
|
|
|
+ QAction *actionQuitter = new QAction ("&Quitter" , this);
|
|
|
+ menuFichier->addAction(actionNouveau);
|
|
|
+ menuFichier->addAction(actionChangerNom);
|
|
|
+ menuFichier->addSeparator();
|
|
|
+ menuFichier->addAction(actionQuitter);
|
|
|
+
|
|
|
///////////////////////////// Boutons /////////////////////////////
|
|
|
- boutonDemarrer = new QPushButton ("Commencer");
|
|
|
- boutonSwitch = new QPushButton ("Changer");
|
|
|
- boutonArreter = new QPushButton ("Arrêter");
|
|
|
- boutonInit = new QPushButton ("Remettre à Zéro");
|
|
|
+ boutonDemarrer = new QPushButton ("Commencer (Barre Espace)");
|
|
|
+ boutonArreter = new QPushButton ("Arrêter(Touche Entrée)");
|
|
|
|
|
|
boutonArreter->setFocusPolicy (Qt::NoFocus);
|
|
|
- boutonSwitch->setFocusPolicy (Qt::NoFocus);
|
|
|
- boutonInit->setFocusPolicy (Qt::NoFocus);
|
|
|
boutonInverser->setFocusPolicy(Qt::NoFocus);
|
|
|
|
|
|
- etatBoutons (true , false , false , false);
|
|
|
+ etatBoutons (true , 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);
|
|
|
+ layoutBoutonSwitch->addWidget (boutonArreter);
|
|
|
|
|
|
///////////////////////////// Aide /////////////////////////////////////
|
|
|
QLabel *labelAide = new QLabel ("<b>Aide</b><br />Espace : Lancer le chrono/Donner le chrono<br />Entrée : Stopper les deux chronos");
|
|
@@ -83,31 +82,27 @@ MaFenetre::MaFenetre() :
|
|
|
layoutComplet->addLayout (layoutChrono);
|
|
|
layoutComplet->addLayout (layoutBoutonSwitch);
|
|
|
layoutComplet->addWidget (labelAide);
|
|
|
- layoutComplet->addLayout (layoutBoutons);
|
|
|
- setLayout (layoutComplet);
|
|
|
+ centralWidget->setLayout (layoutComplet);
|
|
|
+ setCentralWidget(centralWidget);
|
|
|
setWindowTitle ("ChronoCheckMate");
|
|
|
|
|
|
///////////////////////////// Ouverture de la boite de dialogue /////////////////
|
|
|
definirNomJoueurs();
|
|
|
|
|
|
///////////////////////////// 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 () ));
|
|
|
QObject::connect (boutonInverser , SIGNAL(clicked()) , this , SLOT(inverser()));
|
|
|
+ QObject::connect (actionNouveau, SIGNAL(triggered()) , this , SLOT(init()));
|
|
|
+ QObject::connect (actionChangerNom , SIGNAL(triggered()), this, SLOT(definirNomJoueurs()));
|
|
|
+ QObject::connect (actionQuitter , SIGNAL(triggered()) , qApp , SLOT(quit()));
|
|
|
}
|
|
|
|
|
|
///////////////// Méthodes ////////////////////
|
|
|
-void MaFenetre::etatBoutons (bool bouton1, bool bouton2 , bool bouton3 , bool bouton4) {
|
|
|
+void MaFenetre::etatBoutons (bool bouton1, bool bouton2) {
|
|
|
boutonDemarrer->setEnabled (bouton1);
|
|
|
- boutonSwitch->setEnabled (bouton2);
|
|
|
- boutonArreter->setEnabled (bouton3);
|
|
|
- boutonInit->setEnabled (bouton4);
|
|
|
+ boutonArreter->setEnabled (bouton2);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
////////////////// SLOTS ////////////////////////
|
|
|
void MaFenetre::inverser() {
|
|
|
layoutChrono->removeWidget(chrono1);
|
|
@@ -125,7 +120,7 @@ void MaFenetre::demarrer () {
|
|
|
chrono2->reinit ();
|
|
|
chrono1->start ();
|
|
|
marche = true;
|
|
|
- etatBoutons (false , true , true , false);
|
|
|
+ etatBoutons (false , true);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -146,15 +141,14 @@ void MaFenetre::arreter () {
|
|
|
chrono1->stop();
|
|
|
chrono2->stop();
|
|
|
marche = false;
|
|
|
- etatBoutons (true , false , false , true);
|
|
|
+ etatBoutons (true , false);
|
|
|
}
|
|
|
|
|
|
void MaFenetre::init () {
|
|
|
- if (marche == false) {
|
|
|
- chrono1->reinit();
|
|
|
- chrono2->reinit();
|
|
|
- etatBoutons (true , false , false , false);
|
|
|
- }
|
|
|
+ chrono1->reinit();
|
|
|
+ chrono2->reinit();
|
|
|
+ marche = false;
|
|
|
+ etatBoutons (true , false);
|
|
|
}
|
|
|
|
|
|
void MaFenetre::definirNomJoueurs() {
|