|
@@ -31,22 +31,17 @@
|
|
#include <QTime>
|
|
#include <QTime>
|
|
#include <QSound>
|
|
#include <QSound>
|
|
|
|
|
|
-Chronometre::Chronometre (const QString & nom , int tempsDepart, bool son, QWidget * parent = nullptr) :
|
|
|
|
|
|
+Chronometre::Chronometre (const QString & nom , QTime const& tempsDepart, bool son, QWidget * parent = nullptr) :
|
|
QGroupBox (nom , parent),
|
|
QGroupBox (nom , parent),
|
|
- ms(0),
|
|
|
|
- msTempsDepart(0),
|
|
|
|
|
|
+ temps(tempsDepart),
|
|
|
|
+ msTempsDepart(tempsDepart),
|
|
sonnette(son)
|
|
sonnette(son)
|
|
{
|
|
{
|
|
- // init des compteurs
|
|
|
|
- definirTemps(tempsDepart);
|
|
|
|
- ms = msTempsDepart;
|
|
|
|
-
|
|
|
|
setFlat(false);
|
|
setFlat(false);
|
|
|
|
|
|
- temps = new QTime (0,0,0,0);
|
|
|
|
QFont font("Arial" , 22 , 5);
|
|
QFont font("Arial" , 22 , 5);
|
|
|
|
|
|
- ecranTemps = new QLabel (temps->toString("hh:mm::ss:zzz"));
|
|
|
|
|
|
+ ecranTemps = new QLabel(temps.toString("hh:mm:ss:zzz"));
|
|
ecranTemps->setFont(font);
|
|
ecranTemps->setFont(font);
|
|
|
|
|
|
ecranLayout = new QHBoxLayout;
|
|
ecranLayout = new QHBoxLayout;
|
|
@@ -54,10 +49,8 @@ Chronometre::Chronometre (const QString & nom , int tempsDepart, bool son, QWidg
|
|
ecranLayout->addWidget(ecranTemps);
|
|
ecranLayout->addWidget(ecranTemps);
|
|
ecranLayout->addSpacing(40);
|
|
ecranLayout->addSpacing(40);
|
|
|
|
|
|
-
|
|
|
|
setLayout (ecranLayout);
|
|
setLayout (ecranLayout);
|
|
|
|
|
|
- affichage();
|
|
|
|
timer = new QTimer (this);
|
|
timer = new QTimer (this);
|
|
timer->setInterval (INTERVAL);
|
|
timer->setInterval (INTERVAL);
|
|
QObject::connect (timer , SIGNAL (timeout() ) , this , SLOT (refresh()));
|
|
QObject::connect (timer , SIGNAL (timeout() ) , this , SLOT (refresh()));
|
|
@@ -67,8 +60,8 @@ void Chronometre::modifierNomJoueur(QString joueur) {
|
|
setTitle(joueur);
|
|
setTitle(joueur);
|
|
}
|
|
}
|
|
|
|
|
|
-void Chronometre::definirTemps(int tempsDepart) {
|
|
|
|
- msTempsDepart = tempsDepart*1000*60;
|
|
|
|
|
|
+void Chronometre::definirTemps(QTime const& tempsDepart) {
|
|
|
|
+ msTempsDepart = tempsDepart;
|
|
}
|
|
}
|
|
|
|
|
|
void Chronometre::modifierSon(bool son) {
|
|
void Chronometre::modifierSon(bool son) {
|
|
@@ -76,8 +69,8 @@ void Chronometre::modifierSon(bool son) {
|
|
}
|
|
}
|
|
|
|
|
|
void Chronometre::refresh () {
|
|
void Chronometre::refresh () {
|
|
- ms -= INTERVAL;
|
|
|
|
- if (ms <= 0) {
|
|
|
|
|
|
+ temps = temps.addMSecs(-INTERVAL);
|
|
|
|
+ if (temps <= QTime (0,0,0,0)) {
|
|
if (sonnette == true)
|
|
if (sonnette == true)
|
|
QSound::play(":/ressources/sonnette.wav");
|
|
QSound::play(":/ressources/sonnette.wav");
|
|
emit fin();
|
|
emit fin();
|
|
@@ -95,7 +88,7 @@ void Chronometre::stop () {
|
|
|
|
|
|
|
|
|
|
void Chronometre::affichage () {
|
|
void Chronometre::affichage () {
|
|
- QString chaineTemps = temps->addMSecs(ms).toString("hh:mm:ss:zzz");
|
|
|
|
|
|
+ QString chaineTemps = temps.toString("hh:mm:ss:zzz");
|
|
ecranTemps->setText(chaineTemps);
|
|
ecranTemps->setText(chaineTemps);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -103,7 +96,7 @@ void Chronometre::reinit () {
|
|
if (timer->isActive()) {
|
|
if (timer->isActive()) {
|
|
timer->stop();
|
|
timer->stop();
|
|
}
|
|
}
|
|
- ms = msTempsDepart;
|
|
|
|
|
|
+ temps = msTempsDepart;
|
|
affichage();
|
|
affichage();
|
|
}
|
|
}
|
|
|
|
|