00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "chessclockwindow.h"
00023
00024 #include "classes/clockswidget.h"
00025 #include "classes/chessclockwidget.h"
00026 #include "classes/startwidget.h"
00027 #include "classes/timecontrol.h"
00028
00029
00030 #include "classes/timecontrol/notimecontrol.h"
00031 #include "classes/timecontrol/fischertimecontrol.h"
00032 #include "classes/timecontrol/fischeraftertimecontrol.h"
00033 #include "classes/timecontrol/delaytimecontrol.h"
00034 #include "classes/timecontrol/delayaftertimecontrol.h"
00035 #include "classes/timecontrol/hourglasstimecontrol.h"
00036
00037 #include <QIcon>
00038 #include <QApplication>
00039 #include <QMenuBar>
00040 #include <QMessageBox>
00041 #include <QStackedWidget>
00042 #include <QProcess>
00043
00044
00045 ChessClockWindow::ChessClockWindow(QWidget *parent)
00046 : QMainWindow(parent)
00047 {
00048
00049 setWindowIcon( QIcon(":/rc/pic/chessclock.png"));
00050 setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) );
00051
00052
00053 start_ = new StartWidget;
00054 clocks_ = 0;
00055
00056 initTimeControls();
00057
00058 stack_ = new QStackedWidget;
00059 stack_->addWidget(start_);
00060
00061 setCentralWidget( stack_ );
00062
00063 connect( start_, SIGNAL(selected(TimeControl*)), this, SLOT(startGame(TimeControl*)));
00064
00065
00066
00067
00068 menuBar()->addAction( tr("New game"), this, SLOT(newGame()));
00069
00070 menuBar()->addAction( tr("Visit web page"), this, SLOT(visitWeb()));
00071 menuBar()->addAction( tr("About"),this, SLOT(about()));
00072 menuBar()->addAction(tr("About Qt"), this, SLOT(aboutQt()));
00073
00074 }
00075
00076 void ChessClockWindow::pause()
00077 {
00078 if( clocks_ )
00079 clocks_->pause();
00080 }
00081
00082 void ChessClockWindow::newGame()
00083 {
00084 pause();
00085 if( clocks_ == 0 || !clocks_->isPlayStarted() || QMessageBox::question(this, tr("Start new game"),
00086 tr("Really quit the current game and start a new one?"),
00087 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
00088 {
00089 stack_->setCurrentWidget(start_);
00090
00091 if( clocks_ )
00092 { stack_->removeWidget(clocks_);
00093 delete clocks_;
00094 }
00095 clocks_=0;
00096 }
00097 }
00098
00099 void ChessClockWindow::visitWeb()
00100 {
00101 pause();
00102 QProcess* process = new QProcess(this);
00103 process->start(QString("browser --url=chessclock.garage.maemo.org"));
00104 }
00105
00106 void ChessClockWindow::about()
00107 {
00108 pause();
00109 QMessageBox::about(this, tr("About ChessClock"),
00110 tr("<h1>Chess Clock %1</h1>"
00111 "©Arto Hyvättinen 2010"
00112 "<p>Chess Clock is free software under the terms of GNU General Public License 3"
00113 "<p>Bugtracker and instructions at <a>http://chessclock.garage.maemo.org</a>"
00114 ).arg(qApp->applicationVersion())) ;
00115 }
00116
00117 void ChessClockWindow::aboutQt()
00118 {
00119 pause();
00120 qApp->aboutQt();
00121 }
00122
00123
00124 void ChessClockWindow::initTimeControls()
00125 {
00126 start_->addTimeControl( new NoTimeControl );
00127 start_->addTimeControl( new FischerTimeControl);
00128 start_->addTimeControl( new FischerAfterTimeControl);
00129 start_->addTimeControl( new DelayTimeControl );
00130 start_->addTimeControl( new DelayAfterTimeControl);
00131 start_->addTimeControl( new HourGlassTimeControl);
00132 }
00133
00134 void ChessClockWindow::startGame(TimeControl *timecontrol)
00135 {
00136 ClocksWidget* newWidget = timecontrol->initGame(false);
00137 if( newWidget )
00138 {
00139
00140 clocks_ = newWidget;
00141 stack_->addWidget(clocks_);
00142 stack_->setCurrentWidget(clocks_);
00143 }
00144 }
00145
00146
00147 ChessClockWindow::~ChessClockWindow()
00148 {
00149
00150 }