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!