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 #ifndef CHESSCLOCK_H 00023 #define CHESSCLOCK_H 00024 00025 #include <QWidget> 00026 #include <QTime> 00027 #include <QTimer> 00028 00029 class TurnInformation; 00030 00031 00043 class ChessClock : public QWidget 00044 { 00045 Q_OBJECT 00046 public: 00047 ChessClock(bool white, QWidget *parent = 0); 00048 00049 public: 00050 enum RunningStatus { 00051 NotRunning = 0, 00052 Running = 1, 00053 Paused = 2 00054 }; 00055 00056 bool isLoser() const { return loser_; } 00057 int getTurn() const { return turn_; } 00058 bool isWhite() const { return isWhite_; } 00059 RunningStatus getStatus() const { return status_ ; } 00060 00061 00063 virtual void startTurn(); 00064 00069 virtual TurnInformation* endTurn(); 00070 00072 virtual void pauseTurn(); 00073 00075 virtual void continueTurn(); 00076 00079 void setAnother( ChessClock* another); 00080 00086 virtual int getTimeAvailable(); 00087 00090 virtual int getTimePlayed() const; 00091 00092 00093 signals: 00094 void timeOutLoser(); 00095 00096 public slots: 00097 00099 virtual void repaintClock() = 0; 00100 00102 virtual void updateClock(); 00103 00104 private: 00105 ChessClock* another_; 00107 bool loser_; 00108 int turn_; 00109 RunningStatus status_; 00110 TurnInformation* currentTurn_; 00111 00112 int timePlayedBeforeTurn_; 00113 int timeAvailableBeforeTurn_; 00115 bool isWhite_; 00117 QTime clockTime_; 00118 QTimer updateTimer_; 00119 00120 static const int UPDATEINTERVAL = 1000; 00122 }; 00123 00124 #endif // CHESSCLOCK_H