From cfcfb018dce39cd48eda0f601aa5134632a50484 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arto=20Hyv=C3=A4ttinen?= Date: Mon, 16 Aug 2010 20:09:56 +0300 Subject: [PATCH] ALPHA VERSION Time controls ready to use. --- chessclock.pro | 20 ++++++- chessclockwindow.cpp | 9 +++ classes/chessclock.h | 2 +- classes/chessclockwidget.cpp | 2 +- classes/startwidget.cpp | 5 +- classes/timecontrol/delayafterclock.cpp | 42 +++++++++++++ classes/timecontrol/delayafterclock.h | 50 ++++++++++++++++ classes/timecontrol/delayaftertimecontrol.cpp | 63 +++++++++++++++++++ classes/timecontrol/delayaftertimecontrol.h | 37 ++++++++++++ classes/timecontrol/delayclock.cpp | 44 ++++++++++++++ classes/timecontrol/delayclock.h | 51 ++++++++++++++++ classes/timecontrol/delaytimecontrol.cpp | 63 +++++++++++++++++++ classes/timecontrol/delaytimecontrol.h | 37 ++++++++++++ classes/timecontrol/fischerafterclock.cpp | 38 ++++++++++++ classes/timecontrol/fischerafterclock.h | 52 ++++++++++++++++ classes/timecontrol/fischeraftertimecontrol.cpp | 56 +++++++++++++++++ classes/timecontrol/fischeraftertimecontrol.h | 39 ++++++++++++ classes/timecontrol/hourglassclock.cpp | 73 +++++++++++++++++++++++ classes/timecontrol/hourglassclock.h | 42 +++++++++++++ classes/timecontrol/hourglasstimecontrol.cpp | 65 ++++++++++++++++++++ classes/timecontrol/hourglasstimecontrol.h | 37 ++++++++++++ main.cpp | 3 +- 22 files changed, 821 insertions(+), 9 deletions(-) create mode 100644 classes/timecontrol/delayafterclock.cpp create mode 100644 classes/timecontrol/delayafterclock.h create mode 100644 classes/timecontrol/delayaftertimecontrol.cpp create mode 100644 classes/timecontrol/delayaftertimecontrol.h create mode 100644 classes/timecontrol/delayclock.cpp create mode 100644 classes/timecontrol/delayclock.h create mode 100644 classes/timecontrol/delaytimecontrol.cpp create mode 100644 classes/timecontrol/delaytimecontrol.h create mode 100644 classes/timecontrol/fischerafterclock.cpp create mode 100644 classes/timecontrol/fischerafterclock.h create mode 100644 classes/timecontrol/fischeraftertimecontrol.cpp create mode 100644 classes/timecontrol/fischeraftertimecontrol.h create mode 100644 classes/timecontrol/hourglassclock.cpp create mode 100644 classes/timecontrol/hourglassclock.h create mode 100644 classes/timecontrol/hourglasstimecontrol.cpp create mode 100644 classes/timecontrol/hourglasstimecontrol.h diff --git a/chessclock.pro b/chessclock.pro index 21fd9f0..d30905a 100644 --- a/chessclock.pro +++ b/chessclock.pro @@ -21,7 +21,15 @@ SOURCES += main.cpp\ classes/timecontrol/notimecontrol.cpp \ classes/startwidget.cpp \ classes/timecontrol/fischertimecontrol.cpp \ - classes/timecontrol/fischerclock.cpp + classes/timecontrol/fischerclock.cpp \ + classes/timecontrol/fischerafterclock.cpp \ + classes/timecontrol/fischeraftertimecontrol.cpp \ + classes/timecontrol/delayclock.cpp \ + classes/timecontrol/delaytimecontrol.cpp \ + classes/timecontrol/delayafterclock.cpp \ + classes/timecontrol/delayaftertimecontrol.cpp \ + classes/timecontrol/hourglassclock.cpp \ + classes/timecontrol/hourglasstimecontrol.cpp HEADERS += chessclockwindow.h \ classes/turninformation.h \ @@ -34,7 +42,15 @@ HEADERS += chessclockwindow.h \ classes/timecontrol/notimecontrol.h \ classes/startwidget.h \ classes/timecontrol/fischertimecontrol.h \ - classes/timecontrol/fischerclock.h + classes/timecontrol/fischerclock.h \ + classes/timecontrol/fischerafterclock.h \ + classes/timecontrol/fischeraftertimecontrol.h \ + classes/timecontrol/delayclock.h \ + classes/timecontrol/delaytimecontrol.h \ + classes/timecontrol/delayafterclock.h \ + classes/timecontrol/delayaftertimecontrol.h \ + classes/timecontrol/hourglasstimecontrol.h \ + classes/timecontrol/hourglassclock.h CONFIG += mobility MOBILITY = diff --git a/chessclockwindow.cpp b/chessclockwindow.cpp index 0ab4e48..c1715f1 100644 --- a/chessclockwindow.cpp +++ b/chessclockwindow.cpp @@ -26,8 +26,13 @@ #include "classes/startwidget.h" #include "classes/timecontrol.h" +// Time controls #include "classes/timecontrol/notimecontrol.h" #include "classes/timecontrol/fischertimecontrol.h" +#include "classes/timecontrol/fischeraftertimecontrol.h" +#include "classes/timecontrol/delaytimecontrol.h" +#include "classes/timecontrol/delayaftertimecontrol.h" +#include "classes/timecontrol/hourglasstimecontrol.h" #include #include @@ -88,6 +93,10 @@ void ChessClockWindow::initTimeControls() { start_->addTimeControl( new NoTimeControl ); start_->addTimeControl( new FischerTimeControl); + start_->addTimeControl( new FischerAfterTimeControl); + start_->addTimeControl( new DelayTimeControl ); + start_->addTimeControl( new DelayAfterTimeControl); + start_->addTimeControl( new HourGlassTimeControl); } void ChessClockWindow::startGame(TimeControl *timecontrol) diff --git a/classes/chessclock.h b/classes/chessclock.h index 56f05bb..793cd84 100644 --- a/classes/chessclock.h +++ b/classes/chessclock.h @@ -119,7 +119,7 @@ public slots: /*! Update clock information, check looser state and refresh */ virtual void updateClock(); -private: +protected: ChessClock* another_; /*! Another player's clock */ bool loser_; /*! Is player losed because of timeout */ diff --git a/classes/chessclockwidget.cpp b/classes/chessclockwidget.cpp index df29ae0..cfba058 100644 --- a/classes/chessclockwidget.cpp +++ b/classes/chessclockwidget.cpp @@ -133,7 +133,7 @@ void ChessClockWidget::initBottom() void ChessClockWidget::repaintClock() { // Set picture - if( getStatus() == Running ) + if( getStatus() == Running || getStatus() == Paused) pictureLabel_->setPixmap( picActive_); else pictureLabel_->setPixmap(picPassive_); diff --git a/classes/startwidget.cpp b/classes/startwidget.cpp index e18970b..a1496e4 100644 --- a/classes/startwidget.cpp +++ b/classes/startwidget.cpp @@ -35,7 +35,7 @@ StartWidget::StartWidget(QWidget *parent) : QLabel* titleLabel = new QLabel( qApp->applicationName() ); titleLabel->setFont(QFont("Helvetica",32,QFont::Bold)); - QLabel* copyLabel = new QLabel( tr("© Arto Hyvättinen 2010")); + QLabel* copyLabel = new QLabel( tr("© Arto Hyvättinen 2010
Free software GPL3")); copyLabel->setTextFormat(Qt::RichText); copyLabel->setWordWrap(true); @@ -47,9 +47,8 @@ StartWidget::StartWidget(QWidget *parent) : QVBoxLayout* leftLayout = new QVBoxLayout; leftLayout->addWidget(titleLabel); - leftLayout->addWidget(copyLabel); leftLayout->addWidget(logoLabel); - + leftLayout->addWidget(copyLabel); modeSelect_ = new QListWidget(); modeSelect_->setViewMode(QListView::IconMode); diff --git a/classes/timecontrol/delayafterclock.cpp b/classes/timecontrol/delayafterclock.cpp new file mode 100644 index 0000000..ee564ab --- /dev/null +++ b/classes/timecontrol/delayafterclock.cpp @@ -0,0 +1,42 @@ + /************************************************************************** + + 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 "delayafterclock.h" + +DelayAfterClock::DelayAfterClock(bool white, int delay, QWidget *parent) : + ChessClockWidget(white, parent) +{ + delay_ = delay; + setGreenTime( delay_); +} + +TurnInformation* DelayAfterClock::endTurn() +{ + int turntime = currentTurnPlayed(); + + if( turntime > delay_ ) + addTime( delay_ ); // Add whole delay + else + addTime( currentTurnPlayed()); // Add time of turn + + return ChessClock::endTurn(); + +} diff --git a/classes/timecontrol/delayafterclock.h b/classes/timecontrol/delayafterclock.h new file mode 100644 index 0000000..add7b1e --- /dev/null +++ b/classes/timecontrol/delayafterclock.h @@ -0,0 +1,50 @@ + /************************************************************************** + + 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 DELAYAFTERCLOCK_H +#define DELAYAFTERCLOCK_H + +#include "../chessclockwidget.h" + + +/*! Delay after (Bronstein delay) + + @author Arto Hyvättinen + @date 2010-08-16 + + */ +class DelayAfterClock : public ChessClockWidget +{ + Q_OBJECT +public: + DelayAfterClock(bool white, int delay, QWidget *parent = 0); + + TurnInformation* endTurn(); +signals: + +public slots: + +protected: + int delay_; + +}; + +#endif // DELAYAFTERCLOCK_H diff --git a/classes/timecontrol/delayaftertimecontrol.cpp b/classes/timecontrol/delayaftertimecontrol.cpp new file mode 100644 index 0000000..eafe48e --- /dev/null +++ b/classes/timecontrol/delayaftertimecontrol.cpp @@ -0,0 +1,63 @@ + /************************************************************************** + + 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 "delayaftertimecontrol.h" +#include "delayafterclock.h" +#include "../clockswidget.h" +#include "basicdialog.h" + +#include + +DelayAfterTimeControl::DelayAfterTimeControl() +{ +} + +QString DelayAfterTimeControl::getName() +{ + return qApp->translate("Delay after","Delay after"); +} + +QString DelayAfterTimeControl::getDescription() +{ + return qApp->translate("Delay","Time up to special increment is added after turn"); +} + +ClocksWidget* DelayAfterTimeControl::initGame(bool useLastSettings) +{ + BasicDialog dialog(getName()); + dialog.disablePerTurns(); + dialog.init(); + + if( useLastSettings || dialog.exec() == QDialog::Accepted) + { + dialog.store(); + DelayAfterClock* white = new DelayAfterClock( true, dialog.getWhiteAddition()); + white->setTimeAvailable(dialog.getWhiteInitial()); + + DelayAfterClock* black = new DelayAfterClock( false, dialog.getBlackAddition()); + black->setTimeAvailable( dialog.getBlackInitial()); + + return( new ClocksWidget(white,black)); + + } + else + return 0; +} diff --git a/classes/timecontrol/delayaftertimecontrol.h b/classes/timecontrol/delayaftertimecontrol.h new file mode 100644 index 0000000..ab979af --- /dev/null +++ b/classes/timecontrol/delayaftertimecontrol.h @@ -0,0 +1,37 @@ + /************************************************************************** + + 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 DELAYAFTERTIMECONTROL_H +#define DELAYAFTERTIMECONTROL_H + +#include "../timecontrol.h" + +class DelayAfterTimeControl : public TimeControl +{ +public: + DelayAfterTimeControl(); + + QString getName(); + QString getDescription(); + ClocksWidget* initGame(bool useLastSettings); +}; + +#endif // DELAYAFTERTIMECONTROL_H diff --git a/classes/timecontrol/delayclock.cpp b/classes/timecontrol/delayclock.cpp new file mode 100644 index 0000000..9ccfccf --- /dev/null +++ b/classes/timecontrol/delayclock.cpp @@ -0,0 +1,44 @@ + /************************************************************************** + + 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 "delayclock.h" + +DelayClock::DelayClock(bool white, int delay, QWidget *parent) : + ChessClockWidget(white, parent) +{ + delay_ = delay; + setGreenTime( delay_ ); +} + +int DelayClock::getTimeAvailable() +{ + if( currentTurn_) + { + int played = currentTurnPlayed(); + if( played > delay_) + { + // Will add the whole delay + return timeAvailableBeforeTurn_ + delay_ - played; + } + } + // in delay or not in turn. + return timeAvailableBeforeTurn_; +} diff --git a/classes/timecontrol/delayclock.h b/classes/timecontrol/delayclock.h new file mode 100644 index 0000000..5a4b166 --- /dev/null +++ b/classes/timecontrol/delayclock.h @@ -0,0 +1,51 @@ + /************************************************************************** + + 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 DELAYCLOCK_H +#define DELAYCLOCK_H + +#include "../chessclockwidget.h" +/*! Simple delay + + @author Arto Hyvättinen + @date 2010-08-16 + + + + */ +class DelayClock : public ChessClockWidget +{ + Q_OBJECT +public: + DelayClock(bool white, int delay, QWidget *parent = 0); + + int getTimeAvailable(); +signals: + +public slots: + +protected: + int delay_; + + +}; + +#endif // DELAYCLOCK_H diff --git a/classes/timecontrol/delaytimecontrol.cpp b/classes/timecontrol/delaytimecontrol.cpp new file mode 100644 index 0000000..8a0bcff --- /dev/null +++ b/classes/timecontrol/delaytimecontrol.cpp @@ -0,0 +1,63 @@ + /************************************************************************** + + 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 "delaytimecontrol.h" +#include "delayclock.h" +#include "../clockswidget.h" +#include "basicdialog.h" + +#include + +DelayTimeControl::DelayTimeControl() +{ +} + +QString DelayTimeControl::getName() +{ + return qApp->translate("Delay","Delay"); +} + +QString DelayTimeControl::getDescription() +{ + return qApp->translate("Delay","The clock waits for the delay period before starting"); +} + +ClocksWidget* DelayTimeControl::initGame(bool useLastSettings) +{ + BasicDialog dialog(getName()); + dialog.disablePerTurns(); + dialog.init(); + + if( useLastSettings || dialog.exec() == QDialog::Accepted) + { + dialog.store(); + DelayClock* white = new DelayClock( true, dialog.getWhiteAddition()); + white->setTimeAvailable(dialog.getWhiteInitial()); + + DelayClock* black = new DelayClock( false, dialog.getBlackAddition()); + black->setTimeAvailable( dialog.getBlackInitial()); + + return( new ClocksWidget(white,black)); + + } + else + return 0; +} diff --git a/classes/timecontrol/delaytimecontrol.h b/classes/timecontrol/delaytimecontrol.h new file mode 100644 index 0000000..2af88fa --- /dev/null +++ b/classes/timecontrol/delaytimecontrol.h @@ -0,0 +1,37 @@ + /************************************************************************** + + 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 DELAYTIMECONTROL_H +#define DELAYTIMECONTROL_H + +#include "../timecontrol.h" + +class DelayTimeControl : public TimeControl +{ +public: + DelayTimeControl(); + + QString getName(); + QString getDescription(); + ClocksWidget* initGame(bool useLastSettings); +}; + +#endif // DELAYTIMECONTROL_H diff --git a/classes/timecontrol/fischerafterclock.cpp b/classes/timecontrol/fischerafterclock.cpp new file mode 100644 index 0000000..fc82bd0 --- /dev/null +++ b/classes/timecontrol/fischerafterclock.cpp @@ -0,0 +1,38 @@ + /************************************************************************** + + 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 "fischerafterclock.h" + +FischerAfterClock::FischerAfterClock(bool white, int addition, int perTurns, QWidget *parent) : + ChessClockWidget(white, parent) +{ + addition_ = addition; + perTurns_ = perTurns; + + setGreenTime( addition ); +} + +TurnInformation* FischerAfterClock::endTurn() +{ + if( getTurn() % perTurns_ == 0) + addTime( addition_ ); + return ChessClock::endTurn() ; +} diff --git a/classes/timecontrol/fischerafterclock.h b/classes/timecontrol/fischerafterclock.h new file mode 100644 index 0000000..d352666 --- /dev/null +++ b/classes/timecontrol/fischerafterclock.h @@ -0,0 +1,52 @@ + /************************************************************************** + + 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 FISCHERAFTERCLOCK_H +#define FISCHERAFTERCLOCK_H + +#include "../chessclockwidget.h" + +class TurnInformation; + +/*! Insert specified time after turn + + @author Arto Hyvättinen + @date 2010-08-16 + */ +class FischerAfterClock : public ChessClockWidget +{ + Q_OBJECT +public: + FischerAfterClock(bool white, int addition, int perTurns, QWidget *parent = 0); + TurnInformation* endTurn(); + +signals: + +public slots: + +protected: + int addition_; + int perTurns_; + + +}; + +#endif // FISCHERAFTERCLOCK_H diff --git a/classes/timecontrol/fischeraftertimecontrol.cpp b/classes/timecontrol/fischeraftertimecontrol.cpp new file mode 100644 index 0000000..c1a3580 --- /dev/null +++ b/classes/timecontrol/fischeraftertimecontrol.cpp @@ -0,0 +1,56 @@ + /************************************************************************** + + 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 "fischeraftertimecontrol.h" +#include "fischerafterclock.h" +#include "../clockswidget.h" +#include "basicdialog.h" + + +FischerAfterTimeControl::FischerAfterTimeControl() +{ +} + +QString FischerAfterTimeControl::getDescription() +{ + return qApp->translate("FischerAfter","Specified time increment is added to clock after turn."); +} + +ClocksWidget* FischerAfterTimeControl::initGame(bool useLastSettings) +{ + BasicDialog dialog(getName()); + dialog.init(); + + if( useLastSettings || dialog.exec() == QDialog::Accepted) + { + dialog.store(); + FischerAfterClock* white = new FischerAfterClock( true, dialog.getWhiteAddition(), dialog.getWhitePerTurns()); + white->setTimeAvailable(dialog.getWhiteInitial()); + + FischerAfterClock* black = new FischerAfterClock( false, dialog.getBlackAddition(), dialog.getBlackPerTurns()); + black->setTimeAvailable( dialog.getBlackInitial()); + + return( new ClocksWidget(white,black)); + + } + else + return 0; +} diff --git a/classes/timecontrol/fischeraftertimecontrol.h b/classes/timecontrol/fischeraftertimecontrol.h new file mode 100644 index 0000000..ac48fc9 --- /dev/null +++ b/classes/timecontrol/fischeraftertimecontrol.h @@ -0,0 +1,39 @@ + /************************************************************************** + + 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 FISCHERAFTERTIMECONTROL_H +#define FISCHERAFTERTIMECONTROL_H + +#include "../timecontrol.h" +#include + +class FischerAfterTimeControl : public TimeControl +{ +public: + FischerAfterTimeControl(); + + QString getName() { return qApp->translate("FischerAfter","Addition after"); } + QString getDescription(); + ClocksWidget* initGame( bool useLastSettings); + +}; + +#endif // FISCHERAFTERTIMECONTROL_H diff --git a/classes/timecontrol/hourglassclock.cpp b/classes/timecontrol/hourglassclock.cpp new file mode 100644 index 0000000..548132d --- /dev/null +++ b/classes/timecontrol/hourglassclock.cpp @@ -0,0 +1,73 @@ + /************************************************************************** + + 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 "hourglassclock.h" +#include "../turninformation.h" + +HourGlassClock::HourGlassClock(bool white, QWidget *parent) : + ChessClockWidget(white, parent) +{ +} + + +int HourGlassClock::getTimeAvailable() +{ + if( !another_) + return timeAvailableBeforeTurn_; + + if( currentTurn_ ) + { + return timeAvailableBeforeTurn_ - currentTurnPlayed(); + } + else + { + return timeAvailableBeforeTurn_ + another_->currentTurnPlayed(); + } +} + + +TurnInformation* HourGlassClock::endTurn() +{ + updateTimer_.stop(); + status_ = NotRunning; + + updateClock(); + + timePlayedBeforeTurn_ = getTimePlayed(); + + // Count available times of BOTH the clocks! + setTimeAvailable( getTimeAvailable() ); + another_->setTimeAvailable( another_->getTimeAvailable()); + + // Close and return turn information + currentTurn_->turnReady(timeAvailableBeforeTurn_ ); + TurnInformation* information = currentTurn_; + currentTurn_ = 0; + + emit turnEnded(); + return information; +} + +void HourGlassClock::updateClock() +{ + ChessClock::updateClock(); + another_->ChessClock::updateClock(); +} diff --git a/classes/timecontrol/hourglassclock.h b/classes/timecontrol/hourglassclock.h new file mode 100644 index 0000000..bceb063 --- /dev/null +++ b/classes/timecontrol/hourglassclock.h @@ -0,0 +1,42 @@ + /************************************************************************** + + 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 HOURGLASSCLOCK_H +#define HOURGLASSCLOCK_H + +#include "../chessclockwidget.h" + + +class HourGlassClock : public ChessClockWidget +{ + Q_OBJECT +public: + HourGlassClock(bool white, QWidget *parent = 0); + + int getTimeAvailable(); + TurnInformation* endTurn(); + +public slots: + void updateClock(); + +}; + +#endif // HOURGLASSCLOCK_H diff --git a/classes/timecontrol/hourglasstimecontrol.cpp b/classes/timecontrol/hourglasstimecontrol.cpp new file mode 100644 index 0000000..340b926 --- /dev/null +++ b/classes/timecontrol/hourglasstimecontrol.cpp @@ -0,0 +1,65 @@ + /************************************************************************** + + 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 "hourglasstimecontrol.h" +#include "hourglassclock.h" +#include "../clockswidget.h" +#include "basicdialog.h" + +#include +#include + +HourGlassTimeControl::HourGlassTimeControl() +{ +} + + +QString HourGlassTimeControl::getName() +{ + return qApp->translate("Hour Glass","Hour Glass"); +} + +QString HourGlassTimeControl::getDescription() +{ + return qApp->translate("Hour Glass","Time added to clock is substracted to another"); +} + +ClocksWidget* HourGlassTimeControl::initGame(bool useLastSettings) +{ + BasicDialog dialog(getName()); + dialog.disableAddition(); + dialog.init(QTime(0,30),QTime(0,30)); + + if( useLastSettings || dialog.exec() == QDialog::Accepted) + { + dialog.store(); + HourGlassClock* white = new HourGlassClock( true); + white->setTimeAvailable(dialog.getWhiteInitial()); + + HourGlassClock* black = new HourGlassClock( false); + black->setTimeAvailable( dialog.getBlackInitial()); + + return( new ClocksWidget(white,black)); + + } + else + return 0; +} diff --git a/classes/timecontrol/hourglasstimecontrol.h b/classes/timecontrol/hourglasstimecontrol.h new file mode 100644 index 0000000..76cb211 --- /dev/null +++ b/classes/timecontrol/hourglasstimecontrol.h @@ -0,0 +1,37 @@ + /************************************************************************** + + 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 HOURGLASSTIMECONTROL_H +#define HOURGLASSTIMECONTROL_H + +#include "../timecontrol.h" + +class HourGlassTimeControl : public TimeControl +{ +public: + HourGlassTimeControl(); + + QString getName(); + QString getDescription(); + ClocksWidget* initGame(bool useLastSettings); +}; + +#endif // HOURGLASSTIMECONTROL_H diff --git a/main.cpp b/main.cpp index b54e0f9..f70a4dd 100644 --- a/main.cpp +++ b/main.cpp @@ -23,7 +23,6 @@ /*! @mainpage Chess Clock @author Arto Hyvättinen - @version 0.1.0 Chess Clock @@ -56,7 +55,7 @@ int main(int argc, char *argv[]) a.setApplicationName( a.tr("Chess Clock","Application name") ); a.setOrganizationName("Chess Clock"); a.setOrganizationDomain("chessclock.garage.maemo.org"); - a.setApplicationVersion("0.1.0"); + a.setApplicationVersion("0.1.1"); ChessClockWindow w; -- 1.7.9.5