mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 17:02:15 -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)
|
void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
|
|
||||||
if (width() == 0 || height() == 0) {
|
if (width() == 0 || height() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -159,19 +160,19 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
||||||
|
|
||||||
// Adjust scaling after rotation
|
// Adjust scaling after rotation
|
||||||
const QSize availableSize = size(); // Size of the widget
|
const QSize availableSize = size(); // Size of the widget
|
||||||
const QSize pixmapSize = transformedPixmap.size();
|
const QSize scaledSize = transformedPixmap.size().scaled(availableSize, Qt::KeepAspectRatio);
|
||||||
const QSize scaledSize = pixmapSize.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();
|
const qreal radius = 0.05 * scaledSize.width();
|
||||||
|
|
||||||
|
// Draw the pixmap with rounded corners
|
||||||
QStylePainter painter(this);
|
QStylePainter painter(this);
|
||||||
QPainterPath shape;
|
QPainterPath shape;
|
||||||
shape.addRoundedRect(QRect(topLeft, scaledSize), radius, radius);
|
shape.addRoundedRect(targetRect, radius, radius);
|
||||||
painter.setClipPath(shape);
|
painter.setClipPath(shape);
|
||||||
painter.drawItemPixmap(QRect(topLeft, scaledSize), Qt::AlignCenter,
|
painter.drawPixmap(targetRect, transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue