X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=chessclockwindow.cpp;h=8bbd15a7eb536439f95fe969708eaa5ec9f7882b;hb=9473d40c4b521f23d222ed1373d405995b02ee33;hp=2bdecdad8c78ae711b5aea803abf2caa9239f27b;hpb=ba3a771506c5a43c9f93d99930537215400f75e6;p=chessclock diff --git a/chessclockwindow.cpp b/chessclockwindow.cpp index 2bdecda..8bbd15a 100644 --- a/chessclockwindow.cpp +++ b/chessclockwindow.cpp @@ -23,9 +23,17 @@ #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 #include +#include +#include +#include ChessClockWindow::ChessClockWindow(QWidget *parent) : QMainWindow(parent) @@ -34,16 +42,68 @@ ChessClockWindow::ChessClockWindow(QWidget *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() {