1 /**************************************************************************
5 Copyright (c) Arto Hyvättinen 2010
7 This file is part of Chess Clock software.
9 Chess Clock is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Chess Clock is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
20 **************************************************************************/
22 #include "chessclock.h"
24 #include "turninformation.h"
26 const int ChessClock::UPDATEINTERVAL;
28 ChessClock::ChessClock(bool white, QWidget *parent) :
37 // Set clock timer calculating played time
41 updateTimer_.setInterval( UPDATEINTERVAL );
42 connect( &updateTimer_, SIGNAL(timeout),this,SLOT(updateClock()));
45 void ChessClock::startTurn()
49 // Turn information for this new turn
50 currentTurn_ = new TurnInformation(turn_, isWhite_);
58 void ChessClock::pauseTurn()
61 currentTurn_->addTime( clockTime_.restart() );
66 void ChessClock::continueTurn()
68 // Continue paused game
69 // Add pause duration to information object
70 currentTurn_->addPause( clockTime_.restart() );
76 TurnInformation* ChessClock::endTurn()
80 currentTurn_->addTime( clockTime_.restart());
81 // Count time available
82 timeAvailableBeforeTurn_ = getTimeAvailable();
85 // Close and return turn information
86 currentTurn_->turnReady(timeAvailableBeforeTurn_ );
87 TurnInformation* information = currentTurn_;
92 void ChessClock::setAnother(ChessClock *another)
97 int ChessClock::getTimeAvailable()
99 // Most simple - will be overwritten in more complex time controls:
100 // subtract duration time!
102 return timeAvailableBeforeTurn_-currentTurn_->getDuration();
104 return timeAvailableBeforeTurn_;