mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-27 09:58:08 +01:00
RackWidget: update the visual rack only when the game rack changes.
This avoids losing the state when any unrelated update happens in the game (for example when clicking on the board to set the coordinates).
This commit is contained in:
parent
f37b3f7d84
commit
c285e37354
3 changed files with 45 additions and 31 deletions
|
@ -168,8 +168,8 @@ MainWindow::MainWindow(QWidget *iParent)
|
|||
rackWidget->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
|
||||
QObject::connect(m_gameSignals, SIGNAL(gameChanged(const PublicGame*)),
|
||||
rackWidget, SLOT(setGame(const PublicGame*)));
|
||||
QObject::connect(m_gameSignals, SIGNAL(gameUpdated()),
|
||||
rackWidget, SLOT(refresh()));
|
||||
QObject::connect(m_gameSignals, SIGNAL(gameRackChanged(const PlayedRack&)),
|
||||
rackWidget, SLOT(setRack(const PlayedRack&)));
|
||||
vSplitter->addWidget(rackWidget);
|
||||
|
||||
hlayout->addWidget(vSplitter);
|
||||
|
@ -1283,8 +1283,8 @@ void MainWindow::onWindowsBoard()
|
|||
rackWidget->setGame(m_game);
|
||||
QObject::connect(m_gameSignals, SIGNAL(gameChanged(const PublicGame*)),
|
||||
rackWidget, SLOT(setGame(const PublicGame*)));
|
||||
QObject::connect(m_gameSignals, SIGNAL(gameUpdated()),
|
||||
rackWidget, SLOT(refresh()));
|
||||
QObject::connect(m_gameSignals, SIGNAL(gameRackChanged(const PlayedRack&)),
|
||||
rackWidget, SLOT(setRack(const PlayedRack&)));
|
||||
hSplitter->addWidget(rackWidget);
|
||||
|
||||
hSplitter->addWidget(new QWidget);
|
||||
|
|
|
@ -81,32 +81,36 @@ void RackWidget::setGame(const PublicGame *iGame)
|
|||
layout->clear();
|
||||
m_tilesVect.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RackWidget::setRack(const PlayedRack &iRack)
|
||||
{
|
||||
ASSERT(m_game != NULL, "setRack() called without a game");
|
||||
if (m_showOnlyLastTurn && !m_game->isLastTurn())
|
||||
return;
|
||||
|
||||
// Get the tiles
|
||||
vector<Tile> tiles;
|
||||
iRack.getAllTiles(tiles);
|
||||
|
||||
// Update the rack
|
||||
setTiles(tiles);
|
||||
}
|
||||
|
||||
|
||||
void RackWidget::setTiles(const vector<Tile> &iTiles)
|
||||
{
|
||||
m_tiles = iTiles;
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
||||
void RackWidget::refresh()
|
||||
{
|
||||
if (m_game == NULL)
|
||||
return;
|
||||
m_filteredTiles = filterRack(m_tiles);
|
||||
|
||||
if (m_showOnlyLastTurn && !m_game->isLastTurn())
|
||||
return;
|
||||
|
||||
// Get the tiles
|
||||
vector<Tile> tiles;
|
||||
m_game->getCurrentRack().getAllTiles(tiles);
|
||||
|
||||
// Update the rack
|
||||
setRack(tiles);
|
||||
}
|
||||
|
||||
|
||||
void RackWidget::setRack(const vector<Tile> &iTiles)
|
||||
{
|
||||
m_tiles = filterRack(iTiles);
|
||||
|
||||
unsigned tilesCount = m_tiles.size();
|
||||
unsigned tilesCount = m_filteredTiles.size();
|
||||
|
||||
// Make sure we have as many widgets as there are letters in the rack
|
||||
while (m_tilesVect.size() > tilesCount)
|
||||
|
@ -286,15 +290,15 @@ void RackWidget::moveTile(int fromPos, int toPos, bool shaded)
|
|||
if (fromPos != toPos)
|
||||
{
|
||||
// Change the order
|
||||
Tile moved = m_tiles[fromPos];
|
||||
m_tiles.erase(m_tiles.begin() + fromPos);
|
||||
m_tiles.insert(m_tiles.begin() + toPos, moved);
|
||||
Tile moved = m_filteredTiles[fromPos];
|
||||
m_filteredTiles.erase(m_filteredTiles.begin() + fromPos);
|
||||
m_filteredTiles.insert(m_filteredTiles.begin() + toPos, moved);
|
||||
// Update the rack
|
||||
setRack(m_tiles);
|
||||
setTiles(m_filteredTiles);
|
||||
}
|
||||
// Change the look of the moved tile
|
||||
m_tilesVect[toPos]->tileChanged(shaded ? TileWidget::SHADED : TileWidget::NORMAL,
|
||||
m_tiles[toPos]);
|
||||
m_filteredTiles[toPos]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -52,8 +52,7 @@ public:
|
|||
|
||||
public slots:
|
||||
void setGame(const PublicGame *iGame);
|
||||
void refresh();
|
||||
void setRack(const vector<Tile> &iTiles);
|
||||
void setRack(const PlayedRack &iRack);
|
||||
|
||||
protected:
|
||||
virtual void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
@ -61,10 +60,21 @@ protected:
|
|||
virtual void dragMoveEvent(QDragMoveEvent *event);
|
||||
virtual void dropEvent(QDropEvent *event);
|
||||
|
||||
private slots:
|
||||
/**
|
||||
* Refresh the widget, using m_tiles as a reference.
|
||||
*/
|
||||
void refresh();
|
||||
/// Set the tiles and refresh the widget
|
||||
void setTiles(const vector<Tile> &iTiles);
|
||||
|
||||
private:
|
||||
/// Tiles from which widgets are created
|
||||
vector<Tile> m_tiles;
|
||||
|
||||
/// Tiles after filtering (removing from m_tiles the ones in the word being played)
|
||||
vector<Tile> m_filteredTiles;
|
||||
|
||||
/**
|
||||
* Encapsulated tiles.
|
||||
* Always in sync with m_tiles, except maybe during a drag & drop operation.
|
||||
|
@ -79,7 +89,7 @@ private:
|
|||
|
||||
/**
|
||||
* Indicate whether to show only the last rack
|
||||
* (useful for on the external board, in particular in arbitration mode)
|
||||
* (useful on the external board, in particular in arbitration mode)
|
||||
*/
|
||||
bool m_showOnlyLastTurn;
|
||||
|
||||
|
|
Loading…
Reference in a new issue