mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 00:42:14 -07:00
Fix the image shrinking due to repeated scaling and FP precision loss.
This commit is contained in:
parent
3cf0904651
commit
1365eb9146
1 changed files with 8 additions and 7 deletions
|
|
@ -141,6 +141,7 @@ void CardInfoPictureWidget::loadPixmap()
|
|||
void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
|
||||
if (width() == 0 || height() == 0) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -159,19 +160,19 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
|||
|
||||
// Adjust scaling after rotation
|
||||
const QSize availableSize = size(); // Size of the widget
|
||||
const QSize pixmapSize = transformedPixmap.size();
|
||||
const QSize scaledSize = pixmapSize.scaled(availableSize, Qt::KeepAspectRatio);
|
||||
const QSize scaledSize = transformedPixmap.size().scaled(availableSize, Qt::KeepAspectRatio);
|
||||
|
||||
const QRect targetRect{(availableSize.width() - scaledSize.width()) / 2,
|
||||
(availableSize.height() - scaledSize.height()) / 2, scaledSize.width(), scaledSize.height()};
|
||||
|
||||
const QPoint topLeft{(availableSize.width() - scaledSize.width()) / 2,
|
||||
(availableSize.height() - scaledSize.height()) / 2};
|
||||
const qreal radius = 0.05 * scaledSize.width();
|
||||
|
||||
// Draw the pixmap with rounded corners
|
||||
QStylePainter painter(this);
|
||||
QPainterPath shape;
|
||||
shape.addRoundedRect(QRect(topLeft, scaledSize), radius, radius);
|
||||
shape.addRoundedRect(targetRect, radius, radius);
|
||||
painter.setClipPath(shape);
|
||||
painter.drawItemPixmap(QRect(topLeft, scaledSize), Qt::AlignCenter,
|
||||
transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
painter.drawPixmap(targetRect, transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue