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(); 00091 00095 void setTimeAvailable(int msecs); 00096 00103 void addTime(int msecs); 00104 00107 int currentTurnPlayed(); 00108 00109 00110 signals: 00111 void timeOutLoser(); 00112 void turnEnded(); 00118 void dontEatBattery(); 00119 00120 public slots: 00121 00123 virtual void repaintClock() = 0; 00124 00126 virtual void updateClock(); 00127 00128 protected: 00129 ChessClock* another_; 00131 bool loser_; 00132 int turn_; 00133 RunningStatus status_; 00134 TurnInformation* currentTurn_; 00135 bool dontEatBatteryEmitted_; 00136 00137 int timePlayedBeforeTurn_; 00138 int timeAvailableBeforeTurn_; 00140 bool isWhite_; 00142 QTime clockTime_; 00143 QTimer updateTimer_; 00144 00145 static const int UPDATEINTERVAL = 1000; 00146 static const int DONTEATBATTERYTIME = 30 * 60 * 1000; 00147 }; 00148 00149 #endif // CHESSCLOCK_H