Chronometre.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Chronometre.cpp
  3. * This file is part of ChronoCheckMate
  4. *
  5. * Copyright (C) 2010 - François Drouhard
  6. *
  7. * ChronoCheckMate is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * ChronoCheckMate is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with ChronoCheckMate; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301 USA
  21. */
  22. #include "Chronometre.h"
  23. #include <QTimer>
  24. #include <QWidget>
  25. #include <QLCDNumber>
  26. #include <QObject>
  27. #include <QHBoxLayout>
  28. Chronometre::Chronometre (const QString & nom , QWidget * parent = 0) : QGroupBox (nom , parent) {
  29. setFlat (false);
  30. heure = 0;
  31. minute = 0;
  32. seconde = 0;
  33. centieme = 0;
  34. ecranHeure = new QLCDNumber (2, this);
  35. ecranMinute = new QLCDNumber (2, this);
  36. ecranSeconde = new QLCDNumber (2, this);
  37. ecranCentieme = new QLCDNumber (2 , this);
  38. ecranHeure->setSegmentStyle (QLCDNumber::Flat);
  39. ecranMinute->setSegmentStyle (QLCDNumber::Flat);
  40. ecranSeconde->setSegmentStyle (QLCDNumber::Flat);
  41. ecranCentieme->setSegmentStyle (QLCDNumber::Flat);
  42. ecranLayout = new QHBoxLayout;
  43. ecranLayout->addWidget(ecranHeure);
  44. ecranLayout->addWidget(ecranMinute);
  45. ecranLayout->addWidget(ecranSeconde);
  46. ecranLayout->addWidget(ecranCentieme);
  47. setLayout (ecranLayout);
  48. affichage();
  49. timer = new QTimer (this);
  50. timer->setInterval (10);
  51. QObject::connect (timer , SIGNAL (timeout() ) , this , SLOT (refresh()));
  52. }
  53. void Chronometre::refresh () {
  54. if (centieme == 99) {
  55. if (seconde == 59) {
  56. if (minute == 59) {
  57. heure += 1;
  58. minute = 0;
  59. seconde = 0;
  60. centieme = 0;
  61. }
  62. else {
  63. minute += 1;
  64. seconde = 0;
  65. centieme = 0;
  66. }
  67. }
  68. else {
  69. seconde += 1;
  70. centieme = 0;
  71. }
  72. }
  73. else {
  74. centieme += 1;
  75. }
  76. affichage ();
  77. }
  78. void Chronometre::start () {
  79. timer->start ();
  80. }
  81. void Chronometre::stop () {
  82. timer->stop();
  83. }
  84. int Chronometre::getHeure () {
  85. return heure;
  86. }
  87. int Chronometre::getMinute () {
  88. return minute;
  89. }
  90. int Chronometre::getSeconde () {
  91. return seconde;
  92. }
  93. int Chronometre::getCentieme () {
  94. return centieme;
  95. }
  96. void Chronometre::affichage () {
  97. ecranHeure->display(heure);
  98. ecranMinute->display(minute);
  99. ecranSeconde->display(seconde);
  100. ecranCentieme->display (centieme);
  101. }
  102. void Chronometre::reinit () {
  103. if (timer->isActive()) {
  104. timer->stop();
  105. }
  106. heure = 0;
  107. minute = 0;
  108. seconde = 0;
  109. centieme = 0;
  110. affichage();
  111. }
  112. void Chronometre::basculer () {
  113. if (timer->isActive()) {
  114. timer->stop();
  115. }
  116. else {
  117. timer->start ();
  118. }
  119. }