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.
This commit is contained in:
Olivier Teulière 2013-01-14 15:55:00 +01:00
parent d9ee0633db
commit 6f2ee6f9ff
2 changed files with 24 additions and 6 deletions

View file

@ -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();
}
}

View file

@ -23,6 +23,7 @@
#include <string>
#include <QtGui/QValidator>
#include <QtGui/QPalette>
#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!