Seems needed to create new ClocksWidget for each game.
chessclockwindow.cpp \
classes/turninformation.cpp \
classes/chessclock.cpp \
- classes/chessclockwidget.cpp
+ classes/chessclockwidget.cpp \
+ classes/clockswidget.cpp \
+ classes/welcomescreenwidget.cpp
HEADERS += chessclockwindow.h \
classes/turninformation.h \
classes/chessclock.h \
- classes/chessclockwidget.h
+ classes/chessclockwidget.h \
+ classes/clockswidget.h \
+ classes/welcomescreenwidget.h
CONFIG += mobility
MOBILITY =
<file>pic/white_blue.png</file>
<file>pic/white_gray.png</file>
<file>pic/chessclock.png</file>
+ <file>pic/logo.png</file>
</qresource>
</RCC>
#include "chessclockwindow.h"
+#include "classes/clockswidget.h"
#include "classes/chessclockwidget.h"
#include <QIcon>
setWindowIcon( QIcon(":/rc/pic/chessclock.png"));
setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) );
- ChessClockWidget* widget = new ChessClockWidget(true, this);
- setCentralWidget(widget);
- widget->startTurn();
+ ChessClockWidget* white = new ChessClockWidget(true, this);
+ white->setGreenTime(5000);
+ ChessClockWidget* black = new ChessClockWidget(false, this);
+ white->startTurn();
+ black->repaintClock();
+
+ clocks_ = new ClocksWidget( this );
+ setCentralWidget( clocks_ );
+ clocks_->setClocks(white, black);
}
#include <QtGui/QMainWindow>
+class ClocksWidget;
+
class ChessClockWindow : public QMainWindow
{
Q_OBJECT
public:
ChessClockWindow(QWidget *parent = 0);
~ChessClockWindow();
+
+
+protected:
+ ClocksWidget* clocks_;
};
#endif // CHESSCLOCKWINDOW_H
TurnInformation* ChessClock::endTurn()
{
- status_ = NotRunning;
updateTimer_.stop();
- // Update turn time
- currentTurn_->addTime( clockTime_.restart());
// Count time played
timePlayedBeforeTurn_ = getTimePlayed();
// Count time available
+ // This update current turn
timeAvailableBeforeTurn_ = getTimeAvailable();
+
+ status_ = NotRunning;
updateClock();
// Close and return turn information
if( currentTurn_)
{
// Update turn time
- currentTurn_->addTime( clockTime_.restart());
- return timeAvailableBeforeTurn_-currentTurn_->getDuration();
+ return timeAvailableBeforeTurn_-currentTurnPlayed();
}
else
return timeAvailableBeforeTurn_;
}
-int ChessClock::getTimePlayed() const
+int ChessClock::getTimePlayed()
{
// Count time played time
if( currentTurn_ )
- return timePlayedBeforeTurn_ + currentTurn_->getDuration();
+ return timePlayedBeforeTurn_ + currentTurnPlayed();
else
return timePlayedBeforeTurn_;
}
timeAvailableBeforeTurn_ += msecs;
}
+int ChessClock::currentTurnPlayed()
+{
+ if( currentTurn_ )
+ {
+ // Update current time
+ if( status_ == Running )
+ currentTurn_->addTime( clockTime_.restart());
+
+ // Return current time
+ return currentTurn_->getDuration();
+ }
+ else
+ // No current turn!
+ return 0;
+}
+
void ChessClock::updateClock()
{
// Check loser
/*! Get total time played
@return Time played in msecs */
- virtual int getTimePlayed() const;
+ virtual int getTimePlayed();
/*! Set time available
@param msecs Time to add in msecs */
void addTime(int msecs);
+ /*! Get time played current turn.
+ @return Time in msecs */
+ int currentTurnPlayed();
+
signals:
void timeOutLoser();
ChessClockWidget::ChessClockWidget(bool white, QWidget *parent) :
ChessClock(white, parent)
{
+ greenTime_ = 0;
+
mainLayout = new QVBoxLayout;
initPictures();
}
+void ChessClockWidget::setGreenTime(int msecs)
+{
+ greenTime_ = msecs;
+}
+
void ChessClockWidget::initPictures()
{
// Load pictures from resources.
timeUsedLabel_ = new QLabel;
timeAverageLabel_ = new QLabel;
turnLabel_=new QLabel;
+ turnTimeLabel_=new QLabel;
timeUsedLabel_->setFont(normalFont);
timeAverageLabel_->setFont(normalFont);
turnLabel_->setFont(normalFont);
+ QFont turnTimeFont("Helvetica",36,QFont::Bold);
+ turnTimeLabel_->setFont(turnTimeFont);
+
loserLabel_ = new QLabel;
loserLabel_->setPixmap(picLoser_);
loserLabel_->setVisible(false);
details->addWidget(timeUsedLabel_);
details->addWidget(timeAverageLabel_);
details->addWidget(turnLabel_);
+ details->addWidget(turnTimeLabel_);
QHBoxLayout* topLayout = new QHBoxLayout();
if( isWhite() )
leftLabel_ = new QLabel("0.00.00");
leftLabel_->setFont(bigfont);
// Black player: right alignment
- if( isWhite() )
+ if( !isWhite() )
leftLabel_->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
mainLayout->addWidget(leftLabel_);
}
turnLabel_->setText( tr("Turn %1").arg(getTurn()));
+ // Current turn played
+ // Extra time of this turn is shown in green.
+ if( currentTurnPlayed() < greenTime_ )
+ turnTimeLabel_->setText( QString("<font color=green> %1 </font>") .arg(timeString( currentTurnPlayed()) ) );
+ else
+ turnTimeLabel_->setText( timeString( currentTurnPlayed() ) );
+
// Loser flag
loserLabel_->setVisible( isLoser());
Q_OBJECT
public:
ChessClockWidget(bool white, QWidget *parent = 0);
+ /*! Set time begin of turn shown green.
+
+ Extra time of turn is shown green.
+ @param msecs Green time in msecs
+ */
+ void setGreenTime(int msecs);
signals:
QLabel* timeUsedLabel_;
QLabel* timeAverageLabel_;
QLabel* turnLabel_;
+ QLabel* turnTimeLabel_;
QLabel* loserLabel_;
QLabel* leftLabel_;
QVBoxLayout* mainLayout;
+ int greenTime_; /*! Green time in begin of turn */
+
};
--- /dev/null
+ /**************************************************************************
+
+ Chess Clock
+
+ Copyright (c) Arto Hyvättinen 2010
+
+ This file is part of Chess Clock software.
+
+ Chess Clock is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Chess Clock is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+
+**************************************************************************/
+
+#include "clockswidget.h"
+#include "chessclock.h"
+#include "welcomescreenwidget.h"
+
+#include <QLabel>
+#include <QPixmap>
+#include <QApplication>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QFont>
+
+
+ClocksWidget::ClocksWidget(QWidget *parent) :
+ QWidget(parent)
+{
+ white_ = 0;
+ black_ = 0;
+ status_ = NoClocks;
+
+ // Make layout for clocks
+ QHBoxLayout* clockLayout_ = new QHBoxLayout;
+
+ // Pause information label
+ pauseLabel_ = new QLabel( tr("<font color=yellow>Paused. Touch to continue.</font>"));
+ pauseLabel_->setFont( QFont("Helvetica",25));
+ pauseLabel_->setAlignment( Qt::AlignCenter);
+ pauseLabel_->setVisible( false );
+
+ // Welcome label for first touch
+ welcomeLabel_ = new QLabel( tr("<font color=yellow>Welcome! Please touch to start game.<br>"
+ "Then touch to end turn.</font>"));
+ welcomeLabel_->setFont( QFont("Helvetica",25));
+ welcomeLabel_->setAlignment( Qt::AlignCenter);
+ welcomeLabel_->setVisible( false );
+
+ // Welcome screen if no clocks set
+ welcomeScreen_ = new WelcomeScreenWidget(this);
+
+ // Put all in layout
+ QVBoxLayout* mainLayout = new QVBoxLayout;
+ mainLayout->addLayout(clockLayout_);
+ mainLayout->addWidget(pauseLabel_);
+ mainLayout->addWidget(welcomeLabel_);
+ mainLayout->addWidget(welcomeScreen_);
+
+ setLayout( mainLayout);
+
+}
+
+
+
+void ClocksWidget::setClocks(ChessClock *white, ChessClock *black)
+{
+ // Remove old clocks
+ if( white_ )
+ {
+ clockLayout_->removeWidget( white_ );
+ delete white_;
+ }
+ if( black_ )
+ {
+ clockLayout_->removeWidget( black_ );
+ delete black_;
+ }
+
+ // Set up new ones
+ white_ = white;
+ black_ = black;
+
+ clockLayout_->addWidget(white_);
+ clockLayout_->addWidget( black_ );
+
+ // First paint
+ white_->repaintClock();
+ black_->repaintClock();
+
+ // Welcome status for first touch
+ welcomeLabel_->setVisible(true);
+ status_ = Welcome;
+
+
+}
+
+int const ClocksWidget::CLICKDELAY;
--- /dev/null
+ /**************************************************************************
+
+ Chess Clock
+
+ Copyright (c) Arto Hyvättinen 2010
+
+ This file is part of Chess Clock software.
+
+ Chess Clock is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Chess Clock is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+
+**************************************************************************/
+
+#ifndef CLOCKSWIDGET_H
+#define CLOCKSWIDGET_H
+
+#include <QWidget>
+#include <QTime>
+
+class QHBoxLayout;
+class QVBoxLayout;
+class QLabel;
+class WelcomeScreenWidget;
+
+class ChessClock;
+
+/*! Widget with two clocks
+
+ @author Arto Hyvättinen
+ @date 2010-08-14
+
+ Central widget of Chess Clock
+
+ */
+class ClocksWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ ClocksWidget(QWidget *parent = 0);
+
+ /*! Set clocks and paint them.
+
+ */
+ void setClocks(ChessClock* white, ChessClock* black);
+
+
+protected:
+// void mouseReleaseEvent(QMouseEvent *event);
+
+ void initEmptyScreen();
+
+signals:
+ void setupTouch();
+
+public slots:
+
+protected:
+ ChessClock* white_;
+ ChessClock* black_;
+
+ QHBoxLayout* clockLayout_;
+
+ QLabel* pauseLabel_;
+ QLabel* welcomeLabel_;
+ WelcomeScreenWidget* welcomeScreen_;
+
+ enum GameStatus {
+ Stopped /*! Not running */,
+ WhiteTurn,
+ BlackTurn,
+ WhitePause,
+ BlackPause,
+ NoClocks, /*! Clocks not set ! */
+ Welcome
+ };
+
+ GameStatus status_;
+ QTime delayTimer_; /*! To avoid double clicks */
+
+ static int const CLICKDELAY = 500 ; /*! Click delay in msecs */
+
+
+
+};
+
+#endif // CLOCKSWIDGET_H
--- /dev/null
+ /**************************************************************************
+
+ Chess Clock
+
+ Copyright (c) Arto Hyvättinen 2010
+
+ This file is part of Chess Clock software.
+
+ Chess Clock is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Chess Clock is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+
+**************************************************************************/
+
+#include <QLabel>
+#include <QPixmap>
+#include <QApplication>
+#include <QHBoxLayout>
+
+#include "welcomescreenwidget.h"
+
+WelcomeScreenWidget::WelcomeScreenWidget(QWidget *parent) :
+ QWidget(parent)
+{
+ QLabel* logoLabel = new QLabel;
+ logoLabel->setPixmap( QPixmap(":/rc/pic/logo.png"));
+ QLabel* introLabel = new QLabel(
+ tr("<h1>Chess Clock</h1><br>"
+ "Version %1<br>"
+ "© Arto Hyvättinen 2010<br>"
+ "Chess Clock is free software in terms of GNU General Public Licence v3"
+ "<p>Welcome to Chess Clock!<br>"
+ "Please touch to set up game clock.</p>"
+ ).arg(qApp->applicationVersion())
+
+ );
+ introLabel->setWordWrap(true);
+ QHBoxLayout* layout = new QHBoxLayout;
+ layout->addWidget(logoLabel);
+ layout->addWidget(introLabel);
+ setLayout( layout );
+}
--- /dev/null
+ /**************************************************************************
+
+ Chess Clock
+
+ Copyright (c) Arto Hyvättinen 2010
+
+ This file is part of Chess Clock software.
+
+ Chess Clock is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Chess Clock is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+
+**************************************************************************/
+
+#ifndef WELCOMESCREENWIDGET_H
+#define WELCOMESCREENWIDGET_H
+
+#include <QWidget>
+
+/*! Welcome screen
+
+ @author Arto Hyvättinen
+ @date 2010-08-14
+
+ */
+
+class WelcomeScreenWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ WelcomeScreenWidget(QWidget *parent = 0);
+
+signals:
+
+public slots:
+
+};
+
+#endif // WELCOMESCREENWIDGET_H