| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 | /* * Chronometre.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 "Chronometre.h"#include <QTimer>#include <QtWidgets>#include <QLabel>#include <QObject>#include <QHBoxLayout>#include <QDebug>#include <QFont>#include <QTime>#include <QSound>Chronometre::Chronometre (const QString & nom , int tempsDepart, bool son, QWidget * parent = nullptr) :    QGroupBox (nom , parent),    ms(0),    msTempsDepart(0),    sonnette(son){    // init des compteurs    definirTemps(tempsDepart);    ms = msTempsDepart;    setFlat(false);    temps = new QTime (0,0,0,0);    QFont font("Arial" , 22 , 5);    ecranTemps = new QLabel (temps->toString("hh:mm::ss:zzz"));    ecranTemps->setFont(font);    ecranLayout = new QHBoxLayout;    ecranLayout->addSpacing(40);    ecranLayout->addWidget(ecranTemps);    ecranLayout->addSpacing(40);    setLayout (ecranLayout);	    affichage();    timer = new QTimer  (this);	timer->setInterval (10);	QObject::connect (timer , SIGNAL (timeout() ) , this , SLOT (refresh()));}void Chronometre::modifierNomJoueur(QString joueur) {    setTitle(joueur);}void Chronometre::definirTemps(int tempsDepart) {    msTempsDepart = tempsDepart*1000;//*60;}void Chronometre::modifierSon(bool son) {    sonnette = son;}void Chronometre::refresh () {    ms -= 10;    if (ms <= 0) {        if (sonnette == true)            QSound::play(":/ressources/sonnette.wav");        emit fin();    }	affichage ();}void Chronometre::start () {	timer->start ();}void Chronometre::stop () {    timer->stop();}void Chronometre::affichage () {    QString chaineTemps = temps->addMSecs(ms).toString("hh:mm:ss:zzz");    ecranTemps->setText(chaineTemps);}void Chronometre::reinit () {	if (timer->isActive()) {		timer->stop();	}    ms  = msTempsDepart;	affichage();}void Chronometre::basculer () {	if (timer->isActive()) {		timer->stop();	}	else {		timer->start ();	}}
 |