diff --git a/qt/main_window.cpp b/qt/main_window.cpp index 163b601..6c1b1b2 100644 --- a/qt/main_window.cpp +++ b/qt/main_window.cpp @@ -405,6 +405,8 @@ void MainWindow::updateForGame(PublicGame *iGame) statusBar()->removeWidget(m_lettersLabel); statusBar()->removeWidget(m_turnLabel); + m_playModel.disconnect(this); + // Destroy the players widget QtCommon::DestroyObject(m_playersWidget, this); m_playersWidget = NULL; @@ -435,6 +437,9 @@ void MainWindow::updateForGame(PublicGame *iGame) statusBar()->addWidget(m_turnLabel); m_turnLabel->show(); + QObject::connect(&m_playModel, SIGNAL(movePlayed(const wstring&, const wstring&)), + this, SLOT(playWord(const wstring&, const wstring&))); + if (iGame->getMode() == PublicGame::kTRAINING) { setWindowTitle(_q("Training mode") + " - Eliot"); @@ -711,6 +716,69 @@ void MainWindow::changeDictionary(QString iFileName) } +void MainWindow::playWord(const wstring &iWord, const wstring &iCoord) +{ + ASSERT(m_game != NULL, "No game in progress"); + + int res = m_game->play(iWord, iCoord); + if (res == 0) + { + emit gameUpdated(); + } + else + { + // Try to be as explicit as possible concerning the error + QString msg = _q("Cannot play '%1' at position '%2':\n%3") + .arg(qfw(iWord)).arg(qfw(iCoord)); + switch (res) + { + case 1: + msg = msg.arg(_q("Some letters are not valid for the current dictionary")); + break; + case 2: + msg = msg.arg(_q("Invalid coordinates")); + break; + case 3: + msg = msg.arg(_q("The word does not exist")); + break; + case 4: + msg = msg.arg(_q("The rack doesn't contain the letters needed to play this word")); + break; + case 5: + msg = msg.arg(_q("The word is part of a longer one")); + break; + case 6: + msg = msg.arg(_q("The word tries to replace an existing letter")); + break; + case 7: + msg = msg.arg(_q("An orthogonal word is not valid")); + break; + case 8: + msg = msg.arg(_q("The word is already present on the board at these coordinates")); + break; + case 9: + msg = msg.arg(_q("A word cannot be isolated (not connected to the placed words)")); + break; + case 10: + msg = msg.arg(_q("The first word of the game must be horizontal")); + break; + case 11: + msg = msg.arg(_q("The first word of the game must cover the H8 square")); + break; + case 12: + msg = msg.arg(_q("The word is going out of the board")); + break; + case 13: + msg = msg.arg(_q("The word contains too many letters from the rack")); + break; + default: + msg = msg.arg(_q("Incorrect or misplaced word")); + } + displayErrorMsg(msg); + } +} + + QAction * MainWindow::addMenuAction(QMenu *menu, QString iText, const QKeySequence &iShortcut, QString iStatusTip, const char *iMember, diff --git a/qt/main_window.h b/qt/main_window.h index 82864eb..7e0dcc4 100644 --- a/qt/main_window.h +++ b/qt/main_window.h @@ -110,6 +110,9 @@ private slots: /** Load a new dictionary */ void changeDictionary(QString); + /// Play the given word + void playWord(const wstring &iWord, const wstring &iCoord); + /** Perform some updates when the game is updated */ void refresh(); diff --git a/qt/play_model.cpp b/qt/play_model.cpp index 028374d..449c506 100644 --- a/qt/play_model.cpp +++ b/qt/play_model.cpp @@ -67,3 +67,11 @@ void PlayModel::setMove(const Move &iMove) emit moveChanged(iMove, m_prevMove); } + + +void PlayModel::playWord(const wstring &iWord, const wstring &iCoord) +{ + emit movePlayed(iWord, iCoord); +} + + diff --git a/qt/play_model.h b/qt/play_model.h index 66db919..93a3fe5 100644 --- a/qt/play_model.h +++ b/qt/play_model.h @@ -62,9 +62,14 @@ public: void setMove(const Move &iMove); const Move &getMove() const { return m_currMove; } + // FIXME: should probably take no argument, and use the current move instead + void playWord(const wstring &iWord, const wstring &iCoord); + signals: void coordChanged(const Coord &iNewCoord, const Coord &iOldCoord); void moveChanged(const Move &iMove, const Move &iOldMove); + // FIXME: should probably use a Move object instead + void movePlayed(const wstring &iWord, const wstring &iCoord); private: Coord m_currCoord; diff --git a/qt/play_word_mediator.cpp b/qt/play_word_mediator.cpp index 680c16b..16a4b8e 100644 --- a/qt/play_word_mediator.cpp +++ b/qt/play_word_mediator.cpp @@ -156,62 +156,7 @@ void PlayWordMediator::playWord() const wstring &word = getWord(); QString coords = m_lineEditCoord.text(); - int res = m_game->play(word, wfq(coords)); - if (res == 0) - { - emit gameUpdated(); - } - else - { - // Try to be as explicit as possible concerning the error - QString msg = _q("Cannot play '%1' at position '%2':\n%3") - .arg(m_lineEditPlay.text()).arg(coords); - switch (res) - { - case 1: - msg = msg.arg(_q("Some letters are not valid for the current dictionary")); - break; - case 2: - msg = msg.arg(_q("Invalid coordinates")); - break; - case 3: - msg = msg.arg(_q("The word does not exist")); - break; - case 4: - msg = msg.arg(_q("The rack doesn't contain the letters needed to play this word")); - break; - case 5: - msg = msg.arg(_q("The word is part of a longer one")); - break; - case 6: - msg = msg.arg(_q("The word tries to replace an existing letter")); - break; - case 7: - msg = msg.arg(_q("An orthogonal word is not valid")); - break; - case 8: - msg = msg.arg(_q("The word is already present on the board at these coordinates")); - break; - case 9: - msg = msg.arg(_q("A word cannot be isolated (not connected to the placed words)")); - break; - case 10: - msg = msg.arg(_q("The first word of the game must be horizontal")); - break; - case 11: - msg = msg.arg(_q("The first word of the game must cover the H8 square")); - break; - case 12: - msg = msg.arg(_q("The word is going out of the board")); - break; - case 13: - msg = msg.arg(_q("The word contains too many letters from the rack")); - break; - default: - msg = msg.arg(_q("Incorrect or misplaced word")); - } - emit notifyProblem(msg); - } + m_playModel.playWord(word, wfq(coords)); }