From 6f2ee6f9ff7e9747c1414d5f5c3db9a365a623a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Mon, 14 Jan 2013 15:55:00 +0100 Subject: [PATCH] PlayWordMediator: improve the handling of words in Intermediate state. The syntactically invalid words (such as those without matching parens) are displayed in red, and do not trigger un update of the PlayModel. As a result, the letters do not disappear from the preview anymore when the opening parenthesis of a blank tile is typed. --- qt/play_word_mediator.cpp | 22 ++++++++++++++++------ qt/play_word_mediator.h | 8 ++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/qt/play_word_mediator.cpp b/qt/play_word_mediator.cpp index 16a4b8e..6dbe6a1 100644 --- a/qt/play_word_mediator.cpp +++ b/qt/play_word_mediator.cpp @@ -45,6 +45,10 @@ PlayWordMediator::PlayWordMediator(QObject *parent, QLineEdit &iEditPlay, { SetTooltips(m_lineEditPlay, m_lineEditCoord); + blackPalette = m_lineEditPlay.palette(); + redPalette = m_lineEditPlay.palette(); + redPalette.setColor(QPalette::Text, Qt::red); + /// Set validators; if (m_game) { @@ -170,13 +174,19 @@ void PlayWordMediator::onCoordChanged() void PlayWordMediator::onWordChanged() { - wstring playedWord; - GetPlayedWord(m_lineEditPlay, m_game->getDic(), &playedWord, NULL); + bool acceptableInput = m_lineEditPlay.hasAcceptableInput(); + m_lineEditPlay.setPalette(acceptableInput ? blackPalette : redPalette); - Move move; - m_game->checkPlayedWord(playedWord, wfq(m_lineEditCoord.text()), move); - m_playModel.setMove(move); - updatePointsAndState(); + if (acceptableInput) + { + wstring playedWord; + GetPlayedWord(m_lineEditPlay, m_game->getDic(), &playedWord, NULL); + + Move move; + m_game->checkPlayedWord(playedWord, wfq(m_lineEditCoord.text()), move); + m_playModel.setMove(move); + updatePointsAndState(); + } } diff --git a/qt/play_word_mediator.h b/qt/play_word_mediator.h index da685a9..68710bc 100644 --- a/qt/play_word_mediator.h +++ b/qt/play_word_mediator.h @@ -23,6 +23,7 @@ #include #include +#include #include "logging.h" @@ -102,6 +103,13 @@ private: QPushButton &m_pushButtonPlay; PlayModel &m_playModel; + /// Palette to write text in black + QPalette blackPalette; + + /// Palette to write text in red + QPalette redPalette; + + /** * Wrapper around GetPlayedWord(), more practical to use. * But it should be called only for a valid input!