123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /*
- * 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"
- #include <QTimer>
- #include <QtWidgets>
- #include <QLabel>
- #include <QObject>
- #include <QHBoxLayout>
- #include <QDebug>
- #include <QFont>
- #include <QTime>
- #include <QGroupBox>
- #include <QDebug>
- Chronometre::Chronometre (const QString & nom, Couleur unecouleur, QTime const& tempsDepart, Placement placement, QWidget * parent) :
- QWidget (parent),
- couleur(unecouleur),
- temps(tempsDepart),
- msTempsDepart(tempsDepart)
- {
- QHBoxLayout *layoutPrincipal = new QHBoxLayout;
- labelPion = new QLabel;
- pion = new QPixmap();
- setCouleur(couleur);
- labelPion->setPixmap(*pion);
- groupBox = new QGroupBox(nom);
- groupBox->setFlat(false);
- groupBox->setFont(QFont(groupBox->font().family(), 15));
- QFont font("Arial", 45, QFont::Black);
- ecranTemps = new QLabel();
- ecranTemps->setMinimumWidth(200);
- ecranTemps->setFont(font);
- ecranTemps->setDisabled(true);
- ecranLayout = new QHBoxLayout;
- //ecranLayout->addSpacing(10);
- //ecranLayout->addStretch(1);
- ecranLayout->addWidget(ecranTemps, 0, Qt::AlignHCenter);
- //ecranLayout->addStretch(1);
- //ecranLayout->addSpacing(10);
- if (placement == Placement::Gauche)
- {
- layoutPrincipal->addWidget(labelPion,0);
- layoutPrincipal->addWidget(groupBox,1);
- } else
- {
- layoutPrincipal->addWidget(groupBox,1);
- layoutPrincipal->addWidget(labelPion,0);
- }
- groupBox->setLayout (ecranLayout);
- setLayout(layoutPrincipal);
-
- timer = new QTimer (this);
- timer->setInterval (INTERVAL);
- QObject::connect (timer , &QTimer::timeout , this , &Chronometre::refresh);
- }
- void Chronometre::modifierNomJoueur(QString const& joueur) {
- groupBox->setTitle(joueur);
- }
- void Chronometre::definirTemps(QTime const& tempsDepart) {
- msTempsDepart = tempsDepart;
- }
- void Chronometre::echangerCouleur(Chronometre & chrono) {
- Couleur temp = couleur;
- setCouleur(chrono.couleur);
- chrono.setCouleur(temp);
- }
- void Chronometre::setCouleur (Couleur const& color) {
- couleur = color;
- QString stringCouleur;
- if (couleur == Blanc)
- stringCouleur = "white";
- else
- stringCouleur = "black";
- pion->load(QString (":/ressources/pawn_%1.svg").arg(stringCouleur));
- labelPion->setPixmap(*pion);
- }
- Couleur Chronometre::getCouleur() const {
- return couleur;
- }
- void Chronometre::refresh () {
- temps = temps.addMSecs(-INTERVAL);
- affichage ();
- if (temps <= QTime (0,0,0,0)) {
- emit fin(this);
- }
- }
- void Chronometre::start () {
- ecranTemps->setEnabled(true);
- timer->start ();
- }
- void Chronometre::stop () {
- ecranTemps->setDisabled(true);
- timer->stop();
- }
- void Chronometre::affichage () {
- QString chaineTemps = temps.toString("hh:mm:ss");
- ecranTemps->setText(chaineTemps);
- //qDebug() << "Taille : " << ecranTemps->width();
- }
- void Chronometre::reinit () {
- if (timer->isActive()) {
- timer->stop();
- }
- temps = msTempsDepart;
- affichage();
- }
- void Chronometre::basculer () {
- if (timer->isActive()) {
- stop();
- emit is_paused(this);
- }
- else {
- start ();
- }
- }
- void Chronometre::declareGagnant()
- {
- emit won(this);
- }
- void Chronometre::basculer(Chronometre & Chrono) {
- basculer();
- Chrono.basculer();
- }
- QString Chronometre::nomJoueur() const
- {
- return groupBox->title();
- }
- /**
- * @brief Ajouter du temps, prévu pour plus que des secondes
- */
- void Chronometre::addSecs(unsigned int secondes)
- {
- temps = temps.addSecs(secondes);
- }
|