eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot dic/dic.cpp dic/dic.h dic/header.cpp dic/...


From: Olivier Teulière
Subject: [Eliot-dev] eliot dic/dic.cpp dic/dic.h dic/header.cpp dic/...
Date: Sat, 27 Jun 2009 18:09:44 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>       09/06/27 18:09:44

Modified files:
        dic            : dic.cpp dic.h header.cpp header.h 
        qt             : dic_tools_widget.cpp dic_tools_widget.h 
                         play_word_mediator.cpp player_widget.cpp 
                         training_widget.cpp training_widget.h 

Log message:
        Accept various inputs for the same tile in the Qt interface.
        The dictionary format still needs to support that.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.cpp?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.h?cvsroot=eliot&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.cpp?cvsroot=eliot&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.h?cvsroot=eliot&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_tools_widget.cpp?cvsroot=eliot&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/dic_tools_widget.h?cvsroot=eliot&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/play_word_mediator.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/player_widget.cpp?cvsroot=eliot&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/training_widget.cpp?cvsroot=eliot&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/training_widget.h?cvsroot=eliot&r1=1.6&r2=1.7

Patches:
Index: dic/dic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- dic/dic.cpp 22 Nov 2008 13:11:48 -0000      1.5
+++ dic/dic.cpp 27 Jun 2009 18:09:44 -0000      1.6
@@ -81,6 +81,11 @@
     std::transform(lower.begin(), lower.end(), lower.begin(), towlower);
     m_allLetters = m_header->getLetters() + lower;
 
+    // Same for the input characters
+    lower = m_header->getInputChars();
+    std::transform(lower.begin(), lower.end(), lower.begin(), towlower);
+    m_allInputChars = m_header->getInputChars() + lower;
+
     m_dic = this;
 }
 
@@ -124,6 +129,14 @@
 }
 
 
+bool Dictionary::validateInputChars(const wistring &iLetters,
+                                    const wistring &iAccepted) const
+{
+    return iLetters.empty()
+        || iLetters.find_first_not_of(m_allInputChars + iAccepted) == 
string::npos;
+}
+
+
 dic_elt_t Dictionary::getNext(const dic_elt_t &e) const
 {
      if (!isLast(e))

Index: dic/dic.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- dic/dic.h   23 Jun 2009 21:39:07 -0000      1.23
+++ dic/dic.h   27 Jun 2009 18:09:44 -0000      1.24
@@ -93,6 +93,15 @@
     bool validateLetters(const wstring &iLetters,
                          const wstring &iAccepted = L"") const;
 
+    /**
+     * Check whether all the given characters can be part of an input
+     * form for one or more dictionary letter, or are one of the other
+     * accepted letters.
+     * Return true if this is the case, false otherwise
+     */
+    bool validateInputChars(const wstring &iLetters,
+                            const wstring &iAccepted = L"") const;
+
     /** Return a vector containing one of each possible tile */
     const vector<Tile>& getAllTiles() const { return m_tilesVect; }
 
@@ -241,9 +250,18 @@
     Header *m_header;
     uint32_t *m_dawg;
 
-    /** Letters of the dictionary, both in uppercase and lowercase */
+    /**
+     * Letters of the dictionary, both in uppercase and lowercase
+     * (internal representation)
+     */
     wstring m_allLetters;
 
+    /**
+     * All the possible characters possibly used to input letters of
+     * the dictionary, both in uppercase and lowercase
+     */
+    wstring m_allInputChars;
+
     /// Vector of available tiles
     vector<Tile> m_tilesVect;
 

Index: dic/header.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/header.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- dic/header.cpp      23 Jun 2009 21:39:07 -0000      1.9
+++ dic/header.cpp      27 Jun 2009 18:09:44 -0000      1.10
@@ -211,6 +211,8 @@
     m_type = iInfo.dawg ? kDAWG : kGADDAG;
     m_dicName = iInfo.dicName;
     m_letters = iInfo.letters;
+    // FIXME: it should be more than that!
+    m_inputChars = iInfo.letters + L"<>|";
     m_points = iInfo.points;
     m_frequency = iInfo.frequency;
     m_vowels = iInfo.vowels;
@@ -281,6 +283,9 @@
     // we could simply return the given string without further processing.
     wdstring dispStr;
     dispStr.reserve(iWord.size());
+    // TODO: change the implementation, to avoid throwing an exception
+    // if there is a character not part of the dictionary (this can happen
+    // with regular expressions, at least...)
     for (unsigned int i = 0; i < iWord.size(); ++i)
     {
         const wdstring &chr = getDisplayStr(getCodeFromChar(iWord[i]));
@@ -369,6 +374,8 @@
     {
         throw DicException("Header::read: inconsistent header");
     }
+    // FIXME: it should be more than that!
+    m_inputChars = m_letters + L"<>|";
 
     // Letters points and frequency
     for (unsigned int i = 0; i < m_letters.size(); ++i)

Index: dic/header.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/header.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- dic/header.h        23 Jun 2009 21:39:07 -0000      1.7
+++ dic/header.h        27 Jun 2009 18:09:44 -0000      1.8
@@ -109,6 +109,7 @@
     wstring      getName()         const { return m_dicName; }
     DictType     getType()         const { return m_type; }
     wstring      getLetters()      const { return m_letters; }
+    wstring      getInputChars()   const { return m_inputChars; }
     uint8_t      getPoints(unsigned int iCode) const { return m_points[iCode - 
1]; }
     uint8_t      getFrequency(unsigned int iCode) const { return 
m_frequency[iCode - 1]; }
     bool         isVowel(unsigned int iCode) const { return m_vowels[iCode - 
1]; }
@@ -177,9 +178,12 @@
     /// Dictionary name (e.g.: ODS 5.0)
     wstring m_dicName;
 
-    /// The letters constituting the words of the dictionary
+    /// (Internal) letters constituting the words of the dictionary
     wstring m_letters;
 
+    /// Characters usable to input the dictionary letters
+    wstring m_inputChars;
+
     /// Points of the letters
     vector<uint8_t> m_points;
 

Index: qt/dic_tools_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_tools_widget.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- qt/dic_tools_widget.cpp     23 Jun 2009 17:07:17 -0000      1.8
+++ qt/dic_tools_widget.cpp     27 Jun 2009 18:09:44 -0000      1.9
@@ -22,6 +22,7 @@
 
 #include <map>
 #include <vector>
+#include <algorithm>
 #include <QtGui/QTreeView>
 #include <QtGui/QStandardItemModel>
 #include <QtGui/QVBoxLayout>
@@ -73,6 +74,8 @@
 
     redPalette = labelCheck->palette();
     redPalette.setColor(QPalette::Foreground, Qt::red);
+    darkYellowPalette = labelCheck->palette();
+    darkYellowPalette.setColor(QPalette::Foreground, Qt::darkYellow);
     greenPalette = labelCheck->palette();
     greenPalette.setColor(QPalette::Foreground, Qt::darkGreen);
 
@@ -147,9 +150,18 @@
         labelCheck->setText("");
     else
     {
-        bool res = m_dic->searchWord(qtw(rack->text()));
-        const wdstring &dispStr =
-            m_dic->getHeader().convertToDisplay(qtw(rack->text().toUpper()));
+        if (!rack->hasAcceptableInput())
+        {
+            labelCheck->setText(_q("Invalid or incomplete characters"));
+            labelCheck->setPalette(darkYellowPalette);
+            return;
+        }
+
+        wstring input = m_dic->getHeader().convertFromInput(qtw(rack->text()));
+        bool res = m_dic->searchWord(input);
+        // Convert the input to uppercase
+        std::transform(input.begin(), input.end(), input.begin(), towupper);
+        const wdstring &dispStr = m_dic->getHeader().convertToDisplay(input);
         if (res)
         {
             labelCheck->setText(_q("The word '%1' exists").arg(qfw(dispStr)));
@@ -178,17 +190,17 @@
                                Qt::DisplayRole);
         return;
     }
-    else
-    {
+
+    const wstring &input = 
m_dic->getHeader().convertFromInput(qtw(rack->text().toUpper()));
+    const wdstring &disp = m_dic->getHeader().convertToDisplay(input);
         model->setHeaderData(0, Qt::Horizontal,
-                               _q("Rack: %1").arg(rack->text().toUpper()),
+                         _q("Rack: %1").arg(qfw(disp)),
                                Qt::DisplayRole);
-    }
 
-    if (rack->text() != "")
+    if (input != L"")
     {
         map<wstring, vector<wstring> > wordList;
-        m_dic->search7pl1(qtw(rack->text()), wordList, true);
+        m_dic->search7pl1(input, wordList, true);
 
         int rowNum = 0;
         map<wstring, vector<wstring> >::const_iterator it;
@@ -231,14 +243,14 @@
                                Qt::DisplayRole);
         return;
     }
-    else
-    {
+
+    const wstring &input = 
m_dic->getHeader().convertFromInput(qtw(rack->text().toUpper()));
+    const wdstring &disp = m_dic->getHeader().convertToDisplay(input);
         model->setHeaderData(0, Qt::Horizontal,
-                               _q("Regular expression: 
%1").arg(rack->text().toUpper()),
+                         _q("Regular expression: %1").arg(qfw(disp)),
                                Qt::DisplayRole);
-    }
 
-    if (rack->text() != "")
+    if (input != L"")
     {
         unsigned lmin = spinBoxMinLength->value();
         unsigned lmax = spinBoxMaxLength->value();
@@ -250,8 +262,7 @@
         int rowNum = 0;
         try
         {
-            res = m_dic->searchRegExp(qtw(rack->text()), wordList,
-                                      lmin, lmax, limit);
+            res = m_dic->searchRegExp(input, wordList, lmin, lmax, limit);
         }
         catch (InvalidRegexpException &e)
         {
@@ -337,12 +348,19 @@
     if (input == "")
         return Intermediate;
 
-    //input = input.toUpper();
+    // The string is invalid if it contains invalid input characters
+    const wistring &winput = qtw(input);
+    if (!m_dic->validateInputChars(winput))
+        return Invalid;
 
+    // Convert the string to internal letters
+    const wstring &intInput = m_dic->getHeader().convertFromInput(winput);
     // The string is invalid if it contains characters not present
-    // in the dictionary or if it contains a '?'
-    if (!m_dic->validateLetters(qtw(input)))
-        return Invalid;
+    // in the dictionary
+    if (!m_dic->validateLetters(intInput))
+        return Intermediate;
+
+    // A '?' may not be acceptable
     if (!m_acceptJoker && input.contains('?'))
         return Invalid;
     // Do not accept more than 2 jokers
@@ -368,18 +386,20 @@
     if (input == "")
         return Intermediate;
 
-    // Strip regular expression characters
-    QString copy(input);
-    QString authorizedChars = ".[]()*+?:^";
-    for (int i = 0; i < authorizedChars.size(); ++i)
-    {
-        copy.remove(authorizedChars[i]);
-    }
+    wstring authorizedChars = L".[]()*+?:^";
+
+    // The string is invalid if it contains invalid input characters
+    const wistring &winput = qtw(input);
+    if (!m_dic->validateInputChars(winput, authorizedChars))
+        return Invalid;
 
+    // Convert the string to internal letters
+    const wstring &intInput = m_dic->getHeader().convertFromInput(winput);
     // The string is invalid if it contains characters not present
     // in the dictionary
-    if (!m_dic->validateLetters(qtw(copy)))
-        return Invalid;
+    if (!m_dic->validateLetters(intInput, authorizedChars))
+        return Intermediate;
+
     return Acceptable;
 }
 

Index: qt/dic_tools_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/dic_tools_widget.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- qt/dic_tools_widget.h       14 Dec 2008 13:20:40 -0000      1.3
+++ qt/dic_tools_widget.h       27 Jun 2009 18:09:44 -0000      1.4
@@ -54,6 +54,8 @@
 
     /// Palette to write text in red
     QPalette redPalette;
+    /// Palette to write text in yellow
+    QPalette darkYellowPalette;
     /// Palette to write text in green
     QPalette greenPalette;
 

Index: qt/play_word_mediator.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/play_word_mediator.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- qt/play_word_mediator.cpp   19 Feb 2009 18:25:19 -0000      1.1
+++ qt/play_word_mediator.cpp   27 Jun 2009 18:09:44 -0000      1.2
@@ -28,6 +28,7 @@
 #include "public_game.h"
 #include "coord.h"
 #include "dic.h"
+#include "header.h"
 #include "debug.h"
 
 
@@ -108,7 +109,10 @@
         return;
 
     // Convert the jokers to lowercase
-    QString word = m_lineEditPlay.text().toUpper();
+    const wistring &inputWord = qtw(m_lineEditPlay.text().toUpper());
+    // Convert to internal representation, then back to QString
+    QString word = 
qfw(m_game->getDic().getHeader().convertFromInput(inputWord));
+
     int pos;
     while ((pos = word.indexOf('(')) != -1)
     {
@@ -129,8 +133,12 @@
         }
     }
 
+    // Convert the input string into an internal one
+    const wstring intWord =
+        m_game->getDic().getHeader().convertFromInput(qtw(word));
+
     QString coords = m_lineEditCoord.text();
-    int res = m_game->play(qtw(word), qtw(coords));
+    int res = m_game->play(intWord, qtw(coords));
     if (res == 0)
     {
         emit gameUpdated();
@@ -221,31 +229,34 @@
     if (input == "")
         return Intermediate;
 
-    QString copy(input);
-    // Strip parentheses
-    copy.remove('(');
-    copy.remove(')');
-    // The string is invalid if it contains characters not present
-    // in the dictionary
-    if (!m_dic.validateLetters(qtw(copy)) || copy.contains('?'))
+    const wistring &winput = qtw(input);
+    // The string is invalid if it contains invalid input characters
+    if (!m_dic.validateInputChars(winput, L"()") || input.contains('?'))
         return Invalid;
 
+    // Convert the string to internal letters
+    const wstring &intInput = m_dic.getHeader().convertFromInput(winput);
+    // The string is invalid if it contains characters not present
+    // in the dictionary (ignoring parentheses)
+    if (!m_dic.validateLetters(intInput, L"()"))
+        return Intermediate;
+
     // Check the parentheses pairs
-    copy = input;
+    QString qintInput = qfw(intInput);
     int pos;
-    while ((pos = copy.indexOf('(')) != -1)
+    while ((pos = qintInput.indexOf('(')) != -1)
     {
-        if (copy.size() < pos + 3 || copy[pos + 2] != ')' ||
-            !m_dic.validateLetters(qtw(QString(copy[pos + 1]))))
+        if (qintInput.size() < pos + 3 || qintInput[pos + 2] != ')' ||
+            !m_dic.validateLetters(qtw(QString(qintInput[pos + 1]))))
         {
             return Intermediate;
         }
         else
         {
-            copy.remove(pos, 3);
+            qintInput.remove(pos, 3);
         }
     }
-    if (copy.indexOf(')') != -1)
+    if (qintInput.indexOf(')') != -1)
         return Intermediate;
 
     return Acceptable;

Index: qt/player_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.cpp,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- qt/player_widget.cpp        19 Feb 2009 18:25:19 -0000      1.15
+++ qt/player_widget.cpp        27 Jun 2009 18:09:44 -0000      1.16
@@ -33,6 +33,7 @@
 #include "coord.h"
 #include "coord_model.h"
 #include "dic.h"
+#include "header.h"
 #include "debug.h"
 
 #include "encoding.h"
@@ -43,11 +44,13 @@
 {
 public:
     explicit ChangeValidator(QObject *parent,
-                             const QLineEdit &iLineEdit);
+                             const QLineEdit &iLineEdit,
+                             const Dictionary &iDic);
     virtual State validate(QString &input, int &pos) const;
 
 private:
     const QLineEdit &m_lineEdit;
+    const Dictionary &m_dic;
 };
 
 
@@ -84,7 +87,8 @@
     }
     else
     {
-        lineEditChange->setValidator(new ChangeValidator(this, *lineEditRack));
+        lineEditChange->setValidator(new ChangeValidator(this, *lineEditRack,
+                                                         m_game->getDic()));
     }
 
     refresh();
@@ -146,19 +150,22 @@
     ASSERT(m_game->getMode() == PublicGame::kFREEGAME,
            "Trying to pass or change letters while not in free game mode");
 
+    QString inputLetters = lineEditChange->text();
+    // Convert the input string into an internal one
+    const wstring &letters =
+        m_game->getDic().getHeader().convertFromInput(qtw(inputLetters));
     // Pass the turn (and possibly change letters)
-    QString letters = lineEditChange->text();
-    int res = m_game->freeGamePass(qtw(letters));
+    int res = m_game->freeGamePass(letters);
     if (res == 0)
         emit gameUpdated();
     else
     {
         // FIXME: the error is too generic
         QString msg;
-        if (letters == "")
+        if (inputLetters == "")
             msg = _q("Cannot pass turn (%1)").arg(res);
         else
-            msg = _q("Cannot change letters '%1' (%2)").arg(letters).arg(res);
+            msg = _q("Cannot change letters '%1' 
(%2)").arg(inputLetters).arg(res);
         emit notifyProblem(msg);
     }
 }
@@ -166,22 +173,39 @@
 
 
 ChangeValidator::ChangeValidator(QObject *parent,
-                                 const QLineEdit &iLineEdit)
-    : QValidator(parent), m_lineEdit(iLineEdit)
+                                 const QLineEdit &iLineEdit,
+                                 const Dictionary &iDic)
+    : QValidator(parent), m_lineEdit(iLineEdit), m_dic(iDic)
 {
 }
 
 
 QValidator::State ChangeValidator::validate(QString &input, int &) const
 {
-    QString rack = m_lineEdit.text();
-    if (input.size() > rack.size())
+    // The string is invalid if it contains invalid input characters
+    const wistring &winput = qtw(input);
+    if (!m_dic.validateInputChars(winput))
+        return Invalid;
+
+    // Convert the string to internal letters
+    const wstring &intInput = m_dic.getHeader().convertFromInput(winput);
+    // The string is invalid if it contains characters not present
+    // in the dictionary
+    if (!m_dic.validateLetters(intInput))
+        return Intermediate;
+
+    const wstring &rack = 
m_dic.getHeader().convertFromInput(qtw(m_lineEdit.text()));
+    if (intInput.size() > rack.size())
         return Intermediate;
     // The letters to change must be in the rack
-    for (int i = 0; i < input.size(); ++i)
+    // We convert back to QString objects, because their count() method is
+    // very practical...
+    QString qrack = qfw(rack);
+    QString qinput = qfw(intInput);
+    for (int i = 0; i < qinput.size(); ++i)
     {
-        if (input.count(input[i], Qt::CaseInsensitive) >
-            rack.count(input[i], Qt::CaseInsensitive))
+        if (qinput.count(qinput[i], Qt::CaseInsensitive) >
+            qrack.count(qinput[i], Qt::CaseInsensitive))
         {
             return Intermediate;
         }

Index: qt/training_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/training_widget.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- qt/training_widget.cpp      28 Feb 2009 09:24:27 -0000      1.11
+++ qt/training_widget.cpp      27 Jun 2009 18:09:44 -0000      1.12
@@ -26,6 +26,7 @@
 #include "play_word_mediator.h"
 
 #include "dic.h"
+#include "header.h"
 #include "bag.h"
 #include "public_game.h"
 #include "game_exception.h"
@@ -52,6 +53,11 @@
 {
     setupUi(this);
 
+    redPalette = lineEditRack->palette();
+    redPalette.setColor(QPalette::Text, Qt::red);
+    blackPalette = lineEditRack->palette();
+    blackPalette.setColor(QPalette::Text, Qt::black);
+
     // Use the mediator
     m_mediator = new PlayWordMediator(this, *lineEditPlay, *lineEditCoords,
                                       *pushButtonPlay, iCoordModel, m_game);
@@ -196,15 +202,24 @@
 {
     // FIXME: first parameter is hardcoded
     m_game->trainingRemoveTestPlay();
+    if (!lineEditRack->hasAcceptableInput())
+    {
+        lineEditRack->setPalette(redPalette);
+        return;
+    }
     try
     {
-        m_game->trainingSetRackManual(false, qtw(iText));
+        lineEditRack->setPalette(blackPalette);
+        const Header &header = m_game->getDic().getHeader();
+        const wstring &input = header.convertFromInput(qtw(iText));
+        m_game->trainingSetRackManual(false, input);
         pushButtonSearch->setEnabled(m_model->rowCount() == 0 &&
                                      lineEditRack->text() != "");
         emit gameUpdated();
     }
     catch (GameException &e)
     {
+        lineEditRack->setPalette(redPalette);
         emit notifyProblem(_q("Warning: Cannot set the rack to 
'%1'").arg(iText));
     }
 }
@@ -212,10 +227,10 @@
 
 void TrainingWidget::on_pushButtonRack_clicked()
 {
-    // FIXME: first parameter is hardcoded
     m_game->trainingRemoveTestPlay();
     try
     {
+        // FIXME: first parameter is hardcoded
         m_game->trainingSetRackRandom(true, PublicGame::kRACK_ALL);
         emit gameUpdated();
     }
@@ -228,10 +243,10 @@
 
 void TrainingWidget::on_pushButtonComplement_clicked()
 {
-    // FIXME: first parameter is hardcoded
     m_game->trainingRemoveTestPlay();
     try
     {
+        // FIXME: first parameter is hardcoded
         m_game->trainingSetRackRandom(true, PublicGame::kRACK_NEW);
         emit gameUpdated();
     }
@@ -296,14 +311,26 @@
 
     input = input.toUpper();
 
-    if (!m_bag->getDic().validateLetters(qtw(input)))
+    const Dictionary &dic = m_bag->getDic();
+
+    // The string is invalid if it contains invalid input characters
+    const wistring &winput = qtw(input);
+    if (!dic.validateInputChars(winput))
         return Invalid;
 
+    // Convert the string to internal letters
+    const wstring &intInput = dic.getHeader().convertFromInput(winput);
+    // The string is invalid if it contains characters not present
+    // in the dictionary
+    if (!dic.validateLetters(intInput))
+        return Intermediate;
+
+    QString qinput = qfw(intInput);
     // The letters must be in the bag
-    for (int i = 0; i < input.size(); ++i)
+    for (int i = 0; i < qinput.size(); ++i)
     {
-        if ((unsigned int)input.count(input[i], Qt::CaseInsensitive) >
-            m_bag->in(qtw(input.mid(i, 1))[0]))
+        if ((unsigned int)qinput.count(qinput[i], Qt::CaseInsensitive) >
+            m_bag->in(qtw(qinput.mid(i, 1))[0]))
         {
             return Invalid;
         }

Index: qt/training_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/training_widget.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- qt/training_widget.h        19 Feb 2009 18:25:20 -0000      1.6
+++ qt/training_widget.h        27 Jun 2009 18:09:44 -0000      1.7
@@ -73,6 +73,12 @@
     /// Mediator for the "play word" controls
     PlayWordMediator *m_mediator;
 
+    /// Palette to write text in red
+    QPalette redPalette;
+
+    /// Palette to write text in black
+    QPalette blackPalette;
+
     /// Force synchronizing the model with the contents of the search results
     void updateModel();
 };




reply via email to

[Prev in Thread] Current Thread [Next in Thread]