Screen will turn black after 30 min
[chessclock] / classes / chessclock.cpp
index 308d82d..aedf531 100644 (file)
@@ -24,6 +24,7 @@
 #include "turninformation.h"
 
 const int ChessClock::UPDATEINTERVAL;
+const int ChessClock::DONTEATBATTERYTIME;
 
 ChessClock::ChessClock(bool white, QWidget *parent) :
     QWidget(parent)
@@ -31,9 +32,11 @@ ChessClock::ChessClock(bool white, QWidget *parent) :
     isWhite_ = white;
     loser_ = false;
     turn_ = 0;
+    dontEatBatteryEmitted_ = false;
     timePlayedBeforeTurn_ = 0;
     status_ = NotRunning;
     another_ = 0;
+    currentTurn_ = 0;
 
     // Set clock timer calculating played time
     clockTime_.start();
@@ -46,6 +49,7 @@ ChessClock::ChessClock(bool white, QWidget *parent) :
 void ChessClock::startTurn()
 {
     turn_++;
+    dontEatBatteryEmitted_ = false;
 
     // Turn information for this new turn
     currentTurn_ = new TurnInformation(turn_, isWhite_);
@@ -80,19 +84,22 @@ void ChessClock::continueTurn()
 TurnInformation* ChessClock::endTurn()
 {
     updateTimer_.stop();
+    status_ = NotRunning;
+
+    updateClock();
     // Count time played
     timePlayedBeforeTurn_ = getTimePlayed();
+
     // Count time available
     // This update current turn
     timeAvailableBeforeTurn_ = getTimeAvailable();
 
-    status_ = NotRunning;
-    updateClock();
 
     // Close and return turn information
     currentTurn_->turnReady(timeAvailableBeforeTurn_ );
     TurnInformation* information = currentTurn_;
     currentTurn_ = 0;
+
     emit turnEnded();
     return information;
 }
@@ -118,11 +125,7 @@ int ChessClock::getTimeAvailable()
 
 int ChessClock::getTimePlayed()
 {
-    // Count time played time
-    if( currentTurn_ )
-        return timePlayedBeforeTurn_ + currentTurnPlayed();
-    else
-        return timePlayedBeforeTurn_;
+     return timePlayedBeforeTurn_ + currentTurnPlayed();
 }
 
 
@@ -143,8 +146,18 @@ int ChessClock::currentTurnPlayed()
     {
         // Update current time
         if( status_ == Running )
+        {
             currentTurn_->addTime( clockTime_.restart());
 
+            // since 1.1.2
+            // emit dontEatBattery signal when screen should not to be keeped on
+            if ( currentTurn_->getDuration() > DONTEATBATTERYTIME  && dontEatBatteryEmitted_ == false )
+            {
+                dontEatBatteryEmitted_ = true;
+                emit dontEatBattery();
+            }
+        }
+
         // Return current time
         return currentTurn_->getDuration();
      }