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()));
68 menuBar()->addAction( tr("About"),this, SLOT(about()));
69 menuBar()->addAction(tr("About Qt"), this, SLOT(aboutQt()));
73 void ChessClockWindow::pause()
79 void ChessClockWindow::newGame()
82 if( clocks_ == 0 || !clocks_->isPlayStarted() || QMessageBox::question(this, tr("Start new game"),
83 tr("Really quit current game and start new one with current settings?"),
84 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
86 stack_->setCurrentWidget(start_);
89 { stack_->removeWidget(clocks_);
96 void ChessClockWindow::visitWeb()
99 QProcess* process = new QProcess(this);
100 process->start(QString("browser --url=chessclock.garage.maemo.org"));
103 void ChessClockWindow::about()
106 QMessageBox::about(this, tr("About ChessClock"),
107 tr("<h1>Chess Clock %1</h1>"
108 "©Arto Hyvättinen 2010"
109 "<p>Chess Clock is free software under the terms of GNU General Public License 3"
110 "<p>Bugtracker and instructions at <a>http://chessclock.garage.maemo.org</a>"
111 ).arg(qApp->applicationVersion())) ;
114 void ChessClockWindow::aboutQt()
121 void ChessClockWindow::initTimeControls()
123 start_->addTimeControl( new NoTimeControl );
124 start_->addTimeControl( new FischerTimeControl);
125 start_->addTimeControl( new FischerAfterTimeControl);
126 start_->addTimeControl( new DelayTimeControl );
127 start_->addTimeControl( new DelayAfterTimeControl);
128 start_->addTimeControl( new HourGlassTimeControl);
131 void ChessClockWindow::startGame(TimeControl *timecontrol)
133 ClocksWidget* newWidget = timecontrol->initGame(false);
138 stack_->addWidget(clocks_);
139 stack_->setCurrentWidget(clocks_);
144 ChessClockWindow::~ChessClockWindow()