From dc84f85f79d52ecf39e032289306ee97adf5e083 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Arto=20Hyv=C3=A4ttinen?= Date: Sat, 14 Aug 2010 02:17:47 +0300 Subject: [PATCH] Started ChessClock::updateTimer_ in begin of turn Application Name and version set. Window icon and title set. --- chessclock.qrc | 1 + chessclockwindow.cpp | 7 +++++++ classes/chessclock.cpp | 17 ++++++++++++++++- classes/chessclock.h | 6 ++++++ classes/chessclockwidget.cpp | 2 +- main.cpp | 4 ++++ misc/template.txt~ | 21 --------------------- 7 files changed, 35 insertions(+), 23 deletions(-) delete mode 100644 misc/template.txt~ diff --git a/chessclock.qrc b/chessclock.qrc index aefab1b..d0d6d4f 100644 --- a/chessclock.qrc +++ b/chessclock.qrc @@ -5,5 +5,6 @@ pic/loser.png pic/white_blue.png pic/white_gray.png + pic/chessclock.png diff --git a/chessclockwindow.cpp b/chessclockwindow.cpp index a75cccf..017819d 100644 --- a/chessclockwindow.cpp +++ b/chessclockwindow.cpp @@ -23,12 +23,19 @@ #include "classes/chessclockwidget.h" +#include +#include + ChessClockWindow::ChessClockWindow(QWidget *parent) : QMainWindow(parent) { + setWindowIcon( QIcon(":/rc/pic/chessclock.png")); + setWindowTitle( QString("%1 %2").arg(qApp->applicationName()).arg(qApp->applicationVersion()) ); + ChessClockWidget* widget = new ChessClockWidget(true, this); setCentralWidget(widget); + widget->startTurn(); } diff --git a/classes/chessclock.cpp b/classes/chessclock.cpp index 896f654..d3b169a 100644 --- a/classes/chessclock.cpp +++ b/classes/chessclock.cpp @@ -40,7 +40,7 @@ ChessClock::ChessClock(bool white, QWidget *parent) : // Set updating timer updateTimer_.setInterval( UPDATEINTERVAL ); - connect( &updateTimer_, SIGNAL(timeout),this,SLOT(updateClock())); + connect( &updateTimer_, SIGNAL(timeout()),this,SLOT(updateClock())); } void ChessClock::startTurn() @@ -50,6 +50,7 @@ void ChessClock::startTurn() // Turn information for this new turn currentTurn_ = new TurnInformation(turn_, isWhite_); clockTime_.restart(); + updateTimer_.start(); status_=Running; // Repaint clock @@ -58,6 +59,7 @@ void ChessClock::startTurn() void ChessClock::pauseTurn() { + updateTimer_.stop(); // Update turn time currentTurn_->addTime( clockTime_.restart() ); status_ = Paused; @@ -70,6 +72,7 @@ void ChessClock::continueTurn() // Add pause duration to information object currentTurn_->addPause( clockTime_.restart() ); status_ = Running; + updateTimer_.start(); updateClock(); } @@ -77,6 +80,7 @@ void ChessClock::continueTurn() TurnInformation* ChessClock::endTurn() { status_ = NotRunning; + updateTimer_.stop(); // Update turn time currentTurn_->addTime( clockTime_.restart()); // Count time played @@ -89,6 +93,7 @@ TurnInformation* ChessClock::endTurn() currentTurn_->turnReady(timeAvailableBeforeTurn_ ); TurnInformation* information = currentTurn_; currentTurn_ = 0; + emit endTurn(); return information; } @@ -102,7 +107,11 @@ int ChessClock::getTimeAvailable() // Most simple - will be overwritten in more complex time controls: // subtract duration time! if( currentTurn_) + { + // Update turn time + currentTurn_->addTime( clockTime_.restart()); return timeAvailableBeforeTurn_-currentTurn_->getDuration(); + } else return timeAvailableBeforeTurn_; } @@ -117,6 +126,12 @@ int ChessClock::getTimePlayed() const return timePlayedBeforeTurn_; } + +void ChessClock::setTimeAvailable(int msecs) +{ + timeAvailableBeforeTurn_ = msecs; +} + void ChessClock::updateClock() { // Check loser diff --git a/classes/chessclock.h b/classes/chessclock.h index 4504061..d9f599f 100644 --- a/classes/chessclock.h +++ b/classes/chessclock.h @@ -89,9 +89,15 @@ public: @return Time played in msecs */ virtual int getTimePlayed() const; + /*! Set time available + + @param msecs Time available in msecs */ + void setTimeAvailable(int msecs); + signals: void timeOutLoser(); + void endTurn(); public slots: diff --git a/classes/chessclockwidget.cpp b/classes/chessclockwidget.cpp index 6dbcc8a..46fff39 100644 --- a/classes/chessclockwidget.cpp +++ b/classes/chessclockwidget.cpp @@ -134,7 +134,7 @@ void ChessClockWidget::repaintClock() timeAverage = 0; else timeAverage = getTimePlayed() / getTurn(); - timeAverageLabel_->setText( tr("Average %1 per turn").arg( timeString( timeAverage ) ) ); + timeAverageLabel_->setText( tr("Avg %1").arg( timeString( timeAverage ) ) ); turnLabel_->setText( tr("Turn %1").arg(getTurn())); diff --git a/main.cpp b/main.cpp index e369fe1..dab223c 100644 --- a/main.cpp +++ b/main.cpp @@ -53,7 +53,11 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); + a.setApplicationName( a.tr("Chess Clock","Application name") ); + a.setApplicationVersion("0.1.0"); + ChessClockWindow w; + #if defined(Q_WS_S60) w.showMaximized(); #else diff --git a/misc/template.txt~ b/misc/template.txt~ deleted file mode 100644 index b28741e..0000000 --- a/misc/template.txt~ +++ /dev/null @@ -1,21 +0,0 @@ - -/************************************************************************** - - Chess Clock - - Copyright (c) Arto Hyvättinen 2010 - - This file is part of Chess Clock software. - - Chess Clock is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Chess Clock is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - -**************************************************************************/ -- 1.7.9.5