ChessClock class
[chessclock] / classes / chessclock.h
1  /**************************************************************************
2
3     Chess Clock
4
5     Copyright (c) Arto Hyvättinen 2010
6
7     This file is part of Chess Clock software.
8
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.
13
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.
18
19
20 **************************************************************************/
21
22 #ifndef CHESSCLOCK_H
23 #define CHESSCLOCK_H
24
25 #include <QWidget>
26 #include <QTime>
27 #include <QTimer>
28
29 class TurnInformation;
30
31
32 /*! Clock of a individual player
33
34   @author Arto Hyvättinen
35   @date 2010-08-13
36
37   Base class of chess clock.
38
39   */
40 class ChessClock : public QWidget
41 {
42     Q_OBJECT
43 public:
44     ChessClock(bool white, QWidget *parent = 0);
45
46 public:
47     enum RunningStatus {
48         NotRunning /*! Not turn  */ = 0,
49         Running /*! Turn running */ = 1,
50         Paused /*! Turn paused */ = 2
51     };
52
53     bool isLoser() const  { return loser_; }
54     int getTurn() const  { return turn_; }
55
56
57     /*! Start new turn */
58     virtual void startTurn();
59
60     /*! End this turn.
61
62       Player has done his move.
63       @return Locked turn information */
64     virtual TurnInformation* endTurn();
65
66     /*! Pause clock */
67     virtual void pauseTurn();
68
69     /*! Continue paused game */
70     virtual void continueTurn();
71
72     /*! Set another chess clock for connecting
73       @param another Clock of opposite player */
74     void setAnother( ChessClock* another);
75
76     /*! Get total time available
77
78       Time does't contain delays.
79
80       @return Time available in msecs */
81     virtual int getTimeAvailable();
82
83 signals:
84     void timeOut();
85
86 public slots:    
87
88     /*! Refresh clock information */
89     virtual void repaintClock() = 0;
90
91
92 protected:
93     ChessClock* another_; /*! Another player's clock */
94
95     bool loser_;        /*! Is player losed because of timeout */
96     int turn_;          /*! Current turn */
97     RunningStatus status_;
98     TurnInformation* currentTurn_;
99
100     int timePlayed_;    /*! Time played in this game */
101     int timeAvailableBeforeTurn_; /*! Time available for play BEFORE this turn!*/
102
103     bool isWhite_;      /*! True if white player */
104
105     QTime clockTime_;
106     QTimer updateTimer_;
107
108     static const int UPDATEINTERVAL = 1000; /** Clock updating interval in msecs */
109
110 };
111
112 #endif // CHESSCLOCK_H