1 /**************************************************************************
5 Copyright (c) Arto Hyvättinen 2010
7 This file is part of Chess Clock software.
9 Chess Clock is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Chess Clock is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
20 **************************************************************************/
22 #include "chessclockwindow.h"
24 #include "classes/clockswidget.h"
25 #include "classes/chessclockwidget.h"
26 #include "classes/startwidget.h"
27 #include "classes/timecontrol.h"
30 #include "classes/timecontrol/notimecontrol.h"
31 #include "classes/timecontrol/fischertimecontrol.h"
32 #include "classes/timecontrol/fischeraftertimecontrol.h"
33 #include "classes/timecontrol/delaytimecontrol.h"
34 #include "classes/timecontrol/delayaftertimecontrol.h"
35 #include "classes/timecontrol/hourglasstimecontrol.h"
38 #include <QApplication>
40 #include <QMessageBox>
41 #include <QStackedWidget>
44 ChessClockWindow::ChessClockWindow(QWidget *parent)
48 setWindowIcon( QIcon(":/rc/pic/chessclock.png"));
49 setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) );
51 // Start widget to select time control
52 start_ = new StartWidget;
57 stack_ = new QStackedWidget;
58 stack_->addWidget(start_);
60 setCentralWidget( stack_ );
62 connect( start_, SIGNAL(selected(TimeControl*)), this, SLOT(startGame(TimeControl*)));
65 menuBar()->addAction( tr("Pause"), this, SLOT(pause()));
66 menuBar()->addAction( tr("New game"), this, SLOT(newGame()));
67 menuBar()->addAction( tr("Visit web page"), this, SLOT(visitWeb()));
71 void ChessClockWindow::pause()
77 void ChessClockWindow::newGame()
80 if( clocks_ == 0 || !clocks_->isPlayStarted() || QMessageBox::question(this, tr("Start new game"),
81 tr("Really quit current game and start new one with current settings?"),
82 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
84 stack_->setCurrentWidget(start_);
87 { stack_->removeWidget(clocks_);
94 void ChessClockWindow::visitWeb()
96 QProcess* process = new QProcess(this);
97 process->start(QString("browser --url=chessclock.garage.maemo.org"));
101 void ChessClockWindow::initTimeControls()
103 start_->addTimeControl( new NoTimeControl );
104 start_->addTimeControl( new FischerTimeControl);
105 start_->addTimeControl( new FischerAfterTimeControl);
106 start_->addTimeControl( new DelayTimeControl );
107 start_->addTimeControl( new DelayAfterTimeControl);
108 start_->addTimeControl( new HourGlassTimeControl);
111 void ChessClockWindow::startGame(TimeControl *timecontrol)
113 ClocksWidget* newWidget = timecontrol->initGame(false);
118 stack_->addWidget(clocks_);
119 stack_->setCurrentWidget(clocks_);
124 ChessClockWindow::~ChessClockWindow()