X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=chessclockwindow.cpp;h=ab903b7a74df372851083abf5877cfe31ce4bffc;hb=dd1e46c462d5955488f29756d2dc7cb5670c1125;hp=c1715f11c74644a9775af829482aa4bed493f351;hpb=cfcfb018dce39cd48eda0f601aa5134632a50484;p=chessclock diff --git a/chessclockwindow.cpp b/chessclockwindow.cpp index c1715f1..ab903b7 100644 --- a/chessclockwindow.cpp +++ b/chessclockwindow.cpp @@ -25,6 +25,7 @@ #include "classes/chessclockwidget.h" #include "classes/startwidget.h" #include "classes/timecontrol.h" +#include "classes/turninformation.h" // Time controls #include "classes/timecontrol/notimecontrol.h" @@ -39,11 +40,15 @@ #include #include #include +#include + ChessClockWindow::ChessClockWindow(QWidget *parent) : QMainWindow(parent) { + showFullScreen(); + setWindowIcon( QIcon(":/rc/pic/chessclock.png")); setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) ); @@ -60,10 +65,19 @@ ChessClockWindow::ChessClockWindow(QWidget *parent) connect( start_, SIGNAL(selected(TimeControl*)), this, SLOT(startGame(TimeControl*))); + // Set up menu - menuBar()->addAction( tr("Pause"), this, SLOT(pause())); +// menuBar()->addAction( tr("Pause"), this, SLOT(pause())); // UNUSED - Pause button menuBar()->addAction( tr("New game"), this, SLOT(newGame())); + menuBar()->addAction( tr("Visit web page"), this, SLOT(visitWeb())); + menuBar()->addAction( tr("About"),this, SLOT(about())); + menuBar()->addAction(tr("About Qt"), this, SLOT(aboutQt())); + + //set the event filter to grap window deactivate + + installEventFilter(this); + } void ChessClockWindow::pause() @@ -76,7 +90,7 @@ void ChessClockWindow::newGame() { pause(); if( clocks_ == 0 || !clocks_->isPlayStarted() || QMessageBox::question(this, tr("Start new game"), - tr("Really quit current game and start new one with current settings?"), + tr("Really quit the current game and start a new one?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { stack_->setCurrentWidget(start_); @@ -89,6 +103,31 @@ void ChessClockWindow::newGame() } } +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 ); @@ -104,14 +143,11 @@ void ChessClockWindow::startGame(TimeControl *timecontrol) ClocksWidget* newWidget = timecontrol->initGame(false); if( newWidget ) { - if( clocks_ ) - { - stack_->removeWidget(clocks_); - delete clocks_; - } + clocks_ = newWidget; stack_->addWidget(clocks_); stack_->setCurrentWidget(clocks_); + connect( clocks_, SIGNAL(TurnFinished(TurnInformation*)), this, SLOT(dontEatMemory(TurnInformation*))); } } @@ -120,3 +156,19 @@ ChessClockWindow::~ChessClockWindow() { } + +bool ChessClockWindow::eventFilter(QObject *obj, QEvent *event) +{ + if (event->type() == QEvent::WindowDeactivate) { + pause(); + return QObject::eventFilter(obj,event); + } else { + // standard event processing + return QObject::eventFilter(obj, event); + } +} + +void ChessClockWindow::dontEatMemory(TurnInformation *turnInformation) +{ + delete turnInformation; // hopefully don't cause Segematation Fault +}