Times are now passed from dialog to ClocksWidget
[chessclock] / classes / wrappedclockswidget.cpp
1 /**************************************************************************
2
3    Chess Clock
4
5    This file is part of Chess Clock software.
6
7    (This file) Copyright (c) Heli Hyvättinen 2011
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
23 #include "wrappedclockswidget.h"
24 #include "classes/timecontrol/hourglassclock.h"
25 #include "classes/timecontrol/delayclock.h"
26 #include <QDebug>
27
28
29 WrappedClocksWidget::WrappedClocksWidget(QObject *parent) :
30     QGraphicsProxyWidget()
31 {
32     pClocksWidget_ = NULL;
33     pWhiteClock_ = NULL;
34     pBlackClock_ = NULL;
35 }
36
37 void WrappedClocksWidget::startGame(QString timeControl, int whiteInitialTime, int whiteAdditionalTime, int whiteTurnsPerAddition, int blackInitialTime, int blackAdditionalTime, int blackTurnsPerAddition)
38 {
39
40     qDebug() << whiteInitialTime << "white initial time";
41
42     deleteOldWidgets();
43
44     pWhiteClock_ = new DelayClock (true,whiteAdditionalTime);
45     pWhiteClock_->setTimeAvailable(whiteInitialTime);
46
47     pBlackClock_ = new DelayClock (false,blackAdditionalTime);
48     pBlackClock_->setTimeAvailable(blackInitialTime);
49
50     pClocksWidget_ = new ClocksWidget(pWhiteClock_, pBlackClock_);
51
52
53     pClocksWidget_->setAttribute(Qt::WA_NoSystemBackground);
54     setWidget(pClocksWidget_);
55
56
57 }
58
59  WrappedClocksWidget::~WrappedClocksWidget()
60 {
61      deleteOldWidgets();
62 }
63
64 bool WrappedClocksWidget::isPlayStarted()
65 {
66     if (!pClocksWidget_)
67         return false;
68
69     return  pClocksWidget_->isPlayStarted();
70 }
71
72 void WrappedClocksWidget::deleteOldWidgets()
73 {
74     if (pClocksWidget_)
75     {
76         delete pClocksWidget_;
77         pClocksWidget_ = NULL;
78     }
79
80     if (pWhiteClock_)
81     {
82         delete pWhiteClock_;
83         pWhiteClock_ = NULL;
84     }
85
86     if (pBlackClock_)
87     {
88         delete pBlackClock_;
89         pBlackClock_ = NULL;
90     }
91 }
92
93 void WrappedClocksWidget::pause()
94 {
95     if (pClocksWidget_)
96         pClocksWidget_->pause();
97 }
98
99 void WrappedClocksWidget::stopPlay()
100 {
101     if (pClocksWidget_)
102         pClocksWidget_->stopPlay();
103 }
104
105 void WrappedClocksWidget::saveScreen()
106 {
107     if (pClocksWidget_)
108         pClocksWidget_->saveScreen();
109 }
110