Added time control base class, basic dialog and no-time controll.
Compiled but untested
classes/chessclock.cpp \
classes/chessclockwidget.cpp \
classes/clockswidget.cpp \
- classes/welcomescreenwidget.cpp
+ classes/welcomescreenwidget.cpp \
+ classes/timecontrol/basicdialog.cpp \
+ classes/timecontrol/notimecontrol.cpp
HEADERS += chessclockwindow.h \
classes/turninformation.h \
classes/chessclock.h \
classes/chessclockwidget.h \
classes/clockswidget.h \
- classes/welcomescreenwidget.h
+ classes/welcomescreenwidget.h \
+ classes/timecontrol.h \
+ classes/timecontrol/basicdialog.h \
+ classes/timecontrol/notimecontrol.h
CONFIG += mobility
MOBILITY =
<file>pic/white_gray.png</file>
<file>pic/chessclock.png</file>
<file>pic/logo.png</file>
+ <file>pic/white_small.png</file>
+ <file>pic/black_small.png</file>
</qresource>
</RCC>
virtual void initBottom();
/*! Convert msecs to h:mm:ss QString */
- QString timeString(int msecs);
+ static QString timeString(int msecs);
protected:
--- /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 TIMECONTROL_H
+#define TIMECONTROL_H
+
+#include <QString>
+#include <QIcon>
+class ClocksWidget;
+
+/*! Base class of virtual controls
+
+ @author Arto Hyvättinen
+ @date 2010-08-15
+
+ */
+class TimeControl
+{
+public:
+ /*! Name of the time control */
+ virtual QString getName() = 0;
+ /*! Description of the time control */
+ virtual QString getDescription() = 0;
+ /*! Icon of the time control */
+ virtual QIcon getIcon() { return QIcon(":/rc/pic/chessclock.png"); }
+ /*! Init new game
+
+ Ask options, and init new game.
+ @param useLastSettings Use last settings, don't ask
+ @return Clocks widget for new game, or NULL if unsuccess. */
+ virtual ClocksWidget* initGame(bool useLastSettings=false) = 0;
+};
+
+
+#endif // TIMECONTROL_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 "basicdialog.h"
+
+#include <QTimeEdit>
+#include <QTime>
+#include <QSpinBox>
+#include <QCheckBox>
+#include <QLabel>
+#include <QGridLayout>
+#include <QPushButton>
+#include <QSettings>
+
+
+BasicDialog::BasicDialog(QString timeControlName, QWidget *parent) :
+ QDialog(parent)
+{
+ timeControlName_ = timeControlName;
+
+ // Initial times
+ initialLabel_ = new QLabel( tr("Initial time"));
+ whiteInitial_ = initTimeEdit();
+ blackInitial_ = initTimeEdit();
+ // Additional times
+ additionLabel_ = new QLabel( tr("Additional time"));
+ whiteAddition_ = initTimeEdit();
+ blackAddition_ = initTimeEdit();
+ // Turns per addition
+ perTurnLabel_ = new QLabel( tr("Addition per turn"));
+ whiteTurns_=new QSpinBox;
+ whiteTurns_->setRange(1,99);
+
+ blackTurns_=new QSpinBox;
+ blackTurns_->setRange(1,99);
+
+ // 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)));
+
+ equals_->setChecked(true);
+
+ whiteLabel_ = new QLabel;
+ whiteLabel_->setPixmap(QPixmap(":/rc/pic/white_small.png"));
+ blackLabel_ = new QLabel;
+ blackLabel_->setPixmap(QPixmap(":/rc/pic/black_small.png"));
+
+ // Lay out
+ QGridLayout* layout = new QGridLayout;
+ layout->addWidget(equals_,0,0);
+ layout->addWidget(whiteLabel_,0,1,1,1,Qt::AlignCenter);
+ layout->addWidget(blackLabel_,0,2,1,1,Qt::AlignCenter);
+
+ layout->addWidget(initialLabel_,1,0);
+ layout->addWidget(whiteInitial_,1,1);
+ layout->addWidget(blackInitial_,1,2);
+
+ layout->addWidget(additionLabel_,2,0);
+ layout->addWidget(whiteAddition_,2,1);
+ layout->addWidget(blackAddition_,2,2);
+
+ layout->addWidget(perTurnLabel_,3,0);
+ layout->addWidget(whiteTurns_,3,1);
+ layout->addWidget(blackTurns_,3,2);
+
+ QPushButton* button = new QPushButton( tr("Start game"));
+ connect( button, SIGNAL(clicked()), this, SLOT(accept()));
+
+ setLayout( layout );
+ setWindowTitle( timeControlName_);
+
+}
+
+void BasicDialog::disablePerTurns()
+{
+ perTurnLabel_->setVisible(false);
+ whiteTurns_->setVisible(false);
+ blackTurns_->setVisible(false);
+}
+
+void BasicDialog::disableAddition()
+{
+ disablePerTurns();
+ whiteAddition_->setVisible(false);
+ blackAddition_->setVisible(false);
+ additionLabel_->setVisible(false);
+}
+
+void BasicDialog::disableUnEquals()
+{
+ equals_->setChecked(true);
+ equals_->setVisible(false);
+ whiteLabel_->setVisible(false);
+ blackLabel_->setVisible(false);
+ blackInitial_->setVisible(false);
+ blackAddition_->setVisible(false);
+ blackTurns_->setVisible(false);
+}
+
+void BasicDialog::store()
+{
+ // Store into QSettings
+ QSettings s;
+ s.beginGroup(timeControlName_);
+ s.setValue("Equals",equals_->isChecked());
+ s.setValue("WhiteInitial",whiteInitial_->time());
+ s.setValue("WhiteAddition",whiteAddition_->time());
+ s.setValue("WhitePerTurns",whiteTurns_->value());
+
+ s.setValue("BlackInitial",blackInitial_->time());
+ s.setValue("BlackAddition",blackAddition_->time());
+ s.setValue("BlackPerTurns",blackTurns_->value());
+}
+
+void BasicDialog::init(QTime whiteInitial, QTime blackInitial, QTime whiteAddition, QTime blackAddition, int whitePerTurns, int blackPerTurns)
+{
+ // Load from QSettings
+ // first time use defaults
+ QSettings s;
+ s.beginGroup(timeControlName_);
+
+ equals_->setChecked(s.value("Equals",true).toBool() );
+ whiteInitial_->setTime( s.value("WhiteInitial",whiteInitial).toTime());
+ blackInitial_->setTime(s.value("BlackInitial",blackInitial).toTime());
+ whiteAddition_->setTime(s.value("WhiteAddition",whiteAddition).toTime());
+ blackAddition_->setTime(s.value("BlackAddition",blackAddition).toTime());
+ whiteTurns_->setValue(s.value("WhitePerTurns",whitePerTurns).toInt());
+ blackTurns_->setValue(s.value("BlackPerTurns",blackPerTurns).toInt());
+
+}
+
+int BasicDialog::getWhiteInitial()
+{
+ return toMsecs( whiteInitial_);
+}
+
+int BasicDialog::getWhiteAddition()
+{
+ return toMsecs( whiteAddition_);
+}
+
+int BasicDialog::getWhitePerTurns()
+{
+ return whiteTurns_->value();
+}
+
+int BasicDialog::getBlackInitial()
+{
+ // if Equals is checked, black values are disabled
+ // and white values returned.
+ if( equals_->isChecked())
+ return toMsecs( whiteInitial_);
+ else
+ return toMsecs( blackInitial_);
+}
+
+int BasicDialog::getBlackAddition()
+{
+ if( equals_->isChecked())
+ return toMsecs( whiteAddition_);
+ else
+ return toMsecs( blackAddition_ );
+
+}
+
+int BasicDialog::getBlackPerTurns()
+{
+ if( equals_->isChecked())
+ return whiteTurns_->value();
+ else
+ return blackTurns_->value();
+}
+
+
+int BasicDialog::toMsecs(QTimeEdit *timeEdit)
+{
+ QTime qtime=timeEdit->time();
+ return 0-qtime.msecsTo(QTime(0,0,0));
+}
+
+
+QTimeEdit* BasicDialog::initTimeEdit()
+{
+ // Make QTimeEdit and set up range and display format
+ QTimeEdit* timeEdit = new QTimeEdit;
+ timeEdit->setMinimumTime( QTime(0,0,0));
+ timeEdit->setMaximumTime( QTime(12,0,0));
+ timeEdit->setDisplayFormat( tr("hh:mm:ss","Time Edit display format"));
+ return timeEdit;
+}
--- /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 BASICDIALOG_H
+#define BASICDIALOG_H
+
+#include <QDialog>
+#include <QString>
+#include <QTime>
+
+class QTimeEdit;
+class QSpinBox;
+class QCheckBox;
+class QLabel;
+
+/*! Basic dialog for Time Control settings
+
+ @author Arto Hyvättinen
+ @date 2010-08-16
+
+ Basic dialog setting up clock.
+ Time control can use this dialog.
+ Using disableAddition(), disablePerTurns() or disableUnEquals()
+ it is possible to customize dialog.
+
+ All the widgets are public for customization.
+ */
+
+class BasicDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ /*! Constructor
+
+ @param timeControlName Name of time controller, will be window title */
+ BasicDialog(QString timeContolName, QWidget *parent = 0);
+
+ void disableAddition();
+ void disablePerTurns();
+ void disableUnEquals();
+
+ int getWhiteInitial();
+ int getBlackInitial();
+ int getWhiteAddition();
+ int getBlackAddition();
+ int getWhitePerTurns();
+ int getBlackPerTurns();
+ /*! Store values to settings */
+ void store();
+ /*! Load values from settings, or init to initial values */
+ void init(QTime whiteInitial=QTime(1,30),
+ QTime blackInitial=QTime(1,30),
+ QTime whiteAddition=QTime(0,0,30),
+ QTime blackAddition=QTime(0,0,30),
+ int whitePerTurns = 1,
+ int blackPerTurns = 1);
+signals:
+
+public slots:
+
+protected:
+ static QTimeEdit* initTimeEdit();
+ static int toMsecs(QTimeEdit* timeEdit);
+
+public:
+ QTimeEdit *whiteInitial_, *blackInitial_;
+ QTimeEdit *whiteAddition_, *blackAddition_;
+ QSpinBox *whiteTurns_, *blackTurns_;
+ QCheckBox *equals_;
+
+ QLabel *initialLabel_, *additionLabel_, *perTurnLabel_, *equalsLabel_;
+ QLabel *whiteLabel_, *blackLabel_;
+
+protected:
+ QString timeControlName_;
+
+
+};
+
+#endif // BASICDIALOG_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 "notimecontrol.h"
+
+#include "../chessclock.h"
+#include "basicdialog.h"
+#include "../chessclockwidget.h"
+#include "../clockswidget.h"
+
+#include <QApplication>
+
+NoTimeControl::NoTimeControl()
+{
+}
+
+
+QString NoTimeControl::getDescription()
+{
+ return qApp->translate("NoneTimeControl","Never add time.");
+}
+
+ClocksWidget* NoTimeControl::initGame(bool useLastSettings)
+{
+ BasicDialog dialog(getName());
+
+ dialog.disableAddition();
+ dialog.init();
+
+ if( useLastSettings || dialog.exec() == QDialog::Accepted)
+ {
+ dialog.store();
+ ChessClockWidget* white = new ChessClockWidget(true);
+ white->addTime(dialog.getWhiteInitial());
+
+ ChessClockWidget* black = new ChessClockWidget(false);
+ 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 NOTIMECONTROL_H
+#define NOTIMECONTROL_H
+
+#include "../timecontrol.h"
+#include <QApplication>
+
+class NoTimeControl : public TimeControl
+{
+public:
+ NoTimeControl();
+
+ QString getName() { return qApp->translate("NoTimeControl","Normal clock"); }
+ QString getDescription();
+ ClocksWidget* initGame(bool useLastSettings);
+};
+
+#endif // NOTIMECONTROL_H
{
QApplication a(argc, argv);
a.setApplicationName( a.tr("Chess Clock","Application name") );
+ a.setOrganizationName("Chess Clock");
+ a.setOrganizationDomain("chessclock.garage.maemo.org");
a.setApplicationVersion("0.1.0");
ChessClockWindow w;