fix scaling for background images on home tab (#6656)

This commit is contained in:
ebbit1q 2026-03-04 00:16:45 +01:00 committed by GitHub
parent 43acac5f5d
commit 566c876bdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 18 deletions

View File

@ -8,7 +8,7 @@ CardInfoPictureArtCropWidget::CardInfoPictureArtCropWidget(QWidget *parent)
hide(); hide();
} }
QPixmap CardInfoPictureArtCropWidget::getProcessedBackground(const QSize &targetSize) QPixmap CardInfoPictureArtCropWidget::getBackground()
{ {
// Load the full-resolution card image, not a pre-scaled one // Load the full-resolution card image, not a pre-scaled one
QPixmap fullResPixmap; QPixmap fullResPixmap;
@ -17,10 +17,8 @@ QPixmap CardInfoPictureArtCropWidget::getProcessedBackground(const QSize &target
} else { } else {
CardPictureLoader::getCardBackPixmap(fullResPixmap, QSize(745, 1040)); CardPictureLoader::getCardBackPixmap(fullResPixmap, QSize(745, 1040));
} }
// Fail-safe if loading failed
if (fullResPixmap.isNull()) { if (fullResPixmap.isNull()) {
return QPixmap(targetSize); return QPixmap(); // return null qpixmap
} }
const QSize sz = fullResPixmap.size(); const QSize sz = fullResPixmap.size();
@ -33,9 +31,7 @@ QPixmap CardInfoPictureArtCropWidget::getProcessedBackground(const QSize &target
foilRect = foilRect.intersected(fullResPixmap.rect()); // always clamp to source bounds foilRect = foilRect.intersected(fullResPixmap.rect()); // always clamp to source bounds
// Crop first, then scale for best quality // return full resolution image crop
QPixmap cropped = fullResPixmap.copy(foilRect); QPixmap cropped = fullResPixmap.copy(foilRect);
QPixmap scaled = cropped.scaled(targetSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); return cropped;
return scaled;
} }

View File

@ -16,8 +16,8 @@ class CardInfoPictureArtCropWidget : public CardInfoPictureWidget
public: public:
explicit CardInfoPictureArtCropWidget(QWidget *parent = nullptr); explicit CardInfoPictureArtCropWidget(QWidget *parent = nullptr);
// Returns a processed (cropped & scaled) version of the pixmap // Returns a cropped version of the pixmap
QPixmap getProcessedBackground(const QSize &targetSize); QPixmap getBackground();
}; };
#endif // CARD_INFO_PICTURE_ART_CROP_WIDGET_H #endif // CARD_INFO_PICTURE_ART_CROP_WIDGET_H

View File

@ -125,7 +125,7 @@ void HomeWidget::updateRandomCard()
connect(newCard.getCardPtr().data(), &CardInfo::pixmapUpdated, this, &HomeWidget::updateBackgroundProperties); connect(newCard.getCardPtr().data(), &CardInfo::pixmapUpdated, this, &HomeWidget::updateBackgroundProperties);
backgroundSourceCard->setCard(newCard); backgroundSourceCard->setCard(newCard);
background = backgroundSourceCard->getProcessedBackground(size()); background = backgroundSourceCard->getBackground();
if (SettingsCache::instance().getHomeTabBackgroundShuffleFrequency() <= 0) { if (SettingsCache::instance().getHomeTabBackgroundShuffleFrequency() <= 0) {
cardChangeTimer->stop(); cardChangeTimer->stop();
@ -143,7 +143,7 @@ void HomeWidget::onBackgroundShuffleFrequencyChanged()
void HomeWidget::updateBackgroundProperties() void HomeWidget::updateBackgroundProperties()
{ {
background = backgroundSourceCard->getProcessedBackground(size()); background = backgroundSourceCard->getBackground();
updateButtonsToBackgroundColor(); updateButtonsToBackgroundColor();
update(); // Triggers repaint update(); // Triggers repaint
} }
@ -301,14 +301,17 @@ void HomeWidget::paintEvent(QPaintEvent *event)
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
background = background.scaled(size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation); if (!background.isNull()) {
QSize widgetSize = size() * devicePixelRatio();
QPixmap toDraw = background.scaled(widgetSize, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
// Draw already-scaled background centered // Draw scaled background centered
QSize widgetSize = size(); QSize bgSize = toDraw.size();
QSize bgSize = background.size(); QPoint topLeft((widgetSize.width() - bgSize.width()) / (devicePixelRatio() * 2), // undo scaling for painter
QPoint topLeft((widgetSize.width() - bgSize.width()) / 2, (widgetSize.height() - bgSize.height()) / 2); (widgetSize.height() - bgSize.height()) / (devicePixelRatio() * 2));
painter.drawPixmap(topLeft, background); painter.drawPixmap(topLeft, toDraw);
}
// Draw translucent black overlay with rounded corners // Draw translucent black overlay with rounded corners
QRectF overlayRect(5, 5, width() - 10, height() - 10); QRectF overlayRect(5, 5, width() - 10, height() - 10);