ed1352bb5b702ce75a6ac6ea9e1f5a6016278eb0
[chessclock] / classes / clockswidget.cpp
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 #include "clockswidget.h"
23 #include "chessclock.h"
24 #include "welcomescreenwidget.h"
25
26 #include <QLabel>
27 #include <QPixmap>
28 #include <QApplication>
29 #include <QHBoxLayout>
30 #include <QVBoxLayout>
31 #include <QFont>
32
33
34 ClocksWidget::ClocksWidget(QWidget *parent) :
35     QWidget(parent)
36 {
37     white_ = 0;
38     black_ = 0;
39     status_ = NoClocks;
40
41     // Make layout for clocks
42     QHBoxLayout* clockLayout_ = new QHBoxLayout;
43
44     // Pause information label
45     pauseLabel_ = new QLabel( tr("<font color=yellow>Paused. Touch to continue.</font>"));
46     pauseLabel_->setFont( QFont("Helvetica",25));
47     pauseLabel_->setAlignment( Qt::AlignCenter);
48     pauseLabel_->setVisible( false );
49
50     // Welcome label for first touch
51     welcomeLabel_ = new QLabel( tr("<font color=yellow>Welcome! Please touch to start game.<br>"
52                                    "Then touch to end turn.</font>"));
53     welcomeLabel_->setFont( QFont("Helvetica",25));
54     welcomeLabel_->setAlignment( Qt::AlignCenter);
55     welcomeLabel_->setVisible( false );
56
57     // Welcome screen if no clocks set
58     welcomeScreen_ = new WelcomeScreenWidget(this);
59
60     // Put all in layout
61     QVBoxLayout* mainLayout = new QVBoxLayout;
62     mainLayout->addLayout(clockLayout_);
63     mainLayout->addWidget(pauseLabel_);
64     mainLayout->addWidget(welcomeLabel_);
65     mainLayout->addWidget(welcomeScreen_);
66
67     setLayout( mainLayout);
68
69 }
70
71
72
73 void ClocksWidget::setClocks(ChessClock *white, ChessClock *black)
74 {
75     // Remove old clocks
76     if( white_ )
77     {
78         clockLayout_->removeWidget( white_ );
79         delete white_;
80     }
81     if( black_ )
82     {
83         clockLayout_->removeWidget( black_ );
84         delete black_;
85     }
86
87     // Set up new ones
88     white_ = white;
89     black_ = black;
90
91     clockLayout_->addWidget(white_);
92     clockLayout_->addWidget( black_ );
93
94     // First paint
95     white_->repaintClock();
96     black_->repaintClock();
97
98     // Welcome status for first touch
99     welcomeLabel_->setVisible(true);
100     status_ = Welcome;
101
102
103 }
104
105 int const ClocksWidget::CLICKDELAY;