Reset the timer when the current turn changes

This commit is contained in:
Olivier Teulière 2012-02-21 08:17:29 +01:00
parent 182263ce74
commit efb5fddf58
3 changed files with 20 additions and 3 deletions

View file

@ -76,7 +76,8 @@ MainWindow::MainWindow(QWidget *iParent)
m_playersWidget(NULL), m_trainingWidget(NULL), m_scoresWidget(NULL),
m_bagWindow(NULL), m_boardWindow(NULL),
m_historyWindow(NULL), m_timerWindow(NULL),
m_dicToolsWindow(NULL), m_dicNameLabel(NULL), m_timerModel(NULL)
m_dicToolsWindow(NULL), m_dicNameLabel(NULL), m_timerModel(NULL),
m_currentTurn(0)
{
#ifdef DEBUG
// Check that the string conversion routines are not buggy
@ -104,6 +105,9 @@ MainWindow::MainWindow(QWidget *iParent)
int timerTotal = qs.value(PrefsDialog::kINTF_TIMER_TOTAL_DURATION, 180).toInt();
int timerAlert = qs.value(PrefsDialog::kINTF_TIMER_ALERT_DURATION, 30).toInt();
m_timerModel = new TimerModel(timerTotal, timerAlert);
// Reset the timer when the turn changes
QObject::connect(this, SIGNAL(turnChanged(int, bool)),
m_timerModel, SLOT(resetTimer()));
// TODO: connect to some of the timer signals (alert() and expired())
QObject::connect(this, SIGNAL(gameChangedNonConst(PublicGame*)),
@ -231,8 +235,9 @@ void MainWindow::refresh()
.arg(bag.getNbConsonants())
.arg(bag.getNbVowels())
.arg(bag.in(Tile::Joker())));
unsigned currTurn = m_game->getCurrTurn();
m_turnLabel->setText(_q("Turn %1/%2")
.arg(m_game->getCurrTurn())
.arg(currTurn)
.arg(m_game->getNbTurns()));
bool isFirstTurn = m_game->isFirstTurn();
bool isLastTurn = m_game->isLastTurn();
@ -243,6 +248,12 @@ void MainWindow::refresh()
m_actionHistoryReplayTurn->setEnabled(!isLastTurn);
if (m_game->isFinished())
displayInfoMsg(_q("End of the game"));
// Emit the turnChanged() sign if needed.
if (currTurn != m_currentTurn)
{
m_currentTurn = currTurn;
emit turnChanged(currTurn, isLastTurn);
}
#ifdef DEBUG
//m_game->printTurns();
#endif

View file

@ -57,6 +57,7 @@ signals:
void gameChanged(const PublicGame *iGame);
void gameChangedNonConst(PublicGame *iGame);
void gameUpdated();
void turnChanged(int iCurrTurn, bool isLastTurn);
public slots:
/// Display an error message to the user
@ -176,6 +177,9 @@ private:
/// Model for the timer widgets
TimerModel *m_timerModel;
/// Last known turn number. Used to emit turnChanged().
unsigned m_currentTurn;
/// Save window state
void writeSettings() const;
/// Restore window state

View file

@ -51,11 +51,13 @@ public:
bool wasAlertTriggered() const { return m_alertTriggered; }
bool isExpired() const { return m_remaining == 0; }
bool isActiveTimer() const;
public slots:
// Timer handling
void startTimer();
void pauseTimer();
void resetTimer();
bool isActiveTimer() const;
signals:
void valueChanged(int iNewValue);