TileWidget: change the prototype of tileChanged() and improve the possible states

This commit is contained in:
Olivier Teulière 2012-01-29 17:09:31 +01:00
parent 00a98a7c31
commit 85e79e0294
4 changed files with 16 additions and 17 deletions

View file

@ -58,7 +58,7 @@ void BagWidget2::setGame(const PublicGame *iGame)
{
TileWidget *tileWidget = new TileWidget(NULL, TileWidget::NONE, 0, 0);
tileWidget->setBorder();
tileWidget->tileChanged(tile, false, TileWidget::NORMAL);
tileWidget->tileChanged(TileWidget::NORMAL, tile);
layout->addWidget(tileWidget);
}
}
@ -81,13 +81,13 @@ void BagWidget2::refresh()
for (unsigned i = 0; i < nbInBag; ++i)
{
TileWidget *tileWidget = (TileWidget*) layout()->itemAt(index)->widget();
tileWidget->tileChanged(tile, false, TileWidget::NORMAL);
tileWidget->tileChanged(TileWidget::NORMAL, tile);
++index;
}
for (unsigned i = nbInBag; i < tile.maxNumber(); ++i)
{
TileWidget *tileWidget = (TileWidget*) layout()->itemAt(index)->widget();
tileWidget->tileChanged(tile, false, TileWidget::PLAYED);
tileWidget->tileChanged(TileWidget::RACK_PLAYED, tile);
++index;
}
}

View file

@ -137,18 +137,18 @@ void BoardWidget::refresh()
{
for (unsigned int col = BOARD_MIN; col <= BOARD_MAX; ++col)
{
if (!m_showTemporarySigns && board.isTestChar(row, col))
if (board.isVacant(row, col) ||
(board.isTestChar(row, col) && !m_showTemporarySigns))
{
// Force an empty square.
m_widgetsMatrix[row][col]->tileChanged(
Tile(), false, TileWidget::NORMAL);
m_widgetsMatrix[row][col]->tileChanged(TileWidget::BOARD_EMPTY);
}
else
{
m_widgetsMatrix[row][col]->tileChanged(
board.isTestChar(row, col) ? TileWidget::PREVIEW : TileWidget::NORMAL,
board.getTile(row, col),
board.isJoker(row, col),
board.isTestChar(row, col) ? TileWidget::PREVIEW : TileWidget::NORMAL);
board.isJoker(row, col));
}
}
}
@ -160,8 +160,7 @@ void BoardWidget::refresh()
{
for (unsigned int col = BOARD_MIN; col <= BOARD_MAX; ++col)
{
m_widgetsMatrix[row][col]->tileChanged(
Tile(), false, TileWidget::NORMAL);
m_widgetsMatrix[row][col]->tileChanged(TileWidget::BOARD_EMPTY);
}
}
}

View file

@ -106,7 +106,7 @@ int TileWidget::getSquareSize() const
}
void TileWidget::tileChanged(const Tile &iTile, bool isJoker, State state)
void TileWidget::tileChanged(State state, const Tile &iTile, bool isJoker)
{
// This avoids a lot of useless redraws
if (m_state == state && m_tile == iTile && m_isJoker == isJoker)
@ -157,11 +157,11 @@ void TileWidget::paintEvent(QPaintEvent *iEvent)
// Set the square color
QColor color;
if (!m_tile.isEmpty())
if (!m_tile.isEmpty() && m_state != BOARD_EMPTY)
{
if (m_state == PREVIEW)
color = TilePreviewColour;
else if (m_state == PLAYED)
else if (m_state == RACK_PLAYED)
color = TilePlayedColour;
else
color = TileNormalColour;
@ -233,7 +233,7 @@ void TileWidget::paintEvent(QPaintEvent *iEvent)
painter.drawPolygon(points, 7);
}
if (m_state == PLAYED)
if (m_state == RACK_PLAYED)
{
painter.setPen(TextNormalColour);
painter.drawLine(QLine(0, 0, squareSize, squareSize));

View file

@ -51,8 +51,8 @@ public:
COORDS,
NORMAL,
PREVIEW,
PLAYED,
IN_RACK
BOARD_EMPTY,
RACK_PLAYED,
};
explicit TileWidget(QWidget *parent = 0, Multiplier multiplier = NONE,
@ -70,7 +70,7 @@ public:
virtual QSize sizeHint() const;
public slots:
//void tileChanged(const Tile &iTile, bool isJoker, State state);
void tileChanged(State state, const Tile &iTile = Tile(), bool isJoker = false);
void arrowChanged(bool showArrow, bool horizontalArrow);
signals: