123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- /*
- * 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 ();
- }
- }
|