TileLayout: fix a bug (the rect offset was not taken into account)

This commit is contained in:
Olivier Teulière 2012-12-17 20:20:18 +01:00
parent db6e81a288
commit b5c36bed26
2 changed files with 6 additions and 5 deletions

View file

@ -197,10 +197,11 @@ void BoardWidget::paintEvent(QPaintEvent *)
const int size = boardLayout->getSquareSize(); const int size = boardLayout->getSquareSize();
const int spacing = boardLayout->spacing(); const int spacing = boardLayout->spacing();
// Draw lines between tiles
QLine hLine(0, 0, rect.width() + 1, 0); QLine hLine(0, 0, rect.width() + 1, 0);
QLine vLine(0, 0, 0, rect.height() + 1); QLine vLine(0, 0, 0, rect.height() + 1);
hLine.translate(size, size); hLine.translate(rect.left() - 1, rect.top() - 1);
vLine.translate(size, size); vLine.translate(rect.left() - 1, rect.top() - 1);
for (int i = 0; i <= BOARD_MAX; ++i) for (int i = 0; i <= BOARD_MAX; ++i)
{ {
painter.drawLine(hLine); painter.drawLine(hLine);
@ -208,7 +209,7 @@ void BoardWidget::paintEvent(QPaintEvent *)
hLine.translate(0, size + spacing); hLine.translate(0, size + spacing);
vLine.translate(size + spacing, 0); vLine.translate(size + spacing, 0);
} }
//painter.drawRect(rect); // Draw a second line around the board, so that it looks nicer
painter.drawRect(rect.adjusted(-2, -2, 1, 1)); painter.drawRect(rect.adjusted(-2, -2, 1, 1));
} }

View file

@ -178,12 +178,12 @@ void TileLayout::setGeometry(const QRect &rect)
const int squareSize = squareSizeWithSpacing - spacing(); const int squareSize = squareSizeWithSpacing - spacing();
// Handle margins and alignment // Handle margins and alignment
int x = contentsMargins().left(); int x = contentsRect().left() + contentsMargins().left();
if (alignment() & Qt::AlignRight) if (alignment() & Qt::AlignRight)
x += width - m_nbCols * squareSizeWithSpacing; x += width - m_nbCols * squareSizeWithSpacing;
else if (alignment() & Qt::AlignHCenter) else if (alignment() & Qt::AlignHCenter)
x += (width - m_nbCols * squareSizeWithSpacing) / 2; x += (width - m_nbCols * squareSizeWithSpacing) / 2;
int y = contentsMargins().top(); int y = contentsRect().top() + contentsMargins().top();
if (alignment() & Qt::AlignBottom) if (alignment() & Qt::AlignBottom)
y += height - m_nbRows * squareSizeWithSpacing; y += height - m_nbRows * squareSizeWithSpacing;
else if (alignment() & Qt::AlignVCenter) else if (alignment() & Qt::AlignVCenter)