Chronometre.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 <QtWidgets>
  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("Arial" , 22 , 5);
  38. ecranTemps = new QLabel (temps->toString("hh:mm::ss:zzz"));
  39. ecranTemps->setFont(font);
  40. ecranLayout = new QHBoxLayout;
  41. ecranLayout->addSpacing(40);
  42. ecranLayout->addWidget(ecranTemps);
  43. ecranLayout->addSpacing(40);
  44. setLayout (ecranLayout);
  45. affichage();
  46. timer = new QTimer (this);
  47. timer->setInterval (10);
  48. QObject::connect (timer , SIGNAL (timeout() ) , this , SLOT (refresh()));
  49. }
  50. void Chronometre::modifierNomJoueur(QString joueur) {
  51. setTitle(joueur);
  52. }
  53. void Chronometre::refresh () {
  54. ms += 10;
  55. affichage ();
  56. }
  57. void Chronometre::start () {
  58. timer->start ();
  59. }
  60. void Chronometre::stop () {
  61. timer->stop();
  62. }
  63. void Chronometre::affichage () {
  64. QString chaineTemps = temps->addMSecs(ms).toString("hh:mm:ss:zzz");
  65. ecranTemps->setText(chaineTemps);
  66. }
  67. void Chronometre::reinit () {
  68. if (timer->isActive()) {
  69. timer->stop();
  70. }
  71. ms = 0;
  72. affichage();
  73. }
  74. void Chronometre::basculer () {
  75. if (timer->isActive()) {
  76. timer->stop();
  77. }
  78. else {
  79. timer->start ();
  80. }
  81. }