Modify the target Square in the puzzle

targetSquare judges which square the position falls in. The point
scaling calculation method should not be used. The return value of
QPoint operator/ will be rounded up. Modified to separate the x and
y of position to calculate.

Fixes: QTBUG-81842
Change-Id: I70375185a78ba47efe01be3fd490e0fb0f456e17
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Tang Haixiang 2021-10-29 11:40:46 +08:00 committed by Shawn Rutledge
parent ace53d282d
commit f5eda09a63
2 changed files with 4 additions and 4 deletions

View File

@ -199,8 +199,8 @@ void PuzzleWidget::paintEvent(QPaintEvent *event)
const QRect PuzzleWidget::targetSquare(const QPoint &position) const
{
return QRect(position / pieceSize() * pieceSize(),
QSize(pieceSize(), pieceSize()));
QPoint topLeft = QPoint(position.x() / pieceSize(), position.y() / pieceSize()) * pieceSize();
return QRect(topLeft, QSize(pieceSize(), pieceSize()));
}
int PuzzleWidget::pieceSize() const

View File

@ -195,8 +195,8 @@ void PuzzleWidget::paintEvent(QPaintEvent *event)
const QRect PuzzleWidget::targetSquare(const QPoint &position) const
{
return QRect(position / pieceSize() * pieceSize(),
QSize(pieceSize(), pieceSize()));
QPoint topLeft = QPoint(position.x() / pieceSize(), position.y() / pieceSize()) * pieceSize();
return QRect(topLeft, QSize(pieceSize(), pieceSize()));
}
int PuzzleWidget::pieceSize() const