From 85e79e0294c9ad0cb117ccde8e3e0d38d4119b91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sun, 29 Jan 2012 17:09:31 +0100 Subject: [PATCH] TileWidget: change the prototype of tileChanged() and improve the possible states --- qt/bag_widget2.cpp | 6 +++--- qt/board_widget.cpp | 13 ++++++------- qt/tile_widget.cpp | 8 ++++---- qt/tile_widget.h | 6 +++--- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/qt/bag_widget2.cpp b/qt/bag_widget2.cpp index 0194119..fc48bdd 100644 --- a/qt/bag_widget2.cpp +++ b/qt/bag_widget2.cpp @@ -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; } } diff --git a/qt/board_widget.cpp b/qt/board_widget.cpp index 6954346..2c58a60 100644 --- a/qt/board_widget.cpp +++ b/qt/board_widget.cpp @@ -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); } } } diff --git a/qt/tile_widget.cpp b/qt/tile_widget.cpp index 6454cae..718cf96 100644 --- a/qt/tile_widget.cpp +++ b/qt/tile_widget.cpp @@ -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)); diff --git a/qt/tile_widget.h b/qt/tile_widget.h index 533fb9a..d8af2cf 100644 --- a/qt/tile_widget.h +++ b/qt/tile_widget.h @@ -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: