X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=www%2Fhtml%2Fchessclock_8cpp_source.html;fp=www%2Fhtml%2Fchessclock_8cpp_source.html;h=a9417ccad77bef653d7378b2b305b5545c7ff8c5;hb=d145b92ee23ef361bbfd91eef606cfc3ed9994fa;hp=faf52c18fd18df31749e588f363eae16ac8f1c1d;hpb=e43c493689b3e5a28625a293f811a888bd5042e8;p=chessclock diff --git a/www/html/chessclock_8cpp_source.html b/www/html/chessclock_8cpp_source.html index faf52c1..a9417cc 100644 --- a/www/html/chessclock_8cpp_source.html +++ b/www/html/chessclock_8cpp_source.html @@ -68,151 +68,164 @@ var searchBox = new SearchBox("searchBox", "search",false,'Search'); 00024 #include "turninformation.h" 00025 00026 const int ChessClock::UPDATEINTERVAL; -00027 -00028 ChessClock::ChessClock(bool white, QWidget *parent) : -00029 QWidget(parent) -00030 { -00031 isWhite_ = white; -00032 loser_ = false; -00033 turn_ = 0; -00034 timePlayedBeforeTurn_ = 0; -00035 status_ = NotRunning; -00036 another_ = 0; -00037 currentTurn_ = 0; -00038 -00039 // Set clock timer calculating played time -00040 clockTime_.start(); -00041 -00042 // Set updating timer -00043 updateTimer_.setInterval( UPDATEINTERVAL ); -00044 connect( &updateTimer_, SIGNAL(timeout()),this,SLOT(updateClock())); -00045 } -00046 -00047 void ChessClock::startTurn() -00048 { -00049 turn_++; -00050 -00051 // Turn information for this new turn -00052 currentTurn_ = new TurnInformation(turn_, isWhite_); -00053 clockTime_.restart(); -00054 updateTimer_.start(); -00055 status_=Running; -00056 -00057 // Repaint clock -00058 updateClock(); -00059 } -00060 -00061 void ChessClock::pauseTurn() -00062 { -00063 updateTimer_.stop(); -00064 // Update turn time -00065 currentTurn_->addTime( clockTime_.restart() ); -00066 status_ = Paused; -00067 updateClock(); -00068 } -00069 -00070 void ChessClock::continueTurn() -00071 { -00072 // Continue paused game -00073 // Add pause duration to information object -00074 currentTurn_->addPause( clockTime_.restart() ); -00075 status_ = Running; -00076 updateTimer_.start(); -00077 updateClock(); -00078 } -00079 -00080 -00081 TurnInformation* ChessClock::endTurn() -00082 { -00083 updateTimer_.stop(); -00084 status_ = NotRunning; -00085 -00086 updateClock(); -00087 // Count time played -00088 timePlayedBeforeTurn_ = getTimePlayed(); -00089 -00090 // Count time available -00091 // This update current turn -00092 timeAvailableBeforeTurn_ = getTimeAvailable(); -00093 -00094 -00095 // Close and return turn information -00096 currentTurn_->turnReady(timeAvailableBeforeTurn_ ); -00097 TurnInformation* information = currentTurn_; -00098 currentTurn_ = 0; -00099 -00100 emit turnEnded(); -00101 return information; -00102 } -00103 -00104 void ChessClock::setAnother(ChessClock *another) -00105 { -00106 another_ = another; -00107 } -00108 -00109 int ChessClock::getTimeAvailable() -00110 { -00111 // Most simple - will be overwritten in more complex time controls: -00112 // subtract duration time! -00113 if( currentTurn_) -00114 { -00115 // Update turn time -00116 return timeAvailableBeforeTurn_-currentTurnPlayed(); -00117 } -00118 else -00119 return timeAvailableBeforeTurn_; -00120 } -00121 -00122 -00123 int ChessClock::getTimePlayed() -00124 { -00125 return timePlayedBeforeTurn_ + currentTurnPlayed(); -00126 } -00127 -00128 -00129 void ChessClock::setTimeAvailable(int msecs) -00130 { -00131 timeAvailableBeforeTurn_ = msecs; -00132 } -00133 -00134 -00135 void ChessClock::addTime(int msecs) -00136 { -00137 timeAvailableBeforeTurn_ += msecs; -00138 } -00139 -00140 int ChessClock::currentTurnPlayed() -00141 { -00142 if( currentTurn_ ) -00143 { -00144 // Update current time -00145 if( status_ == Running ) -00146 currentTurn_->addTime( clockTime_.restart()); -00147 -00148 // Return current time -00149 return currentTurn_->getDuration(); -00150 } -00151 else -00152 // No current turn! -00153 return 0; -00154 } -00155 -00156 void ChessClock::updateClock() -00157 { -00158 // Check loser -00159 if( another_ && !another_->isLoser()) -00160 { -00161 if( getTimeAvailable() < 0 && !loser_) -00162 { -00163 loser_ = true; -00164 emit timeOutLoser(); -00165 } -00166 -00167 } -00168 repaintClock(); -00169 -00170 } -00171 +00027 const int ChessClock::DONTEATBATTERYTIME; +00028 +00029 ChessClock::ChessClock(bool white, QWidget *parent) : +00030 QWidget(parent) +00031 { +00032 isWhite_ = white; +00033 loser_ = false; +00034 turn_ = 0; +00035 dontEatBatteryEmitted_ = false; +00036 timePlayedBeforeTurn_ = 0; +00037 status_ = NotRunning; +00038 another_ = 0; +00039 currentTurn_ = 0; +00040 +00041 // Set clock timer calculating played time +00042 clockTime_.start(); +00043 +00044 // Set updating timer +00045 updateTimer_.setInterval( UPDATEINTERVAL ); +00046 connect( &updateTimer_, SIGNAL(timeout()),this,SLOT(updateClock())); +00047 } +00048 +00049 void ChessClock::startTurn() +00050 { +00051 turn_++; +00052 dontEatBatteryEmitted_ = false; +00053 +00054 // Turn information for this new turn +00055 currentTurn_ = new TurnInformation(turn_, isWhite_); +00056 clockTime_.restart(); +00057 updateTimer_.start(); +00058 status_=Running; +00059 +00060 // Repaint clock +00061 updateClock(); +00062 } +00063 +00064 void ChessClock::pauseTurn() +00065 { +00066 updateTimer_.stop(); +00067 // Update turn time +00068 currentTurn_->addTime( clockTime_.restart() ); +00069 status_ = Paused; +00070 updateClock(); +00071 } +00072 +00073 void ChessClock::continueTurn() +00074 { +00075 // Continue paused game +00076 // Add pause duration to information object +00077 currentTurn_->addPause( clockTime_.restart() ); +00078 status_ = Running; +00079 updateTimer_.start(); +00080 updateClock(); +00081 } +00082 +00083 +00084 TurnInformation* ChessClock::endTurn() +00085 { +00086 updateTimer_.stop(); +00087 status_ = NotRunning; +00088 +00089 updateClock(); +00090 // Count time played +00091 timePlayedBeforeTurn_ = getTimePlayed(); +00092 +00093 // Count time available +00094 // This update current turn +00095 timeAvailableBeforeTurn_ = getTimeAvailable(); +00096 +00097 +00098 // Close and return turn information +00099 currentTurn_->turnReady(timeAvailableBeforeTurn_ ); +00100 TurnInformation* information = currentTurn_; +00101 currentTurn_ = 0; +00102 +00103 emit turnEnded(); +00104 return information; +00105 } +00106 +00107 void ChessClock::setAnother(ChessClock *another) +00108 { +00109 another_ = another; +00110 } +00111 +00112 int ChessClock::getTimeAvailable() +00113 { +00114 // Most simple - will be overwritten in more complex time controls: +00115 // subtract duration time! +00116 if( currentTurn_) +00117 { +00118 // Update turn time +00119 return timeAvailableBeforeTurn_-currentTurnPlayed(); +00120 } +00121 else +00122 return timeAvailableBeforeTurn_; +00123 } +00124 +00125 +00126 int ChessClock::getTimePlayed() +00127 { +00128 return timePlayedBeforeTurn_ + currentTurnPlayed(); +00129 } +00130 +00131 +00132 void ChessClock::setTimeAvailable(int msecs) +00133 { +00134 timeAvailableBeforeTurn_ = msecs; +00135 } +00136 +00137 +00138 void ChessClock::addTime(int msecs) +00139 { +00140 timeAvailableBeforeTurn_ += msecs; +00141 } +00142 +00143 int ChessClock::currentTurnPlayed() +00144 { +00145 if( currentTurn_ ) +00146 { +00147 // Update current time +00148 if( status_ == Running ) +00149 { +00150 currentTurn_->addTime( clockTime_.restart()); +00151 +00152 // since 1.1.2 +00153 // emit dontEatBattery signal when screen should not to be keeped on +00154 if ( currentTurn_->getDuration() > DONTEATBATTERYTIME && dontEatBatteryEmitted_ == false ) +00155 { +00156 dontEatBatteryEmitted_ = true; +00157 emit dontEatBattery(); +00158 } +00159 } +00160 +00161 // Return current time +00162 return currentTurn_->getDuration(); +00163 } +00164 else +00165 // No current turn! +00166 return 0; +00167 } +00168 +00169 void ChessClock::updateClock() +00170 { +00171 // Check loser +00172 if( another_ && !another_->isLoser()) +00173 { +00174 if( getTimeAvailable() < 0 && !loser_) +00175 { +00176 loser_ = true; +00177 emit timeOutLoser(); +00178 } +00179 +00180 } +00181 repaintClock(); +00182 +00183 } +00184
-
Generated on Mon Sep 27 18:30:33 2010 for Chess Clock by  +
Generated on Tue Oct 12 20:52:59 2010 for Chess Clock by  doxygen 1.6.3