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"
28 #include "classes/turninformation.h"
31 #include "classes/timecontrol/notimecontrol.h"
32 #include "classes/timecontrol/fischertimecontrol.h"
33 #include "classes/timecontrol/fischeraftertimecontrol.h"
34 #include "classes/timecontrol/delaytimecontrol.h"
35 #include "classes/timecontrol/delayaftertimecontrol.h"
36 #include "classes/timecontrol/hourglasstimecontrol.h"
39 #include <QApplication>
41 #include <QMessageBox>
42 #include <QStackedWidget>
46 ChessClockWindow::ChessClockWindow(QWidget *parent)
52 setWindowIcon( QIcon(":/rc/pic/chessclock.png"));
53 setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) );
55 // Start widget to select time control
56 start_ = new StartWidget;
61 stack_ = new QStackedWidget;
62 stack_->addWidget(start_);
64 setCentralWidget( stack_ );
66 connect( start_, SIGNAL(selected(TimeControl*)), this, SLOT(startGame(TimeControl*)));
70 // menuBar()->addAction( tr("Pause"), this, SLOT(pause())); // UNUSED - Pause button
71 menuBar()->addAction( tr("New game"), this, SLOT(newGame()));
73 menuBar()->addAction( tr("Visit web page"), this, SLOT(visitWeb()));
74 menuBar()->addAction( tr("About"),this, SLOT(about()));
75 menuBar()->addAction(tr("About Qt"), this, SLOT(aboutQt()));
77 //set the event filter to grap window deactivate
79 installEventFilter(this);
83 void ChessClockWindow::pause()
89 void ChessClockWindow::newGame()
92 if( clocks_ == 0 || !clocks_->isPlayStarted() || QMessageBox::question(this, tr("Start new game"),
93 tr("Really quit the current game and start a new one?"),
94 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
96 stack_->setCurrentWidget(start_);
99 { stack_->removeWidget(clocks_);
106 void ChessClockWindow::visitWeb()
109 QProcess* process = new QProcess(this);
110 process->start(QString("browser --url=chessclock.garage.maemo.org"));
113 void ChessClockWindow::about()
116 QMessageBox::about(this, tr("About ChessClock"),
117 tr("<h1>Chess Clock %1</h1>"
118 "©Arto Hyvättinen 2010"
119 "<p>Chess Clock is free software under the terms of GNU General Public License 3"
120 "<p>Bugtracker and instructions at <a>http://chessclock.garage.maemo.org</a>"
121 ).arg(qApp->applicationVersion())) ;
124 void ChessClockWindow::aboutQt()
131 void ChessClockWindow::initTimeControls()
133 start_->addTimeControl( new NoTimeControl );
134 start_->addTimeControl( new FischerTimeControl);
135 start_->addTimeControl( new FischerAfterTimeControl);
136 start_->addTimeControl( new DelayTimeControl );
137 start_->addTimeControl( new DelayAfterTimeControl);
138 start_->addTimeControl( new HourGlassTimeControl);
141 void ChessClockWindow::startGame(TimeControl *timecontrol)
143 ClocksWidget* newWidget = timecontrol->initGame(false);
148 stack_->addWidget(clocks_);
149 stack_->setCurrentWidget(clocks_);
150 connect( clocks_, SIGNAL(TurnFinished(TurnInformation*)), this, SLOT(dontEatMemory(TurnInformation*)));
155 ChessClockWindow::~ChessClockWindow()
160 bool ChessClockWindow::eventFilter(QObject *obj, QEvent *event)
162 if (event->type() == QEvent::WindowDeactivate) {
164 return QObject::eventFilter(obj,event);
166 // standard event processing
167 return QObject::eventFilter(obj, event);
171 void ChessClockWindow::dontEatMemory(TurnInformation *turnInformation)
173 delete turnInformation; // hopefully don't cause Segematation Fault