1 /**************************************************************************
5 Copyright (c) Arto Hyvättinen 2010
7 This file is part of Chess Clock software.
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 **************************************************************************/
22 #include "clockswidget.h"
23 #include "chessclock.h"
27 #include <QApplication>
28 #include <QHBoxLayout>
29 #include <QVBoxLayout>
33 ClocksWidget::ClocksWidget(ChessClock *white, ChessClock *black, QWidget *parent):
41 // Make layout for clocks
42 QHBoxLayout* clockLayout = new QHBoxLayout;
43 clockLayout->addWidget(white_ );
44 clockLayout->addWidget( black_ );
46 // Pause information label
47 pauseLabel_ = new QLabel( tr("<font color=yellow>Paused. Touch to continue.</font>"));
48 pauseLabel_->setFont( QFont("Helvetica",25));
49 pauseLabel_->setAlignment( Qt::AlignCenter);
50 pauseLabel_->setVisible( false );
52 // Welcome label for first touch
53 welcomeLabel_ = new QLabel( tr("<font color=green>Welcome! Please touch to start game.<br>"
54 "Then touch to end turn.</font>"));
55 welcomeLabel_->setFont( QFont("Helvetica",25));
56 welcomeLabel_->setAlignment( Qt::AlignCenter);
57 welcomeLabel_->setVisible( true ); // Show welcome message
60 QVBoxLayout* mainLayout = new QVBoxLayout;
61 mainLayout->addLayout(clockLayout);
62 mainLayout->addWidget(pauseLabel_);
63 mainLayout->addWidget(welcomeLabel_);
65 setLayout( mainLayout);
69 white_->repaintClock();
70 black_->repaintClock();
73 white_->setAnother(black_);
74 black_->setAnother(white_);
76 delayTimer_.start(); // Initial start
79 void ClocksWidget::pause()
81 if(status_ == WhiteTurn)
85 pauseLabel_->setVisible(true);
87 else if( status_ == BlackTurn)
91 pauseLabel_->setVisible(true);
96 void ClocksWidget::mouseReleaseEvent(QMouseEvent *event)
98 if( delayTimer_.elapsed() > CLICKDELAY ) // To avoid double clicks
104 welcomeLabel_->setVisible(false);
109 // White turn finished, then black
110 emit TurnFinished( white_->endTurn());
115 // Black finished, then white
116 emit TurnFinished( black_->endTurn());
126 int const ClocksWidget::CLICKDELAY;