00001 /************************************************************************** 00002 00003 Chess Clock 00004 00005 Copyright (c) Arto Hyvättinen 2010 00006 00007 This file is part of Chess Clock software. 00008 00009 Chess Clock is free software: you can redistribute it and/or modify 00010 it under the terms of the GNU General Public License as published by 00011 the Free Software Foundation, either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 Chess Clock is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU General Public License for more details. 00018 00019 00020 **************************************************************************/ 00021 00022 #include "hourglassclock.h" 00023 #include "../turninformation.h" 00024 00025 HourGlassClock::HourGlassClock(bool white, QWidget *parent) : 00026 ChessClockWidget(white, parent) 00027 { 00028 } 00029 00030 00031 int HourGlassClock::getTimeAvailable() 00032 { 00033 if( !another_) 00034 return timeAvailableBeforeTurn_; 00035 00036 if( currentTurn_ ) 00037 { 00038 return timeAvailableBeforeTurn_ - currentTurnPlayed(); 00039 } 00040 else 00041 { 00042 return timeAvailableBeforeTurn_ + another_->currentTurnPlayed(); 00043 } 00044 } 00045 00046 00047 TurnInformation* HourGlassClock::endTurn() 00048 { 00049 updateTimer_.stop(); 00050 status_ = NotRunning; 00051 00052 updateClock(); 00053 00054 timePlayedBeforeTurn_ = getTimePlayed(); 00055 00056 // Count available times of BOTH the clocks! 00057 setTimeAvailable( getTimeAvailable() ); 00058 another_->setTimeAvailable( another_->getTimeAvailable()); 00059 00060 // Close and return turn information 00061 currentTurn_->turnReady(timeAvailableBeforeTurn_ ); 00062 TurnInformation* information = currentTurn_; 00063 currentTurn_ = 0; 00064 00065 emit turnEnded(); 00066 return information; 00067 } 00068 00069 void HourGlassClock::updateClock() 00070 { 00071 ChessClock::updateClock(); 00072 another_->ChessClock::updateClock(); 00073 }