eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot/qt bag_widget.cpp bag_widget.h board_widg...


From: eliot-dev
Subject: [Eliot-dev] eliot/qt bag_widget.cpp bag_widget.h board_widg...
Date: Tue, 22 Jan 2008 15:30:22 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/01/22 15:30:22

Modified files:
        qt             : bag_widget.cpp bag_widget.h board_widget.cpp 
                         board_widget.h history_widget.cpp 
                         history_widget.h main_window.cpp main_window.h 
                         player_widget.cpp player_widget.h 
                         score_widget.cpp score_widget.h 
        qt/ui          : main_window.ui player_widget.ui 

Log message:
         - New HistoryTabWidget control to display all the histories in a 
convenient way
         - New PlayerTabWidget control to simplify the code in MainWindow
         - Simplification and uniformization of signal handling when the Game 
object is changed or updated
         - Improved the general layout a little bit (but the resizing behaviour 
is far from perfect)

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

Patches:
Index: bag_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/bag_widget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- bag_widget.cpp      20 Jan 2008 18:40:12 -0000      1.1
+++ bag_widget.cpp      22 Jan 2008 15:30:20 -0000      1.2
@@ -24,6 +24,7 @@
 
 #include "bag_widget.h"
 #include "qtcommon.h"
+#include "game.h"
 #include "dic.h"
 #include "tile.h"
 #include "bag.h"
@@ -31,8 +32,8 @@
 using namespace std;
 
 
-BagWidget::BagWidget(QWidget *parent, const Bag *iBag)
-    : QTreeView(parent), m_bag(iBag)
+BagWidget::BagWidget(QWidget *parent)
+    : QTreeView(parent), m_game(NULL)
 {
     // Create the tree view
     setEditTriggers(QAbstractItemView::NoEditTriggers);
@@ -48,9 +49,15 @@
 }
 
 
-void BagWidget::setBag(const Bag *iBag)
+void BagWidget::setGame(const Game *iGame)
+{
+    m_game = iGame;
+    updateModel();
+}
+
+
+void BagWidget::refresh()
 {
-    m_bag = iBag;
     updateModel();
 }
 
@@ -62,14 +69,14 @@
     m_model->setHeaderData(0, Qt::Horizontal, _q("Letter"), Qt::DisplayRole);
     m_model->setHeaderData(1, Qt::Horizontal, _q("Points"), Qt::DisplayRole);
 
-    if (m_bag == NULL)
+    if (m_game == NULL)
         return;
 
-    const vector<Tile>& allTiles = m_bag->getDic().getAllTiles();
+    const vector<Tile>& allTiles = m_game->getDic().getAllTiles();
     vector<Tile>::const_iterator it;
     for (it = allTiles.begin(); it != allTiles.end(); ++it)
     {
-        unsigned int nb = m_bag->in(*it);
+        unsigned int nb = m_game->getBag().in(*it);
         if (nb != 0)
         {
             int rowNum = m_model->rowCount();

Index: bag_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/bag_widget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- bag_widget.h        20 Jan 2008 18:40:12 -0000      1.1
+++ bag_widget.h        22 Jan 2008 15:30:20 -0000      1.2
@@ -24,7 +24,7 @@
 #include <QtGui/QTreeView>
 
 
-class Bag;
+class Game;
 class QStandardItemModel;
 
 class BagWidget: public QTreeView
@@ -32,18 +32,19 @@
     Q_OBJECT;
 
 public:
-    explicit BagWidget(QWidget *parent = 0, const Bag *iBag = NULL);
+    explicit BagWidget(QWidget *parent = 0);
 
 public slots:
-    void setBag(const Bag *iBag = NULL);
+    void setGame(const Game *iGame);
+    void refresh();
 
 protected:
     /// Define a default size
     virtual QSize sizeHint() const;
 
 private:
-    /// Encapsulated bag, can be NULL
-    const Bag *m_bag;
+    /// Encapsulated game, can be NULL
+    const Game *m_game;
 
     /// Model of the bag
     QStandardItemModel *m_model;

Index: board_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/board_widget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- board_widget.cpp    20 Jan 2008 18:40:12 -0000      1.1
+++ board_widget.cpp    22 Jan 2008 15:30:21 -0000      1.2
@@ -24,11 +24,13 @@
 
 #include "board_widget.h"
 #include "qtcommon.h"
+#include "game.h"
 #include "tile.h"
 #include "board.h"
 
 using namespace std;
 
+
 const QColor BoardWidget::EmptyColour(Qt::white);
 const QColor BoardWidget::L2Colour(34, 189, 240);
 const QColor BoardWidget::L3Colour(29, 104, 240);
@@ -37,8 +39,8 @@
 const QColor BoardWidget::TileColour(255, 235, 205);
 
 
-BoardWidget::BoardWidget(QWidget *parent, const Board *iBoard)
-    : QFrame(parent), m_board(iBoard)
+BoardWidget::BoardWidget(QWidget *parent)
+    : QFrame(parent), m_game(NULL)
 {
     setFrameStyle(QFrame::Panel);
     // Use as much space as possible
@@ -48,9 +50,9 @@
 }
 
 
-void BoardWidget::setBoard(const Board *iBoard)
+void BoardWidget::setGame(const Game *iGame)
 {
-    m_board = iBoard;
+    m_game = iGame;
     refresh();
 }
 
@@ -80,7 +82,7 @@
         for (unsigned int col = BOARD_MIN; col <= BOARD_MAX; ++col)
         {
             // Set the brush color
-            if (m_board != NULL && !m_board->getTile(row, col).isEmpty())
+            if (m_game != NULL && !m_game->getBoard().getTile(row, 
col).isEmpty())
                 painter.setBrush(TileColour);
             else if (Board::GetWordMultiplier(row, col) == 3)
                 painter.setBrush(W3Colour);
@@ -97,13 +99,13 @@
                              squareSize, squareSize);
 
             // Draw the letter
-            if (m_board != NULL && !m_board->getTile(row, col).isEmpty())
+            if (m_game != NULL && !m_game->getBoard().getTile(row, 
col).isEmpty())
             {
                 painter.drawText((col - BOARD_MIN + 1) * squareSize,
                                  (row - BOARD_MIN + 1) * squareSize + 1,
                                  squareSize, squareSize,
                                  Qt::AlignCenter,
-                                 qfw(wstring(1, m_board->getTile(row, 
col).toChar())));
+                                 qfw(wstring(1, 
m_game->getBoard().getTile(row, col).toChar())));
             }
         }
     }

Index: board_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/board_widget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- board_widget.h      20 Jan 2008 18:40:13 -0000      1.1
+++ board_widget.h      22 Jan 2008 15:30:21 -0000      1.2
@@ -24,7 +24,7 @@
 #include <QtGui/QFrame>
 
 
-class Board;
+class Game;
 class QTreeView;
 
 class BoardWidget: public QFrame
@@ -32,10 +32,10 @@
     Q_OBJECT;
 
 public:
-    explicit BoardWidget(QWidget *parent = 0, const Board *iBoard = NULL);
+    explicit BoardWidget(QWidget *parent = 0);
 
 public slots:
-    void setBoard(const Board *iBoard = NULL);
+    void setGame(const Game *iGame);
     void refresh();
 
 protected:
@@ -45,8 +45,8 @@
     virtual void paintEvent(QPaintEvent *iEvent);
 
 private:
-    /// Encapsulated board, can be NULL
-    const Board *m_board;
+    /// Encapsulated game, can be NULL
+    const Game *m_game;
 
     /// Define a few background colours
     //@{

Index: history_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/history_widget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- history_widget.cpp  20 Jan 2008 18:40:13 -0000      1.1
+++ history_widget.cpp  22 Jan 2008 15:30:21 -0000      1.2
@@ -20,12 +20,13 @@
 
 #include <iostream>
 #include <QtGui/QTreeView>
+#include <QtGui/QTabWidget>
 #include <QtGui/QStandardItemModel>
 
 #include "history_widget.h"
 #include "qtcommon.h"
-#include "dic.h"
-#include "tile.h"
+#include "game.h"
+#include "player.h"
 #include "history.h"
 #include "turn.h"
 #include "move.h"
@@ -33,8 +34,8 @@
 using namespace std;
 
 
-HistoryWidget::HistoryWidget(QWidget *parent, const History *iHistory)
-    : QTreeView(parent), m_history(iHistory)
+HistoryWidget::HistoryWidget(QWidget *parent)
+    : QTreeView(parent), m_history(NULL), m_forPlayer(false)
 {
     // Create the tree view
     setEditTriggers(QAbstractItemView::NoEditTriggers);
@@ -47,9 +48,17 @@
 }
 
 
-void HistoryWidget::setHistory(const History *iHistory)
+void HistoryWidget::setHistory(const History *iHistory,
+                               bool iIsForPlayer)
 {
     m_history = iHistory;
+    m_forPlayer = iIsForPlayer;
+    updateModel();
+}
+
+
+void HistoryWidget::refresh()
+{
     updateModel();
 }
 
@@ -58,12 +67,20 @@
 {
     m_model->clear();
     m_model->setColumnCount(6);
+    if (m_forPlayer)
+    {
+        // Empty column
+        m_model->setHeaderData(5, Qt::Horizontal, "", Qt::DisplayRole);
+    }
+    else
+    {
+        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);
-    m_model->setHeaderData(5, Qt::Horizontal, _q("Player"), Qt::DisplayRole);
 
     if (m_history != NULL)
     {
@@ -81,6 +98,7 @@
             m_model->setData(m_model->index(rowNum, 1),
                              qfw(t.getPlayedRack().toString()));
             m_model->setData(m_model->index(rowNum, 4), m.getScore());
+            if (!m_forPlayer)
             m_model->setData(m_model->index(rowNum, 5), t.getPlayer() + 1);
             // Set the rest
             if (m.getType() == Move::VALID_ROUND)
@@ -124,3 +142,65 @@
     resizeColumnToContents(5);
 }
 
+
+
+HistoryTabWidget::HistoryTabWidget(QWidget *parent)
+    : QTabWidget(parent), m_game(NULL)
+{
+    m_gameHistoryWidget = new HistoryWidget(NULL);
+    insertTab(0, m_gameHistoryWidget, _q("&Game"));
+    //setMinimalSize(300, 100);
+
+    setGame(m_game);
+}
+
+
+void HistoryTabWidget::setGame(const Game *iGame)
+{
+    m_game = iGame;
+
+    if (m_game == NULL)
+    {
+        // Cut all the connections with the pages
+        disconnect();
+
+        // Keep only the Game tab, because it is nicer to have something, even
+        // if it is empty
+        int nbTabs = count();
+        for (int i = nbTabs - 1; i > 0; --i)
+            removeTab(i);
+
+        // Tell the remaining tab that there is no more history to display
+        m_gameHistoryWidget->setHistory(NULL);
+    }
+    else
+    {
+        // Refresh the Game tab
+        m_gameHistoryWidget->setHistory(&m_game->getHistory());
+        QObject::connect(this, SIGNAL(refreshSignal()),
+                         m_gameHistoryWidget, SLOT(refresh()));
+
+        // Add one history tab per player
+        for (unsigned int i = 0; i < m_game->getNPlayers(); ++i)
+        {
+            const Player &player = m_game->getPlayer(i);
+            HistoryWidget *h = new HistoryWidget(NULL);
+            h->setHistory(&player.getHistory(), true);
+            QObject::connect(this, SIGNAL(refreshSignal()), h, 
SLOT(refresh()));
+            addTab(h, qfw(player.getName()));
+        }
+    }
+}
+
+
+void HistoryTabWidget::refresh()
+{
+    emit refreshSignal();
+}
+
+
+QSize HistoryTabWidget::sizeHint() const
+{
+    return QSize(500, 300);
+}
+

Index: history_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/history_widget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- history_widget.h    20 Jan 2008 18:40:13 -0000      1.1
+++ history_widget.h    22 Jan 2008 15:30:21 -0000      1.2
@@ -22,25 +22,37 @@
 #define HISTORY_WIDGET_H_
 
 #include <QtGui/QTreeView>
+#include <QtGui/QTabWidget>
 
 
 class History;
+class Game;
 class QStandardItemModel;
+class QTabWidget;
 
 class HistoryWidget: public QTreeView
 {
     Q_OBJECT;
 
 public:
-    explicit HistoryWidget(QWidget *parent = 0, const History *iHistory = 
NULL);
+    explicit HistoryWidget(QWidget *parent = 0);
+
+    void setHistory(const History *iHistory = NULL,
+                    bool iIsForPlayer = false);
 
 public slots:
-    void setHistory(const History *iHistory = NULL);
+    void refresh();
 
 private:
     /// Encapsulated history, can be NULL
     const History *m_history;
 
+    /**
+     * Flag to avoid displaying the "players" column when the History object
+     * is precisely associated to a Player
+     */
+    bool m_forPlayer;
+
     /// Model of the history
     QStandardItemModel *m_model;
 
@@ -48,5 +60,34 @@
     void updateModel();
 };
 
+
+class HistoryTabWidget: public QTabWidget
+{
+    Q_OBJECT;
+
+public:
+    explicit HistoryTabWidget(QWidget *parent = NULL);
+
+public slots:
+    void setGame(const Game *iGame);
+    void refresh();
+
+signals:
+    void refreshSignal();
+
+protected:
+    virtual QSize sizeHint() const;
+
+private:
+    /// Encapsulated game, can be NULL
+    const Game *m_game;
+
+    /**
+     * HistoryWidget for the game: we reuse it instead of creating and
+     * destroying it every time
+     */
+    HistoryWidget *m_gameHistoryWidget;
+};
+
 #endif
 

Index: main_window.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- main_window.cpp     20 Jan 2008 18:40:13 -0000      1.1
+++ main_window.cpp     22 Jan 2008 15:30:21 -0000      1.2
@@ -46,39 +46,57 @@
 
 
 MainWindow::MainWindow(QWidget *iParent)
-    : QMainWindow(iParent), m_dic(NULL), m_game(NULL), m_newGame(NULL),
+    : QMainWindow(iParent), m_dic(NULL), m_game(NULL), m_newGameDialog(NULL),
     m_bagWindow(NULL)
 {
     m_ui.setupUi(this);
 
-    // Cascading signals
-    QObject::connect(this, SIGNAL(gameChanged(const Game*)),
-                     this, SLOT(gameUpdated()));
-
-    // Create the main window
+    // Board
     BoardWidget *boardWidget = new BoardWidget;
-    QObject::connect(this, SIGNAL(boardChanged(const Board*)),
-                     boardWidget, SLOT(setBoard(const Board*)));
+    QObject::connect(this, SIGNAL(gameChanged(const Game*)),
+                     boardWidget, SLOT(setGame(const Game*)));
+    QObject::connect(this, SIGNAL(gameUpdated()),
+                     boardWidget, SLOT(refresh()));
 
     QDockWidget *dock = new QDockWidget;
     dock->setWidget(boardWidget);
     boardWidget->setWindowTitle(_q("Board"));
 
-    ScoreWidget *scores = new ScoreWidget;
-    QObject::connect(this, SIGNAL(gameChanged(const Game*)),
-                     scores, SLOT(setGame(const Game*)));
-
-    HistoryWidget *historyWidget = new HistoryWidget;
-    QObject::connect(this, SIGNAL(historyChanged(const History*)),
-                     historyWidget, SLOT(setHistory(const History*)));
-
     QHBoxLayout *hlayout = new QHBoxLayout;
     hlayout->addWidget(dock);
-    hlayout->addWidget(scores);
-    hlayout->addWidget(historyWidget);
 
     m_ui.groupBoxTest->setLayout(hlayout);
 
+    // History
+    HistoryTabWidget *historyTab = new HistoryTabWidget;
+    QObject::connect(this, SIGNAL(gameChanged(const Game*)),
+                     historyTab, SLOT(setGame(const Game*)));
+    QObject::connect(this, SIGNAL(gameUpdated()),
+                     historyTab, SLOT(refresh()));
+    QHBoxLayout *hlayout2 = new QHBoxLayout;
+    hlayout2->addWidget(historyTab);
+    m_ui.groupBoxHistory->setLayout(hlayout2);
+
+    // Players racks
+    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(gameUpdated()), players, SLOT(refresh()));
+    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)));
+
+    // Players score
+    ScoreWidget *scores = new ScoreWidget;
+    QObject::connect(this, SIGNAL(gameChanged(const Game*)),
+                     scores, SLOT(setGame(const Game*)));
+    QObject::connect(this, SIGNAL(gameUpdated()),
+                     scores, SLOT(refresh()));
+    m_ui.groupBoxPlayers->layout()->addWidget(scores);
+
     // XXX: temporary, for testing purposes!
     try
     {
@@ -122,11 +140,13 @@
     if (m_bagWindow == NULL)
     {
         // Create the bag window
-        BagWidget *bagWidget =
-            new BagWidget(NULL, m_game ? &m_game->getBag() : NULL);
+        BagWidget *bagWidget = new BagWidget(NULL);
+        bagWidget->setGame(m_game);
         m_bagWindow = new AuxWindow(*bagWidget, m_ui.action_Bag);
-        QObject::connect(this, SIGNAL(bagChanged(const Bag*)),
-                         bagWidget, SLOT(setBag(const Bag*)));
+        QObject::connect(this, SIGNAL(gameChanged(const Game*)),
+                         bagWidget, SLOT(setGame(const Game*)));
+        QObject::connect(this, SIGNAL(gameUpdated()),
+                         bagWidget, SLOT(refresh()));
         // XXX
         m_bagWindow->move(20, 20);
     }
@@ -158,6 +178,22 @@
 }
 
 
+void MainWindow::destroyCurrentGame()
+{
+    if (m_game == NULL)
+        return;
+
+    // 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 gameChanged(NULL);
+
+    m_ui.groupBoxPlayers->hide();
+
+    delete m_game;
+    m_game = NULL;
+}
+
+
 void MainWindow::on_action_New_Game_triggered()
 {
     if (m_dic == NULL)
@@ -166,43 +202,26 @@
         return;
     }
 
-    if (m_newGame == NULL)
-        m_newGame = new NewGame(this);
+    if (m_newGameDialog == NULL)
+        m_newGameDialog = new NewGame(this);
 
-    int res = m_newGame->exec();
+    int res = m_newGameDialog->exec();
     if (res == QDialog::Rejected)
         return;
 
-    m_game = m_newGame->createGame(*m_dic);
+    // Destroy the game and the associated controls
+    destroyCurrentGame();
+
+    // Create a new game
+    m_game = m_newGameDialog->createGame(*m_dic);
     if (m_game == NULL)
         return;
 
-    int nbTabs = m_ui.tabWidgetPlayers->count();
-    for (int i = 0; i < nbTabs; ++i)
-        m_ui.tabWidgetPlayers->removeTab(0);
+    m_ui.groupBoxPlayers->show();
 
     m_game->start();
-    for (unsigned int i = 0; i < m_game->getNPlayers(); ++i)
-    {
-        PlayerWidget *r = new PlayerWidget(NULL, i, m_game);
-        QObject::connect(this, SIGNAL(rackChanged()), r, SLOT(refresh()));
-        QObject::connect(r, SIGNAL(playingWord(unsigned int, QString, 
QString)),
-                         this, SLOT(playerPlays(unsigned int, QString, 
QString)));
-        QObject::connect(r, SIGNAL(passing(unsigned int, QString)),
-                         this, SLOT(playerPasses(unsigned int, QString)));
-        m_ui.tabWidgetPlayers->addTab(r, qfw(m_game->getPlayer(i).getName()));
-    }
-
     emit gameChanged(m_game);
-}
-
-
-void MainWindow::gameUpdated()
-{
-    emit bagChanged(&m_game->getBag());
-    emit boardChanged(&m_game->getBoard());
-    emit historyChanged(&m_game->getHistory());
-    emit rackChanged();
+    emit gameUpdated();
 }
 
 
@@ -219,7 +238,7 @@
         displayErrorMsg(error, qfl("playing word"));
         return;
     }
-    emit gameChanged(m_game);
+    emit gameUpdated();
 }
 
 
@@ -248,10 +267,7 @@
         displayErrorMsg(error, qfl("playing word"));
         return;
     }
-    emit bagChanged(&m_game->getBag());
-    emit boardChanged(&m_game->getBoard());
-    emit historyChanged(&m_game->getHistory());
-    emit rackChanged();
+    emit gameUpdated();
 }
 
 

Index: main_window.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/main_window.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- main_window.h       20 Jan 2008 18:40:13 -0000      1.1
+++ main_window.h       22 Jan 2008 15:30:21 -0000      1.2
@@ -45,28 +45,19 @@
 signals:
     void dicChanged(QString iDicFile, QString iDicName);
     void gameChanged(const Game *iGame);
-    void bagChanged(const Bag *iBag);
-    void boardChanged(const Board *iBoard);
-    void historyChanged(const History *iHistory);
-    void rackChanged();
+    void gameUpdated();
 
 public slots:
     void playerPlays(unsigned int p, QString iWord, QString iCoord);
     void playerPasses(unsigned int p, QString iLetters);
 
 private slots:
-    /// Emit various specific signals
-    void gameUpdated();
-
     void on_action_About_triggered();
     void on_action_Bag_triggered();
     void on_action_ChooseDic_triggered();
     void on_action_New_Game_triggered();
 
 private:
-    /// Display an error message to the user
-    void displayErrorMsg(QString iMsg, QString iContext = QString());
-
     /// Current dictionary
     const Dictionary *m_dic;
 
@@ -77,10 +68,17 @@
     Ui::MainWindow m_ui;
 
     /// Dialog for creating a new game
-    NewGame *m_newGame;
+    NewGame *m_newGameDialog;
 
     /// Bag window
     AuxWindow *m_bagWindow;
+
+    /// Display an error message to the user
+    void displayErrorMsg(QString iMsg, QString iContext = QString());
+
+    /// Destroy the current game (if any) and the associated widgets
+    void destroyCurrentGame();
+
 };
 
 #endif

Index: player_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- player_widget.cpp   20 Jan 2008 18:40:13 -0000      1.1
+++ player_widget.cpp   22 Jan 2008 15:30:21 -0000      1.2
@@ -210,3 +210,49 @@
     return Acceptable;
 }
 
+
+
+PlayerTabWidget::PlayerTabWidget(QWidget *parent)
+    : QTabWidget(parent), m_game(NULL)
+{
+}
+
+
+void PlayerTabWidget::setGame(const Game *iGame)
+{
+    m_game = iGame;
+
+    if (m_game == NULL)
+    {
+        // Cut all the connections with the pages
+        disconnect();
+
+        // Remove all the tabs
+        int nbTabs = count();
+        for (int i = 0; i < nbTabs; ++i)
+            removeTab(0);
+    }
+    else
+    {
+        // Add one tab per player
+        for (unsigned int i = 0; i < m_game->getNPlayers(); ++i)
+        {
+            const Player &player = m_game->getPlayer(i);
+            PlayerWidget *p = new PlayerWidget(NULL, i, m_game);
+            QObject::connect(this, SIGNAL(refreshSignal()), p, 
SLOT(refresh()));
+            QObject::connect(p, SIGNAL(passing(unsigned int, QString)),
+                             this, SIGNAL(passing(unsigned int, QString)));
+            QObject::connect(p, SIGNAL(playingWord(unsigned int, QString, 
QString)),
+                             this, SIGNAL(playingWord(unsigned int, QString, 
QString)));
+            addTab(p, qfw(player.getName()));
+        }
+    }
+}
+
+
+void PlayerTabWidget::refresh()
+{
+    emit refreshSignal();
+}
+
+

Index: player_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- player_widget.h     20 Jan 2008 18:40:13 -0000      1.1
+++ player_widget.h     22 Jan 2008 15:30:21 -0000      1.2
@@ -22,6 +22,7 @@
 #define RACK_WIDGET_H_
 
 #include <QtGui/QWidget>
+#include <QtGui/QTabWidget>
 #include "ui/player_widget.ui.h"
 
 
@@ -36,7 +37,6 @@
     explicit PlayerWidget(QWidget *parent = 0,
                           unsigned int iPlayerNb = 0,
                           const Game *iGame = NULL);
-    QSize sizeHint() const;
 
 signals:
     void playingWord(unsigned int iPlayer, QString iWord, QString iCoord);
@@ -45,6 +45,9 @@
 public slots:
     void refresh();
 
+protected:
+    virtual QSize sizeHint() const;
+
 private slots:
     void on_pushButtonShuffle_clicked();
     void on_pushButtonPlay_clicked() { on_lineEditPlay_returnPressed(); }
@@ -64,5 +67,27 @@
 
 };
 
+
+class PlayerTabWidget: public QTabWidget
+{
+    Q_OBJECT;
+
+public:
+    explicit PlayerTabWidget(QWidget *parent = 0);
+
+public slots:
+    void setGame(const Game *iGame);
+    void refresh();
+
+signals:
+    void refreshSignal();
+    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.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- score_widget.cpp    20 Jan 2008 18:40:14 -0000      1.1
+++ score_widget.cpp    22 Jan 2008 15:30:22 -0000      1.2
@@ -53,6 +53,12 @@
 }
 
 
+void ScoreWidget::refresh()
+{
+    updateModel();
+}
+
+
 void ScoreWidget::updateModel()
 {
     m_model->clear();

Index: score_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/score_widget.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- score_widget.h      20 Jan 2008 18:40:14 -0000      1.1
+++ score_widget.h      22 Jan 2008 15:30:22 -0000      1.2
@@ -36,6 +36,7 @@
 
 public slots:
     void setGame(const Game *iGame = NULL);
+    void refresh();
 
 protected:
     /// Define a default size

Index: ui/main_window.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/main_window.ui,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ui/main_window.ui   20 Jan 2008 18:40:14 -0000      1.1
+++ ui/main_window.ui   22 Jan 2008 15:30:22 -0000      1.2
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>683</width>
-    <height>589</height>
+    <width>828</width>
+    <height>588</height>
    </rect>
   </property>
   <property name="windowTitle" >
@@ -18,6 +18,8 @@
   <widget class="QWidget" name="centralwidget" >
    <layout class="QVBoxLayout" >
     <item>
+     <layout class="QHBoxLayout" >
+      <item>
      <widget class="QGroupBox" name="groupBoxTest" >
       <property name="sizePolicy" >
        <sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
@@ -26,23 +28,31 @@
        </sizepolicy>
       </property>
       <property name="title" >
-       <string>GroupBox</string>
+         <string>_("Board")</string>
       </property>
      </widget>
     </item>
     <item>
-     <widget class="QTabWidget" name="tabWidgetPlayers" >
+       <widget class="QGroupBox" name="groupBoxHistory" >
       <property name="sizePolicy" >
-       <sizepolicy vsizetype="Preferred" hsizetype="Expanding" >
+         <sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
         <horstretch>0</horstretch>
         <verstretch>0</verstretch>
        </sizepolicy>
       </property>
-      <widget class="QWidget" name="tab" >
-       <attribute name="title" >
-        <string>_("No game")</string>
-       </attribute>
+        <property name="title" >
+         <string>_("History")</string>
+        </property>
       </widget>
+      </item>
+     </layout>
+    </item>
+    <item>
+     <widget class="QGroupBox" name="groupBoxPlayers" >
+      <property name="title" >
+       <string>_("Players")</string>
+      </property>
+      <layout class="QHBoxLayout" />
      </widget>
     </item>
    </layout>
@@ -52,8 +62,8 @@
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>683</width>
-     <height>28</height>
+     <width>828</width>
+     <height>29</height>
     </rect>
    </property>
    <widget class="QMenu" name="menuFile" >
@@ -89,6 +99,17 @@
    <addaction name="menu_Help" />
   </widget>
   <widget class="QStatusBar" name="statusbar" />
+  <widget class="QToolBar" name="toolBar" >
+   <property name="windowTitle" >
+    <string>toolBar</string>
+   </property>
+   <attribute name="toolBarArea" >
+    <enum>TopToolBarArea</enum>
+   </attribute>
+   <attribute name="toolBarBreak" >
+    <bool>false</bool>
+   </attribute>
+  </widget>
   <action name="action_ChooseDic" >
    <property name="text" >
     <string>&amp;Choose dictionary...</string>

Index: ui/player_widget.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/player_widget.ui,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ui/player_widget.ui 20 Jan 2008 18:40:14 -0000      1.1
+++ ui/player_widget.ui 22 Jan 2008 15:30:22 -0000      1.2
@@ -5,11 +5,14 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>599</width>
-    <height>170</height>
+    <width>460</width>
+    <height>125</height>
    </rect>
   </property>
   <layout class="QGridLayout" >
+   <property name="horizontalSpacing" >
+    <number>-1</number>
+   </property>
    <item row="0" column="0" >
     <widget class="QLabel" name="label" >
      <property name="text" >
@@ -46,6 +49,9 @@
      <property name="toolTip" >
       <string>_("To play a word, enter the word (case sensitive) and its 
coordinates. E.g.: WORD H4")</string>
      </property>
+     <property name="statusTip" >
+      <string>_("To play a word, enter the word (case sensitive) and its 
coordinates. E.g.: WORD H4")</string>
+     </property>
      <property name="text" >
       <string>dummy</string>
      </property>
@@ -89,26 +95,6 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="0" colspan="3" >
-    <widget class="QLabel" name="label_3" >
-     <property name="text" >
-      <string>_("To play a word, enter the word (case sensitive) and its 
coordinates. E.g.: WORD H4")</string>
-     </property>
-    </widget>
-   </item>
-   <item row="4" column="1" >
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeHint" >
-      <size>
-       <width>20</width>
-       <height>20</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
   </layout>
  </widget>
  <resources/>




reply via email to

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