/* * 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" Chronometre::Chronometre (const QString & nom , QWidget * parent = 0) : QGroupBox (nom , parent) { setFlat (false); heure = 0; minute = 0; seconde = 0; centieme = 0; ecranHeure = new QLCDNumber (2, this); ecranMinute = new QLCDNumber (2, this); ecranSeconde = new QLCDNumber (2, this); ecranCentieme = new QLCDNumber (2 , this); ecranHeure->setSegmentStyle (QLCDNumber::Flat); ecranMinute->setSegmentStyle (QLCDNumber::Flat); ecranSeconde->setSegmentStyle (QLCDNumber::Flat); ecranCentieme->setSegmentStyle (QLCDNumber::Flat); ecranLayout = new QHBoxLayout; ecranLayout->addWidget(ecranHeure); ecranLayout->addWidget(ecranMinute); ecranLayout->addWidget(ecranSeconde); ecranLayout->addWidget(ecranCentieme); 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; } void Chronometre::affichage () { ecranHeure->display(heure); ecranMinute->display(minute); ecranSeconde->display(seconde); ecranCentieme->display (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 (); } }