X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=chessclockwindow.cpp;h=43b64cd42d74054086f0f6c0ecd70a4a05da08c7;hb=4f3147c454280bc975b814ab0328a341473e555a;hp=a75cccf1bc8e5b61b70f08d1a39b958d7425d160;hpb=ebe5873e30a11983068a087332c5046720637fd1;p=chessclock diff --git a/chessclockwindow.cpp b/chessclockwindow.cpp index a75cccf..43b64cd 100644 --- a/chessclockwindow.cpp +++ b/chessclockwindow.cpp @@ -21,17 +21,129 @@ #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 +#include +#include ChessClockWindow::ChessClockWindow(QWidget *parent) : QMainWindow(parent) { - ChessClockWidget* widget = new ChessClockWidget(true, this); - setCentralWidget(widget); + 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())); // UNUSED - Pause button + menuBar()->addAction( tr("New game"), this, SLOT(newGame())); + menuBar()->addAction( keepAction ); + menuBar()->addAction( tr("Visit web page"), this, SLOT(visitWeb())); + menuBar()->addAction( tr("About"),this, SLOT(about())); + menuBar()->addAction(tr("About Qt"), this, SLOT(aboutQt())); + +} + +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 the current game and start a new one?"), + QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) + { + stack_->setCurrentWidget(start_); + + if( clocks_ ) + { stack_->removeWidget(clocks_); + delete clocks_; + } + clocks_=0; + } +} +void ChessClockWindow::visitWeb() +{ + pause(); + QProcess* process = new QProcess(this); + process->start(QString("browser --url=chessclock.garage.maemo.org")); +} + +void ChessClockWindow::about() +{ + pause(); + QMessageBox::about(this, tr("About ChessClock"), + tr("

Chess Clock %1

" + "©Arto Hyvättinen 2010" + "

Chess Clock is free software under the terms of GNU General Public License 3" + "

Bugtracker and instructions at http://chessclock.garage.maemo.org" + ).arg(qApp->applicationVersion())) ; } +void ChessClockWindow::aboutQt() +{ + pause(); + qApp->aboutQt(); +} + + +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 ) + { + + clocks_ = newWidget; + stack_->addWidget(clocks_); + stack_->setCurrentWidget(clocks_); + } +} + + ChessClockWindow::~ChessClockWindow() {