Attempt to wrrap ClocksWidget for use in QML
[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
25
26 WrappedClocksWidget::WrappedClocksWidget(QObject *parent) :
27     QGraphicsProxyWidget(parent)
28 {
29     pClocksWidget_ = NULL;
30     pWhiteClock_ = NULL;
31     pBlackClock_ = NULL;
32 }
33
34 WrappedClocksWidget::startGame(QString timeControl, int whiteInitialTime, int whiteAdditionalTime, int whiteTurnsPerAddition, int blackInitialTime, int blackAdditionalTime, int blackTurnsPerAddition)
35 {
36
37     deleteOldWidgets();
38
39     pWhiteClock_ = new ChessClockWidget(true);
40     pWhiteClock_->setTimeAvailable(whiteInitialTime);
41
42     pBlackClock_ = new ChessClockWidget(false);
43     pBlackClock_->setTimeAvailable(blackInitialTime);
44
45     pClocksWidget_ = new ClocksWidget(pWhiteClock_, pBlackClock_);
46
47
48     pClocksWidget_->setAttribute(Qt::WA_NoSystemBackground);
49     setWidget(pClocksWidget_);
50
51
52 }
53
54 WrappedClocksWidget::~WrappedClocksWidget()
55 {
56     deleteOldWidgets;
57 }
58
59 WrappedClocksWidget::isPlayStarted()
60 {
61     if (!pClocksWidget_)
62         return false;
63
64     return  pClocksWidget_->isPlayStarted();
65 }
66
67 WrappedClocksWidget::deleteOldWidgets()
68 {
69     if (pClocksWidget_)
70     {
71         delete pClocksWidget_;
72         pClocksWidget_ = NULL;
73     }
74
75     if (pWhiteClock_)
76     {
77         delete pWhiteClock_;
78         pWhiteClock_ = NULL;
79     }
80
81     if (pBlackClock_)
82     {
83         delete pBlackClock_;
84         pBlackClock_ = NULL;
85     }
86 }
87