| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | /* * 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 <QWidget>#include <QLabel>#include <QObject>#include <QHBoxLayout>#include <QDebug>Chronometre::Chronometre (const QString & nom , QWidget * parent = 0) : QGroupBox (nom , parent) {	heure = 0;	minute = 0;	seconde = 0;	centieme = 0;	    ecranHeure = new QLabel ("00", this);    ecranMinute = new QLabel ("00" , this);    ecranSeconde = new QLabel ("00" , this);    ecranCentieme = new QLabel ("00" , this);		ecranLayout = new QHBoxLayout;    ecranLayout->addWidget(ecranHeure, Qt::AlignLeft);    ecranLayout->addWidget(new QLabel(":"));    ecranLayout->addWidget(ecranMinute , Qt::AlignLeft);    ecranLayout->addWidget(new QLabel(":"));    ecranLayout->addWidget(ecranSeconde, Qt::AlignLeft);    ecranLayout->addWidget(new QLabel(":"));    ecranLayout->addWidget(ecranCentieme, Qt::AlignLeft);		setLayout (ecranLayout);		affichage();		timer = new QTimer  (this);	timer->setInterval (10);	QObject::connect (timer , SIGNAL (timeout() ) , this , SLOT (refresh()));}void Chronometre::refresh () {	if (centieme == 99) {		if (seconde == 59) {			if (minute == 59) {				heure += 1;				minute = 0;				seconde = 0;				centieme = 0;			}			else {				minute += 1;				seconde = 0;				centieme = 0;			}		}		else {			seconde += 1;			centieme = 0;		}	}	else {		centieme += 1;	}		affichage ();}void Chronometre::start () {	timer->start ();}void Chronometre::stop () {	timer->stop();}int Chronometre::getHeure () {	return heure;}int Chronometre::getMinute () {	return minute;}int Chronometre::getSeconde () {	return seconde;}int Chronometre::getCentieme () {	return centieme;}QString Chronometre::qString (int nombre) {    QString qNombre;    qNombre = "<b>";    if (nombre < 10) {        qNombre.append("0");    }    qNombre.append(QString::number(nombre));    qNombre.append("</b>");    return qNombre;}void Chronometre::affichage () {    ecranHeure->setText(qString (heure));    ecranMinute->setText(qString(minute));    ecranSeconde->setText(qString(seconde));    ecranCentieme->setText(qString(centieme));}void Chronometre::reinit () {	if (timer->isActive()) {		timer->stop();	}	heure = 0;	minute = 0;	seconde = 0;	centieme = 0;	affichage();}void Chronometre::basculer () {	if (timer->isActive()) {		timer->stop();	}	else {		timer->start ();	}}
 |