Started ChessClock::updateTimer_ in begin of turn
authorArto Hyvättinen <arto.hyvattinen@gmail.com>
Fri, 13 Aug 2010 23:17:47 +0000 (02:17 +0300)
committerArto Hyvättinen <arto.hyvattinen@gmail.com>
Fri, 13 Aug 2010 23:17:47 +0000 (02:17 +0300)
Application Name and version set.
Window icon and title set.

chessclock.qrc
chessclockwindow.cpp
classes/chessclock.cpp
classes/chessclock.h
classes/chessclockwidget.cpp
main.cpp
misc/template.txt~ [deleted file]

index aefab1b..d0d6d4f 100644 (file)
@@ -5,5 +5,6 @@
         <file>pic/loser.png</file>
         <file>pic/white_blue.png</file>
         <file>pic/white_gray.png</file>
+        <file>pic/chessclock.png</file>
     </qresource>
 </RCC>
index a75cccf..017819d 100644 (file)
 
 #include "classes/chessclockwidget.h"
 
+#include <QIcon>
+#include <QApplication>
+
 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();
 
 }
 
index 896f654..d3b169a 100644 (file)
@@ -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
index 4504061..d9f599f 100644 (file)
@@ -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:    
 
index 6dbcc8a..46fff39 100644 (file)
@@ -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()));
 
index e369fe1..dab223c 100644 (file)
--- a/main.cpp
+++ b/main.cpp
 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 (file)
index b28741e..0000000
+++ /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.
-
-
-**************************************************************************/