Pause button hidden when game paused
[chessclock] / classes / clockswidget.h
1  /**************************************************************************
2
3     Chess Clock
4
5     Copyright (c) Arto Hyvättinen 2010
6     Changes for porting to Harmattan(c) Heli Hyvättinen 2011
7
8     This file is part of Chess Clock software.
9
10     Chess Clock is free software: you can redistribute it and/or modify
11     it under the terms of the GNU General Public License as published by
12     the Free Software Foundation, either version 3 of the License, or
13     (at your option) any later version.
14
15     Chess Clock is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19
20
21 **************************************************************************/
22
23 #ifndef CLOCKSWIDGET_H
24 #define CLOCKSWIDGET_H
25
26 #include <QWidget>
27 #include <QTime>
28
29 class QHBoxLayout;
30 class QVBoxLayout;
31 class QLabel;
32 class TurnInformation;
33 class QToolButton;
34 class ScreenLitKeeper;
35
36 class ChessClock;
37
38 /*! Widget with two clocks
39
40     @author Arto Hyvättinen (& Heli Hyvättinen)
41     @date 2011-10-07
42
43
44
45     Central widget of Chess Clock.
46     Needed to create new ClocksWidget to
47     every new game.
48
49   */
50 class ClocksWidget : public QWidget
51 {
52     Q_OBJECT
53 public:
54     ClocksWidget(ChessClock* white, ChessClock* black, QWidget *parent = 0);
55     ~ClocksWidget();
56     bool isPlayStarted()  { return (status_!=Welcome); }
57
58 protected:
59     //In Harmattan (PageStackWindow) no mouseReleaseEvents are received. Changed to use mousePressEvent instead
60     void mousePressEvent(QMouseEvent *event);
61     bool eventFilter(QObject *obj, QEvent *event);  //same with eventFilter
62
63
64 signals:
65    void TurnFinished(TurnInformation* turnInfo);
66    void ClickedWhenStopped();
67    void unPaused(); //For Harmattan, to inform QML
68
69 public slots:
70    /*! Pause game */
71     void pause();
72     /*! End the game */
73     void stopPlay();
74     /*! Not to keep screen lit */
75     void saveScreen();
76
77 protected:
78     ChessClock* white_;
79     ChessClock* black_;
80
81     QLabel* pauseLabel_;
82     QLabel* welcomeLabel_;
83     QToolButton* pauseButton_;
84     ScreenLitKeeper* keeper_;
85
86     enum GameStatus {
87         Stopped  /*! Not running */,
88         WhiteTurn,
89         BlackTurn,
90         WhitePause,
91         BlackPause,
92         Welcome
93         };
94
95     GameStatus status_;
96     QTime delayTimer_; /*! To avoid double clicks */
97
98     int recentX;
99     int recentY;
100
101     static int const CLICKDELAY = 1500 ; /*! Click delay in msecs */
102
103
104
105 };
106
107 #endif // CLOCKSWIDGET_H