Chronometre.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <QLabel>
  26. #include <QObject>
  27. #include <QHBoxLayout>
  28. #include <QDebug>
  29. #include <QFont>
  30. #include <QTime>
  31. Chronometre::Chronometre (const QString & nom , QWidget * parent = 0) :
  32. QGroupBox (nom , parent),
  33. ms(0)
  34. {
  35. setFlat(false);
  36. temps = new QTime (0,0,0,0);
  37. QFont font("Times New Roman" , 22 , 5);
  38. ecranTemps = new QLabel (temps->toString("hh:mm::ss:zzz"));
  39. ecranTemps->setFont(font);
  40. ecranLayout = new QHBoxLayout;
  41. ecranLayout->addWidget(ecranTemps);
  42. ecranLayout->addSpacing(40);
  43. setLayout (ecranLayout);
  44. affichage();
  45. timer = new QTimer (this);
  46. timer->setInterval (10);
  47. QObject::connect (timer , SIGNAL (timeout() ) , this , SLOT (refresh()));
  48. }
  49. void Chronometre::refresh () {
  50. ms += 10;
  51. affichage ();
  52. }
  53. void Chronometre::start () {
  54. timer->start ();
  55. }
  56. void Chronometre::stop () {
  57. timer->stop();
  58. }
  59. void Chronometre::affichage () {
  60. QString chaineTemps = temps->addMSecs(ms).toString("hh:mm:ss:zzz");
  61. ecranTemps->setText(chaineTemps);
  62. }
  63. void Chronometre::reinit () {
  64. if (timer->isActive()) {
  65. timer->stop();
  66. }
  67. ms = 0;
  68. affichage();
  69. }
  70. void Chronometre::basculer () {
  71. if (timer->isActive()) {
  72. timer->stop();
  73. }
  74. else {
  75. timer->start ();
  76. }
  77. }