1 /**************************************************************************
5 This file is part of Chess Clock software.
7 (This file) Copyright (c) Heli Hyvättinen 2011
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.
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.
20 **************************************************************************/
23 #include "wrappedclockswidget.h"
24 #include "classes/timecontrol/hourglassclock.h"
25 #include "classes/timecontrol/delayclock.h"
26 #include "classes/timecontrol/delayafterclock.h"
27 #include "classes/timecontrol/fischerclock.h"
28 #include "classes/timecontrol/fischerafterclock.h"
29 #include "classes/chessclockwidget.h"
33 WrappedClocksWidget::WrappedClocksWidget(QObject *parent) :
34 QGraphicsProxyWidget()
36 pClocksWidget_ = NULL;
41 void WrappedClocksWidget::startGame(TimeControlType timeControl, int whiteInitialTime, int whiteAdditionalTime, int whiteTurnsPerAddition, int blackInitialTime, int blackAdditionalTime, int blackTurnsPerAddition)
51 pWhiteClock_ = new ChessClockWidget (true);
52 pWhiteClock_->setTimeAvailable(whiteInitialTime);
54 pBlackClock_ = new ChessClockWidget (false);
55 pBlackClock_->setTimeAvailable(blackInitialTime);
61 pWhiteClock_ = new FischerClock (true,whiteAdditionalTime,whiteTurnsPerAddition);
62 pWhiteClock_->setTimeAvailable(whiteInitialTime);
64 pBlackClock_ = new FischerClock (false,blackAdditionalTime,blackTurnsPerAddition);
65 pBlackClock_->setTimeAvailable(blackInitialTime);
71 pWhiteClock_ = new FischerAfterClock (true,whiteAdditionalTime,whiteTurnsPerAddition);
72 pWhiteClock_->setTimeAvailable(whiteInitialTime);
74 pBlackClock_ = new FischerAfterClock (false,blackAdditionalTime,blackTurnsPerAddition);
75 pBlackClock_->setTimeAvailable(blackInitialTime);
81 pWhiteClock_ = new DelayClock (true,whiteAdditionalTime);
82 pWhiteClock_->setTimeAvailable(whiteInitialTime);
84 pBlackClock_ = new DelayClock (false,blackAdditionalTime);
85 pBlackClock_->setTimeAvailable(blackInitialTime);
91 pWhiteClock_ = new DelayAfterClock (true,whiteAdditionalTime);
92 pWhiteClock_->setTimeAvailable(whiteInitialTime);
94 pBlackClock_ = new DelayAfterClock (false,blackAdditionalTime);
95 pBlackClock_->setTimeAvailable(blackInitialTime);
101 pWhiteClock_ = new HourGlassClock (true);
102 pWhiteClock_->setTimeAvailable(whiteInitialTime);
104 pBlackClock_ = new HourGlassClock (false);
105 pBlackClock_->setTimeAvailable(blackInitialTime);
112 //QML has no type safety for enums (using int for real!)
113 //So there is possibility of getting invalid values if there is a bug in QML files
115 //Defaulting to normal clock
118 qDebug() << "Invalid time control type. Defaulting to Normal Clock.";
120 pWhiteClock_ = new ChessClockWidget (true);
121 pWhiteClock_->setTimeAvailable(whiteInitialTime);
123 pBlackClock_ = new ChessClockWidget (false);
124 pBlackClock_->setTimeAvailable(blackInitialTime);
132 pClocksWidget_ = new ClocksWidget(pWhiteClock_, pBlackClock_);
134 connect(pClocksWidget_,SIGNAL(unPaused()),this,(SIGNAL(unPaused())));
136 pClocksWidget_->setAttribute(Qt::WA_NoSystemBackground);
137 setWidget(pClocksWidget_);
141 WrappedClocksWidget::~WrappedClocksWidget()
146 bool WrappedClocksWidget::isPlayStarted()
151 return pClocksWidget_->isPlayStarted();
154 void WrappedClocksWidget::deleteOldWidgets()
160 pClocksWidget_->deleteLater();
161 pClocksWidget_ = NULL;
166 pWhiteClock_->deleteLater();
172 pBlackClock_->deleteLater();
177 void WrappedClocksWidget::pause()
180 pClocksWidget_->pause();
183 void WrappedClocksWidget::stopPlay()
186 pClocksWidget_->stopPlay();
189 void WrappedClocksWidget::saveScreen()
192 pClocksWidget_->saveScreen();