X-Git-Url: http://git.maemo.org/git/?p=chessclock;a=blobdiff_plain;f=chessclockwindow.cpp;h=c1715f11c74644a9775af829482aa4bed493f351;hp=b41a8934af19fe9c9b87dec5cb53996e51709f5c;hb=cfcfb018dce39cd48eda0f601aa5134632a50484;hpb=0488ea4e4628cf9e931a6e35540123fb854ff189 diff --git a/chessclockwindow.cpp b/chessclockwindow.cpp index b41a893..c1715f1 100644 --- a/chessclockwindow.cpp +++ b/chessclockwindow.cpp @@ -21,11 +21,101 @@ #include "chessclockwindow.h" +#include "classes/clockswidget.h" +#include "classes/chessclockwidget.h" +#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 +#include +#include +#include + ChessClockWindow::ChessClockWindow(QWidget *parent) : QMainWindow(parent) { + + setWindowIcon( QIcon(":/rc/pic/chessclock.png")); + setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) ); + + // Start widget to select time control + start_ = new StartWidget; + clocks_ = 0; + + initTimeControls(); + + stack_ = new QStackedWidget; + stack_->addWidget(start_); + + 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); + start_->addTimeControl( new FischerAfterTimeControl); + start_->addTimeControl( new DelayTimeControl ); + start_->addTimeControl( new DelayAfterTimeControl); + start_->addTimeControl( new HourGlassTimeControl); +} + +void ChessClockWindow::startGame(TimeControl *timecontrol) +{ + ClocksWidget* newWidget = timecontrol->initGame(false); + if( newWidget ) + { + if( clocks_ ) + { + stack_->removeWidget(clocks_); + delete clocks_; + } + clocks_ = newWidget; + stack_->addWidget(clocks_); + stack_->setCurrentWidget(clocks_); + } +} + + ChessClockWindow::~ChessClockWindow() {