eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot/qt Makefile.am bag_widget.cpp history_wid...


From: eliot-dev
Subject: [Eliot-dev] eliot/qt Makefile.am bag_widget.cpp history_wid...
Date: Thu, 24 Jan 2008 20:18:02 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/01/24 20:18:02

Modified files:
        qt             : Makefile.am bag_widget.cpp history_widget.cpp 
                         main_window.cpp main_window.h player_widget.cpp 
                         player_widget.h score_widget.cpp 
        qt/ui          : main_window.ui 
Added files:
        qt             : training_widget.cpp training_widget.h 
        qt/ui          : training_widget.ui 

Log message:
        Qt interface: added support for training mode

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/Makefile.am?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/bag_widget.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/history_widget.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/main_window.h?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/player_widget.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/player_widget.h?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/score_widget.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/training_widget.cpp?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/training_widget.h?cvsroot=eliot&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/main_window.ui?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/training_widget.ui?cvsroot=eliot&rev=1.1

Patches:
Index: Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/Makefile.am,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Makefile.am 20 Jan 2008 18:40:12 -0000      1.1
+++ Makefile.am 24 Jan 2008 20:18:00 -0000      1.2
@@ -29,18 +29,21 @@
 EXTRA_DIST = \
     ui/main_window.ui \
     ui/new_game.ui \
+    ui/training_widget.ui \
     ui/player_widget.ui
 
 BUILT_SOURCES = \
     ui/main_window.ui.h \
     ui/new_game.ui.h \
     ui/player_widget.ui.h \
+    ui/training_widget.ui.h \
     new_game.moc.cpp \
     bag_widget.moc.cpp \
     score_widget.moc.cpp \
     board_widget.moc.cpp \
-    player_widget.moc.cpp \
     history_widget.moc.cpp \
+    player_widget.moc.cpp \
+    training_widget.moc.cpp \
     aux_window.moc.cpp \
     main_window.moc.cpp
 
@@ -52,6 +55,7 @@
     board_widget.cpp board_widget.h \
     history_widget.cpp history_widget.h \
     player_widget.cpp player_widget.h \
+    training_widget.cpp training_widget.h \
     aux_window.cpp aux_window.h \
     main_window.cpp main_window.h \
     main.cpp

Index: bag_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/bag_widget.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- bag_widget.cpp      22 Jan 2008 15:30:20 -0000      1.2
+++ bag_widget.cpp      24 Jan 2008 20:18:00 -0000      1.3
@@ -45,6 +45,9 @@
     // Associate the model to the view
     m_model = new QStandardItemModel(this);
     setModel(m_model);
+    m_model->setColumnCount(2);
+    m_model->setHeaderData(0, Qt::Horizontal, _q("Letter"), Qt::DisplayRole);
+    m_model->setHeaderData(1, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
     updateModel();
 }
 
@@ -64,10 +67,7 @@
 
 void BagWidget::updateModel()
 {
-    m_model->clear();
-    m_model->setColumnCount(2);
-    m_model->setHeaderData(0, Qt::Horizontal, _q("Letter"), Qt::DisplayRole);
-    m_model->setHeaderData(1, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
+    m_model->removeRows(0, m_model->rowCount());
 
     if (m_game == NULL)
         return;

Index: history_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/history_widget.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- history_widget.cpp  22 Jan 2008 15:30:21 -0000      1.2
+++ history_widget.cpp  24 Jan 2008 20:18:00 -0000      1.3
@@ -44,6 +44,12 @@
     // Associate the model to the view
     m_model = new QStandardItemModel(this);
     setModel(m_model);
+    m_model->setColumnCount(6);
+    m_model->setHeaderData(0, Qt::Horizontal, _q("Turn"), Qt::DisplayRole);
+    m_model->setHeaderData(1, Qt::Horizontal, _q("Rack"), Qt::DisplayRole);
+    m_model->setHeaderData(2, Qt::Horizontal, _q("Word"), Qt::DisplayRole);
+    m_model->setHeaderData(3, Qt::Horizontal, _q("Ref"), Qt::DisplayRole);
+    m_model->setHeaderData(4, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
     updateModel();
 }
 
@@ -65,8 +71,7 @@
 
 void HistoryWidget::updateModel()
 {
-    m_model->clear();
-    m_model->setColumnCount(6);
+    m_model->removeRows(0, m_model->rowCount());
     if (m_forPlayer)
     {
         // Empty column
@@ -76,11 +81,6 @@
     {
         m_model->setHeaderData(5, Qt::Horizontal, _q("Player"), 
Qt::DisplayRole);
     }
-    m_model->setHeaderData(0, Qt::Horizontal, _q("Turn"), Qt::DisplayRole);
-    m_model->setHeaderData(1, Qt::Horizontal, _q("Rack"), Qt::DisplayRole);
-    m_model->setHeaderData(2, Qt::Horizontal, _q("Word"), Qt::DisplayRole);
-    m_model->setHeaderData(3, Qt::Horizontal, _q("Ref"), Qt::DisplayRole);
-    m_model->setHeaderData(4, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
 
     if (m_history != NULL)
     {

Index: main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- main_window.cpp     22 Jan 2008 15:30:21 -0000      1.2
+++ main_window.cpp     24 Jan 2008 20:18:00 -0000      1.3
@@ -38,6 +38,7 @@
 #include "score_widget.h"
 #include "player_widget.h"
 #include "history_widget.h"
+#include "training_widget.h"
 #include "aux_window.h"
 #include "qtcommon.h"
 
@@ -81,14 +82,24 @@
     m_ui.groupBoxPlayers->hide();
     PlayerTabWidget *players = new PlayerTabWidget(NULL);
     m_ui.groupBoxPlayers->layout()->addWidget(players);
-    QObject::connect(this, SIGNAL(gameChanged(const Game*)),
-                     players, SLOT(setGame(const Game*)));
+    QObject::connect(this, SIGNAL(gameChangedNonConst(Game*)),
+                     players, SLOT(setGame(Game*)));
     QObject::connect(this, SIGNAL(gameUpdated()), players, SLOT(refresh()));
+
+    QObject::connect(players, SIGNAL(gameUpdated()), this, 
SIGNAL(gameUpdated()));
     QObject::connect(players, SIGNAL(playingWord(unsigned int, QString, 
QString)),
                      this, SLOT(playerPlays(unsigned int, QString, QString)));
     QObject::connect(players, SIGNAL(passing(unsigned int, QString)),
                      this, SLOT(playerPasses(unsigned int, QString)));
 
+    // XXX: temp: Training widget
+    //TrainingWidget *trWidget = new TrainingWidget(NULL);
+    //m_ui.groupBoxPlayers->layout()->addWidget(trWidget);
+    //QObject::connect(this, SIGNAL(gameChangedNonConst(Game*)),
+    //                 trWidget, SLOT(setGame(Game*)));
+    //QObject::connect(this, SIGNAL(gameUpdated()), trWidget, SLOT(refresh()));
+    //QObject::connect(trWidget, SIGNAL(gameUpdated()), this, 
SIGNAL(gameUpdated()));
+
     // Players score
     ScoreWidget *scores = new ScoreWidget;
     QObject::connect(this, SIGNAL(gameChanged(const Game*)),
@@ -185,6 +196,7 @@
 
     // Some controls, like the board, can live when there is no game.
     // We only have to give them a NULL handler instead of the current one.
+    emit gameChangedNonConst(NULL);
     emit gameChanged(NULL);
 
     m_ui.groupBoxPlayers->hide();
@@ -220,6 +232,7 @@
     m_ui.groupBoxPlayers->show();
 
     m_game->start();
+    emit gameChangedNonConst(m_game);
     emit gameChanged(m_game);
     emit gameUpdated();
 }

Index: main_window.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- main_window.h       22 Jan 2008 15:30:21 -0000      1.2
+++ main_window.h       24 Jan 2008 20:18:01 -0000      1.3
@@ -45,6 +45,7 @@
 signals:
     void dicChanged(QString iDicFile, QString iDicName);
     void gameChanged(const Game *iGame);
+    void gameChangedNonConst(Game *iGame);
     void gameUpdated();
 
 public slots:

Index: player_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- player_widget.cpp   22 Jan 2008 15:30:21 -0000      1.2
+++ player_widget.cpp   24 Jan 2008 20:18:01 -0000      1.3
@@ -24,6 +24,7 @@
 #include <QtCore/QStringList>
 
 #include "player_widget.h"
+#include "training_widget.h"
 #include "qtcommon.h"
 #include "game.h"
 #include "player.h"
@@ -213,17 +214,13 @@
 
 
 PlayerTabWidget::PlayerTabWidget(QWidget *parent)
-    : QTabWidget(parent), m_game(NULL)
+    : QTabWidget(parent)
 {
 }
 
 
-void PlayerTabWidget::setGame(const Game *iGame)
+void PlayerTabWidget::setGame(Game *iGame)
 {
-    m_game = iGame;
-
-    if (m_game == NULL)
-    {
         // Cut all the connections with the pages
         disconnect();
 
@@ -231,14 +228,30 @@
         int nbTabs = count();
         for (int i = 0; i < nbTabs; ++i)
             removeTab(0);
+
+    if (iGame != NULL)
+    {
+        // Training mode: use a dedicated widget
+        if (iGame->getMode() == Game::kTRAINING)
+        {
+            const Player &player = iGame->getPlayer(0);
+            TrainingWidget *trWidget = new TrainingWidget;
+            trWidget->setGame(iGame);
+            QObject::connect(this, SIGNAL(refreshSignal()),
+                             trWidget, SLOT(refresh()));
+            // Forward the gameUpdated() signal to the outside
+            QObject::connect(trWidget, SIGNAL(gameUpdated()),
+                             this, SIGNAL(gameUpdated()));
+            addTab(trWidget, qfw(player.getName()));
     }
     else
     {
+
         // Add one tab per player
-        for (unsigned int i = 0; i < m_game->getNPlayers(); ++i)
+            for (unsigned int i = 0; i < iGame->getNPlayers(); ++i)
         {
-            const Player &player = m_game->getPlayer(i);
-            PlayerWidget *p = new PlayerWidget(NULL, i, m_game);
+                const Player &player = iGame->getPlayer(i);
+                PlayerWidget *p = new PlayerWidget(NULL, i, iGame);
             QObject::connect(this, SIGNAL(refreshSignal()), p, 
SLOT(refresh()));
             QObject::connect(p, SIGNAL(passing(unsigned int, QString)),
                              this, SIGNAL(passing(unsigned int, QString)));
@@ -247,6 +260,7 @@
             addTab(p, qfw(player.getName()));
         }
     }
+    }
 }
 
 

Index: player_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- player_widget.h     22 Jan 2008 15:30:21 -0000      1.2
+++ player_widget.h     24 Jan 2008 20:18:01 -0000      1.3
@@ -76,17 +76,14 @@
     explicit PlayerTabWidget(QWidget *parent = 0);
 
 public slots:
-    void setGame(const Game *iGame);
+    void setGame(Game *iGame);
     void refresh();
 
 signals:
     void refreshSignal();
+    void gameUpdated();
     void playingWord(unsigned int iPlayer, QString iWord, QString iCoord);
     void passing(unsigned int iPlayer, QString iChangedLetters);
-
-private:
-    /// Encapsulated game, can be NULL
-    const Game *m_game;
 };
 
 #endif

Index: score_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/score_widget.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- score_widget.cpp    22 Jan 2008 15:30:22 -0000      1.2
+++ score_widget.cpp    24 Jan 2008 20:18:01 -0000      1.3
@@ -42,6 +42,9 @@
     // Associate the model to the view
     m_model = new QStandardItemModel(this);
     setModel(m_model);
+    m_model->setColumnCount(2);
+    m_model->setHeaderData(0, Qt::Horizontal, _q("Player"), Qt::DisplayRole);
+    m_model->setHeaderData(1, Qt::Horizontal, _q("Score"), Qt::DisplayRole);
     updateModel();
 }
 
@@ -61,10 +64,7 @@
 
 void ScoreWidget::updateModel()
 {
-    m_model->clear();
-    m_model->setColumnCount(2);
-    m_model->setHeaderData(0, Qt::Horizontal, _q("Player"), Qt::DisplayRole);
-    m_model->setHeaderData(1, Qt::Horizontal, _q("Score"), Qt::DisplayRole);
+    m_model->removeRows(0, m_model->rowCount());
     resizeColumnToContents(0);
     //resizeColumnToContents(1);
 
@@ -79,6 +79,8 @@
         m_model->setData(m_model->index(rowNum, 0), qfw(p.getName()));
         m_model->setData(m_model->index(rowNum, 1), p.getPoints());
     }
+    resizeColumnToContents(0);
+    //resizeColumnToContents(1);
 }
 
 

Index: ui/main_window.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/main_window.ui,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ui/main_window.ui   22 Jan 2008 15:30:22 -0000      1.2
+++ ui/main_window.ui   24 Jan 2008 20:18:02 -0000      1.3
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>828</width>
-    <height>588</height>
+    <width>747</width>
+    <height>617</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -62,7 +62,7 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>828</width>
+     <width>747</width>
      <height>29</height>
     </rect>
    </property>

Index: training_widget.cpp
===================================================================
RCS file: training_widget.cpp
diff -N training_widget.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ training_widget.cpp 24 Jan 2008 20:18:01 -0000      1.1
@@ -0,0 +1,263 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 2008 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *****************************************************************************/
+
+#include <QtGui/QStandardItemModel>
+#include <QtGui/QValidator>
+
+#include "training_widget.h"
+#include "qtcommon.h"
+#include "game.h"
+#include "training.h"
+#include "player.h"
+#include "results.h"
+
+using namespace std;
+
+
+/// Validator used for the rack line edit
+class RackValidator: public QValidator
+{
+public:
+    explicit RackValidator(QObject *parent);
+    virtual State validate(QString &input, int &pos) const;
+
+    void setBag(const Bag *iBag) { m_bag = iBag; }
+
+private:
+    const Bag *m_bag;
+};
+
+
+TrainingWidget::TrainingWidget(QWidget *parent)
+    : QWidget(parent), m_game(NULL)
+{
+    setupUi(this);
+
+    // Associate the model to the view
+    m_model = new QStandardItemModel(this);
+    treeViewResults->setModel(m_model);
+    m_model->setColumnCount(5);
+    m_model->setHeaderData(0, Qt::Horizontal, _q("Word"), Qt::DisplayRole);
+    m_model->setHeaderData(1, Qt::Horizontal, _q("Ref"), Qt::DisplayRole);
+    m_model->setHeaderData(2, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
+    m_model->setHeaderData(3, Qt::Horizontal, "*", Qt::DisplayRole);
+    m_model->setHeaderData(4, Qt::Horizontal, "", Qt::DisplayRole);
+
+    // Enable the Play button only when there is a selection in the tree
+    QObject::connect(treeViewResults->selectionModel(),
+                     SIGNAL(selectionChanged(const QItemSelection&, const 
QItemSelection&)),
+                     this,
+                     SLOT(enablePlayButton(const QItemSelection&, const 
QItemSelection&)));
+    // Display a preview of the selected word on the board
+    QObject::connect(treeViewResults->selectionModel(),
+                     SIGNAL(selectionChanged(const QItemSelection&, const 
QItemSelection&)),
+                     this,
+                     SLOT(showPreview(const QItemSelection&, const 
QItemSelection&)));
+
+    m_validator = new RackValidator(this);
+    lineEditRack->setValidator(m_validator);
+
+    refresh();
+}
+
+
+void TrainingWidget::setGame(Game *iGame)
+{
+    m_game = dynamic_cast<Training*>(iGame);
+    if (m_game != NULL)
+        m_validator->setBag(&m_game->getBag());
+    else
+        m_validator->setBag(NULL);
+    refresh();
+}
+
+
+void TrainingWidget::refresh()
+{
+    updateModel();
+    if (m_game == NULL)
+    {
+        lineEditRack->setText("");
+        lineEditRack->setEnabled(false);
+        pushButtonRack->setEnabled(false);
+        pushButtonComplement->setEnabled(false);
+        pushButtonSearch->setEnabled(false);
+        pushButtonPlay->setEnabled(false);
+    }
+    else
+    {
+        wstring rack = 
m_game->getPlayer(0).getCurrentRack().toString(PlayedRack::RACK_SIMPLE);
+        // Update the rack only if it needed, to avoid losing cursor position
+        if (qfw(rack) != lineEditRack->text())
+            lineEditRack->setText(qfw(rack));
+        lineEditRack->setEnabled(true);
+        pushButtonRack->setEnabled(true);
+        pushButtonComplement->setEnabled(true);
+        pushButtonSearch->setEnabled(m_model->rowCount() == 0 &&
+                                     lineEditRack->text() != "");
+    }
+}
+
+
+void TrainingWidget::updateModel()
+{
+    // Consider that there is nothing to do if the number of lines is correct
+    // This avoids problems when the game is updated for a test play
+    if (m_game != NULL &&
+        m_game->getResults().size() == (unsigned int)m_model->rowCount())
+    {
+        return;
+    }
+
+    m_model->removeRows(0, m_model->rowCount());
+
+    if (m_game == NULL)
+        return;
+
+    for (unsigned int i = 0; i < m_game->getResults().size(); ++i)
+    {
+        const Round &r = m_game->getResults().get(i);
+        int rowNum = m_model->rowCount();
+        m_model->insertRow(rowNum);
+        m_model->setData(m_model->index(rowNum, 0), qfw(r.getWord()));
+        m_model->setData(m_model->index(rowNum, 1),
+                         qfw(r.getCoord().toString()));
+        m_model->setData(m_model->index(rowNum, 2), r.getPoints());
+        m_model->setData(m_model->index(rowNum, 3),
+                         r.getBonus() ? "*": "");
+    }
+    treeViewResults->resizeColumnToContents(0);
+    treeViewResults->resizeColumnToContents(1);
+    treeViewResults->resizeColumnToContents(2);
+    treeViewResults->resizeColumnToContents(3);
+}
+
+
+void TrainingWidget::enablePlayButton(const QItemSelection &iSelected,
+                                      const QItemSelection &)
+{
+    // Enable the "Play" button iff at least one line in the tree view
+    // is selected
+    pushButtonPlay->setEnabled(!iSelected.indexes().empty());
+}
+
+
+void TrainingWidget::showPreview(const QItemSelection &iSelected,
+                                 const QItemSelection &)
+{
+    m_game->removeTestPlay();
+    if (!iSelected.indexes().empty())
+    {
+        m_game->testPlay(iSelected.indexes().first().row());
+        emit gameUpdated();
+    }
+}
+
+
+void TrainingWidget::on_lineEditRack_textEdited(const QString &iText)
+{
+    // FIXME: first parameter is hardcoded
+    // FIXME: return code ignored
+    m_game->setRackManual(false, qtw(iText));
+    pushButtonSearch->setEnabled(m_model->rowCount() == 0 &&
+                                 lineEditRack->text() != "");
+    emit gameUpdated();
+}
+
+
+void TrainingWidget::on_pushButtonRack_clicked()
+{
+    // FIXME: first parameter is hardcoded
+    m_game->removeTestPlay();
+    m_game->setRackRandom(true, Game::RACK_ALL);
+    emit gameUpdated();
+}
+
+
+void TrainingWidget::on_pushButtonComplement_clicked()
+{
+    // FIXME: first parameter is hardcoded
+    m_game->removeTestPlay();
+    m_game->setRackRandom(true, Game::RACK_NEW);
+    emit gameUpdated();
+}
+
+
+void TrainingWidget::on_pushButtonSearch_clicked()
+{
+    m_game->removeTestPlay();
+    m_game->search();
+    emit gameUpdated();
+}
+
+
+void TrainingWidget::on_pushButtonPlay_clicked()
+{
+    QModelIndexList indexList = 
treeViewResults->selectionModel()->selectedIndexes();
+    if (indexList.empty())
+        return;
+    // Forward the work to another slot
+    on_treeViewResults_doubleClicked(indexList.front());
+}
+
+
+void TrainingWidget::on_treeViewResults_doubleClicked(const QModelIndex 
&iIndex)
+{
+    if (!iIndex.isValid())
+        return;
+    m_game->removeTestPlay();
+    m_game->playResult(iIndex.row());
+    emit gameUpdated();
+}
+
+
+QSize TrainingWidget::sizeHint() const
+{
+    return QSize(160, 300);
+}
+
+
+
+RackValidator::RackValidator(QObject *parent)
+    : QValidator(parent)
+{
+}
+
+
+QValidator::State RackValidator::validate(QString &input, int &) const
+{
+    // This should never happen, since the control should be disabled in
+    // such a case, but checking doesn't hurt...
+    if (m_bag == NULL)
+        return Invalid;
+
+    // The letters must be in the bag
+    for (int i = 0; i < input.size(); ++i)
+    {
+        if ((unsigned int)input.count(input[i], Qt::CaseInsensitive) >
+            m_bag->in(qtw(input.mid(i, 1))[0]))
+        {
+            return Invalid;
+        }
+    }
+    return Acceptable;
+}
+
+

Index: training_widget.h
===================================================================
RCS file: training_widget.h
diff -N training_widget.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ training_widget.h   24 Jan 2008 20:18:01 -0000      1.1
@@ -0,0 +1,78 @@
+/*****************************************************************************
+ * Eliot
+ * Copyright (C) 2008 Olivier Teulière
+ * Authors: Olivier Teulière <ipkiss @@ gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *****************************************************************************/
+
+#ifndef TRAINING_WIDGET_H_
+#define TRAINING_WIDGET_H_
+
+#include <QtGui/QWidget>
+#include "ui/training_widget.ui.h"
+
+
+class Game;
+class Training;
+class RackValidator;
+class QStandardItemModel;
+
+class TrainingWidget: public QWidget, private Ui::TrainingWidget
+{
+    Q_OBJECT;
+
+public:
+    explicit TrainingWidget(QWidget *parent = 0);
+
+public slots:
+    void setGame(Game *iGame);
+    void refresh();
+
+signals:
+    void gameUpdated();
+
+protected:
+    /// Define a default size
+    virtual QSize sizeHint() const;
+
+private slots:
+    void enablePlayButton(const QItemSelection &, const QItemSelection &);
+    void showPreview(const QItemSelection &, const QItemSelection &);
+
+    // These slots are automatocally connected
+    void on_lineEditRack_textEdited(const QString &iText);
+    void on_pushButtonRack_clicked();
+    void on_pushButtonComplement_clicked();
+    void on_pushButtonSearch_clicked();
+    void on_pushButtonPlay_clicked();
+    void on_treeViewResults_doubleClicked(const QModelIndex &iIndex);
+
+private:
+    /// Encapsulated training game, can be NULL
+    Training *m_game;
+
+    /// Model of the search results
+    QStandardItemModel *m_model;
+
+    /// Validator for the rack edition
+    RackValidator *m_validator;
+
+    /// Force synchronizing the model with the contents of the search results
+    void updateModel();
+};
+
+#endif
+

Index: ui/training_widget.ui
===================================================================
RCS file: ui/training_widget.ui
diff -N ui/training_widget.ui
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ ui/training_widget.ui       24 Jan 2008 20:18:02 -0000      1.1
@@ -0,0 +1,88 @@
+<ui version="4.0" >
+ <class>TrainingWidget</class>
+ <widget class="QWidget" name="TrainingWidget" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>415</width>
+    <height>371</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" >
+   <item>
+    <layout class="QHBoxLayout" >
+     <item>
+      <widget class="QLabel" name="label" >
+       <property name="text" >
+        <string>_("Rack:")</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLineEdit" name="lineEditRack" />
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" >
+     <item>
+      <widget class="QPushButton" name="pushButtonRack" >
+       <property name="text" >
+        <string>_("New Rack")</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButtonComplement" >
+       <property name="text" >
+        <string>_("Complement")</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButtonSearch" >
+       <property name="enabled" >
+        <bool>false</bool>
+       </property>
+       <property name="text" >
+        <string>_("Search")</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="pushButtonPlay" >
+       <property name="enabled" >
+        <bool>false</bool>
+       </property>
+       <property name="text" >
+        <string>_("Play")</string>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="groupBox" >
+     <property name="title" >
+      <string>_("Search results")</string>
+     </property>
+     <layout class="QVBoxLayout" >
+      <item>
+       <widget class="QTreeView" name="treeViewResults" >
+        <property name="editTriggers" >
+         <set>QAbstractItemView::NoEditTriggers</set>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>




reply via email to

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