classes/clockswidget.cpp \
classes/welcomescreenwidget.cpp \
classes/timecontrol/basicdialog.cpp \
- classes/timecontrol/notimecontrol.cpp
+ classes/timecontrol/notimecontrol.cpp \
+ classes/startwidget.cpp \
+ classes/timecontrol/fischertimecontrol.cpp \
+ classes/timecontrol/fischerclock.cpp
HEADERS += chessclockwindow.h \
classes/turninformation.h \
classes/welcomescreenwidget.h \
classes/timecontrol.h \
classes/timecontrol/basicdialog.h \
- classes/timecontrol/notimecontrol.h
+ classes/timecontrol/notimecontrol.h \
+ classes/startwidget.h \
+ classes/timecontrol/fischertimecontrol.h \
+ classes/timecontrol/fischerclock.h
CONFIG += mobility
MOBILITY =
#include "classes/clockswidget.h"
#include "classes/chessclockwidget.h"
+#include "classes/startwidget.h"
+#include "classes/timecontrol.h"
+
+#include "classes/timecontrol/notimecontrol.h"
+#include "classes/timecontrol/fischertimecontrol.h"
#include <QIcon>
#include <QApplication>
+#include <QMenuBar>
+#include <QMessageBox>
+#include <QStackedWidget>
ChessClockWindow::ChessClockWindow(QWidget *parent)
: QMainWindow(parent)
setWindowIcon( QIcon(":/rc/pic/chessclock.png"));
setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) );
- ChessClockWidget* white = new ChessClockWidget(true, this);
- white->setGreenTime(5000);
- ChessClockWidget* black = new ChessClockWidget(false, this);
+ // Start widget to select time control
+ start_ = new StartWidget;
+ clocks_ = 0;
+
+ initTimeControls();
+
+ stack_ = new QStackedWidget;
+ stack_->addWidget(start_);
- clocks_ = new ClocksWidget( white, black, this );
- setCentralWidget( clocks_ );
+ setCentralWidget( stack_ );
+ connect( start_, SIGNAL(selected(TimeControl*)), this, SLOT(startGame(TimeControl*)));
+
+ // Set up menu
+ menuBar()->addAction( tr("Pause"), this, SLOT(pause()));
+ menuBar()->addAction( tr("New game"), this, SLOT(newGame()));
}
+void ChessClockWindow::pause()
+{
+ if( clocks_ )
+ clocks_->pause();
+}
+
+void ChessClockWindow::newGame()
+{
+ pause();
+ if( clocks_ == 0 || !clocks_->isPlayStarted() || QMessageBox::question(this, tr("Start new game"),
+ tr("Really quit current game and start new one with current settings?"),
+ QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
+ {
+ stack_->setCurrentWidget(start_);
+
+ if( clocks_ )
+ { stack_->removeWidget(clocks_);
+ delete clocks_;
+ }
+ clocks_=0;
+ }
+}
+
+void ChessClockWindow::initTimeControls()
+{
+ start_->addTimeControl( new NoTimeControl );
+ start_->addTimeControl( new FischerTimeControl);
+}
+
+void ChessClockWindow::startGame(TimeControl *timecontrol)
+{
+ ClocksWidget* newWidget = timecontrol->initGame(false);
+ if( newWidget )
+ {
+ if( clocks_ )
+ delete clocks_;
+ clocks_ = newWidget;
+ stack_->addWidget(clocks_);
+ stack_->setCurrentWidget(clocks_);
+ }
+}
+
+
ChessClockWindow::~ChessClockWindow()
{
#include <QtGui/QMainWindow>
class ClocksWidget;
+class StartWidget;
+class TimeControl;
+class QStackedWidget;
class ChessClockWindow : public QMainWindow
{
ChessClockWindow(QWidget *parent = 0);
~ChessClockWindow();
+public slots:
+ void startGame( TimeControl* timecontrol);
+ void pause();
+ void newGame();
+
+
+protected:
+ void initTimeControls();
protected:
ClocksWidget* clocks_;
+ StartWidget* start_;
+ QStackedWidget* stack_;
};
#endif // CHESSCLOCKWINDOW_H
TurnInformation* ChessClock::endTurn()
{
updateTimer_.stop();
+ status_ = NotRunning;
+
+ updateClock();
// Count time played
timePlayedBeforeTurn_ = getTimePlayed();
+
// Count time available
// This update current turn
timeAvailableBeforeTurn_ = getTimeAvailable();
- status_ = NotRunning;
- updateClock();
// Close and return turn information
currentTurn_->turnReady(timeAvailableBeforeTurn_ );
TurnInformation* information = currentTurn_;
currentTurn_ = 0;
+
emit turnEnded();
return information;
}
int ChessClock::getTimePlayed()
{
- // Count time played time
- if( currentTurn_ )
- return timePlayedBeforeTurn_ + currentTurnPlayed();
- else
- return timePlayedBeforeTurn_;
+ return timePlayedBeforeTurn_ + currentTurnPlayed();
}
break;
case WhitePause:
// Continue play
+ pauseLabel_->setVisible(false);
white_->continueTurn();
status_=WhiteTurn;
break;
case BlackPause:
// Continue play
+ pauseLabel_->setVisible(false);
black_->continueTurn();
status_=BlackTurn;
break;
Q_OBJECT
public:
ClocksWidget(ChessClock* white, ChessClock* black, QWidget *parent = 0);
-
+ bool isPlayStarted() { return (status_!=Welcome); }
protected:
void mouseReleaseEvent(QMouseEvent *event);
--- /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 "startwidget.h"
+#include "timecontrol.h"
+
+#include <QVBoxLayout>
+#include <QHBoxLayout>
+#include <QApplication>
+#include <QFont>
+#include <QLabel>
+#include <QListWidgetItem>
+
+StartWidget::StartWidget(QWidget *parent) :
+ QWidget(parent)
+{
+ QLabel* titleLabel = new QLabel( qApp->applicationName() );
+ titleLabel->setFont(QFont("Helvetica",32,QFont::Bold));
+
+ QLabel* copyLabel = new QLabel( tr("© Arto Hyvättinen 2010"));
+ copyLabel->setTextFormat(Qt::RichText);
+ copyLabel->setWordWrap(true);
+
+ QLabel* logoLabel = new QLabel;
+ logoLabel->setPixmap( QPixmap(":/rc/pic/logo.png"));
+
+ QLabel* introLabel = new QLabel( tr("Select game mode"));
+ introLabel->setWordWrap(true);
+
+ QVBoxLayout* leftLayout = new QVBoxLayout;
+ leftLayout->addWidget(titleLabel);
+ leftLayout->addWidget(copyLabel);
+ leftLayout->addWidget(logoLabel);
+ leftLayout->addWidget(introLabel);
+
+ modeSelect_ = new QListWidget();
+ modeSelect_->setViewMode(QListView::IconMode);
+ modeSelect_->setMovement(QListView::Static);
+ modeSelect_->setSelectionMode(QAbstractItemView::NoSelection);
+ modeSelect_->setIconSize(QSize(64,64 ));
+
+ connect( modeSelect_, SIGNAL(itemClicked(QListWidgetItem*)),this,SLOT(selectControl(QListWidgetItem*)));
+
+ QHBoxLayout* layout = new QHBoxLayout;
+ layout->addLayout(leftLayout);
+ layout->addWidget(modeSelect_);
+
+
+ setLayout( layout );
+}
+
+void StartWidget::addTimeControl(TimeControl *tc)
+{
+ timeControls_.append(tc);
+ QListWidgetItem* item = new QListWidgetItem(modeSelect_);
+ item->setText( tc->getName());
+ item->setIcon( tc->getIcon());
+ // Store index to UserRole
+ item->setData(Qt::UserRole, timeControls_.size()-1);
+
+}
+
+void StartWidget::selectControl(QListWidgetItem *item)
+{
+ int index=item->data(Qt::UserRole).toInt();
+ TimeControl* tc=timeControls_.at(index);
+ emit selected(tc);
+
+}
+
--- /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 STARTWIDGET_H
+#define STARTWIDGET_H
+
+#include <QWidget>
+#include <QListWidget>
+
+
+class QListWidget;
+class TimeControl;
+
+/*! Start widget to ask for Time control
+
+ @author Arto Hyvättinen
+ @date 2010-08-16
+
+ Time Controls are stored inside Start Widget */
+class StartWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ StartWidget(QWidget *parent = 0);
+ void addTimeControl( TimeControl* tc);
+
+signals:
+ void selected(TimeControl* timeControl);
+
+public slots:
+ void selectControl(QListWidgetItem* item);
+
+protected:
+ QListWidget* modeSelect_;
+ QList<TimeControl*> timeControls_;
+
+};
+
+#endif // STARTWIDGET_H
// Equal times
equals_ = new QCheckBox( tr("Equal times"));
- connect( equals_, SIGNAL(stateChanged(bool)),blackInitial_,SLOT(setDisabled(bool)));
- connect( equals_, SIGNAL(stateChanged(bool)),blackAddition_,SLOT(setDisabled(bool)));
- connect( equals_, SIGNAL(stateChanged(bool)),blackTurns_,SLOT(setDisabled(bool)));
+ connect( equals_, SIGNAL(stateChanged(int)),this,SLOT(setEquals()));
equals_->setChecked(true);
+ setEquals();
whiteLabel_ = new QLabel;
whiteLabel_->setPixmap(QPixmap(":/rc/pic/white_small.png"));
QPushButton* button = new QPushButton( tr("Start game"));
connect( button, SIGNAL(clicked()), this, SLOT(accept()));
+ layout->addWidget(button,4,2);
setLayout( layout );
setWindowTitle( timeControlName_);
}
+void BasicDialog::setEquals()
+{
+ blackInitial_->setDisabled( equals_->isChecked());
+ blackAddition_->setDisabled( equals_->isChecked());
+ blackTurns_->setDisabled( equals_->isChecked());
+
+}
+
+
void BasicDialog::disablePerTurns()
{
perTurnLabel_->setVisible(false);
s.beginGroup(timeControlName_);
equals_->setChecked(s.value("Equals",true).toBool() );
+ setEquals();
whiteInitial_->setTime( s.value("WhiteInitial",whiteInitial).toTime());
blackInitial_->setTime(s.value("BlackInitial",blackInitial).toTime());
whiteAddition_->setTime(s.value("WhiteAddition",whiteAddition).toTime());
int BasicDialog::toMsecs(QTimeEdit *timeEdit)
{
QTime qtime=timeEdit->time();
- return 0-qtime.msecsTo(QTime(0,0,0));
+ int msecs=qtime.msecsTo(QTime(0,0,0));;
+ return 0-msecs;
}
signals:
public slots:
+ void setEquals();
protected:
static QTimeEdit* initTimeEdit();
--- /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 "fischerclock.h"
+
+FischerClock::FischerClock(bool white, int addition, int perTurns, QWidget *parent) :
+ ChessClockWidget(white, parent)
+{
+ addition_ = addition;
+ perTurns_ = perTurns;
+
+ setGreenTime( addition );
+}
+
+void FischerClock::startTurn()
+{
+ if(getTurn() % perTurns_ == 0 )
+ addTime( addition_ );
+ ChessClock::startTurn();
+}
--- /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 FISCHERCLOCK_H
+#define FISCHERCLOCK_H
+
+#include "../chessclockwidget.h"
+
+class FischerClock : public ChessClockWidget
+{
+ Q_OBJECT
+public:
+ FischerClock(bool white, int addition, int perTurns, QWidget *parent = 0);
+
+
+ void startTurn();
+
+signals:
+
+public slots:
+
+protected:
+ int addition_;
+ int perTurns_;
+
+};
+
+#endif // FISCHERCLOCK_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 "fischertimecontrol.h"
+#include "fischerclock.h"
+#include "../clockswidget.h"
+#include "basicdialog.h"
+
+#include <QApplication>
+
+
+FischerTimeControl::FischerTimeControl()
+{
+}
+
+QString FischerTimeControl::getDescription()
+{
+ return qApp->translate("Fischer","Specified time increment is added to clock before turn.");
+}
+
+ClocksWidget* FischerTimeControl::initGame(bool useLastSettings)
+{
+ BasicDialog dialog(getName());
+ dialog.init();
+
+ if( useLastSettings || dialog.exec() == QDialog::Accepted)
+ {
+ dialog.store();
+ FischerClock* white = new FischerClock( true, dialog.getWhiteAddition(), dialog.getWhitePerTurns());
+ white->addTime(dialog.getWhiteInitial());
+
+ FischerClock* black = new FischerClock( false, dialog.getBlackAddition(), dialog.getBlackPerTurns());
+ black->addTime( dialog.getBlackInitial());
+
+ return( new ClocksWidget(white,black));
+
+ }
+ else
+ return 0;
+}
--- /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 FISCHERTIMECONTROL_H
+#define FISCHERTIMECONTROL_H
+
+#include "../timecontrol.h"
+#include <QApplication>
+
+class FischerTimeControl : public TimeControl
+{
+public:
+ FischerTimeControl();
+
+ QString getName() { return qApp->translate("Fischer","Addition before"); }
+ QString getDescription();
+ ClocksWidget* initGame(bool useLastSettings);
+};
+
+#endif // FISCHERTIMECONTROL_H
{
dialog.store();
ChessClockWidget* white = new ChessClockWidget(true);
- white->addTime(dialog.getWhiteInitial());
+ white->setTimeAvailable(dialog.getWhiteInitial());
ChessClockWidget* black = new ChessClockWidget(false);
- black->addTime( dialog.getBlackInitial());
+ black->setTimeAvailable( dialog.getBlackInitial());
return( new ClocksWidget(white,black));