4f87423921748882a0fc298287c95b972a064197
[chessclock] / classes / clockswidget.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 CLOCKSWIDGET_H
23 #define CLOCKSWIDGET_H
24
25 #include <QWidget>
26 #include <QTime>
27
28 class QHBoxLayout;
29 class QVBoxLayout;
30 class QLabel;
31 class TurnInformation;
32
33 class ChessClock;
34
35 /*! Widget with two clocks
36
37     @author Arto Hyvättinen
38     @date 2010-08-14
39
40     Central widget of Chess Clock.
41     Needed to create new ClocksWidget to
42     every new game.
43
44   */
45 class ClocksWidget : public QWidget
46 {
47     Q_OBJECT
48 public:
49     ClocksWidget(ChessClock* white, ChessClock* black, QWidget *parent = 0);
50     ~ClocksWidget();
51     bool isPlayStarted()  { return (status_!=Welcome); }
52
53 protected:
54     void mouseReleaseEvent(QMouseEvent *event);
55
56
57 signals:
58    void TurnFinished(TurnInformation* turnInfo);
59    void ClickedWhenStopped();
60
61 public slots:
62    /*! Pause game */
63     void pause();
64     /*! End the game */
65     void stopPlay();
66
67 protected:
68     ChessClock* white_;
69     ChessClock* black_;
70
71     QLabel* pauseLabel_;
72     QLabel* welcomeLabel_;
73
74     enum GameStatus {
75         Stopped  /*! Not running */,
76         WhiteTurn,
77         BlackTurn,
78         WhitePause,
79         BlackPause,
80         Welcome
81         };
82
83     GameStatus status_;
84     QTime delayTimer_; /*! To avoid double clicks */
85
86     static int const CLICKDELAY = 500 ; /*! Click delay in msecs */
87
88
89
90 };
91
92 #endif // CLOCKSWIDGET_H