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