Consistent sizes.

This commit is contained in:
Brübach, Lukas 2025-11-25 10:38:28 +01:00
parent 223035f452
commit 25f7c75b15

View file

@ -164,8 +164,11 @@ void ArchidektApiResponseDeckEntryDisplayWidget::onPreviewImageLoadFinished(QNet
originalPixmap = loaded; originalPixmap = loaded;
float ratio = float(originalPixmap.height()) / float(originalPixmap.width()); // universal fallback/design aspect ratio
previewWidget->setAspectRatio(ratio); static constexpr float DESIGN_RATIO = 150.0f / 267.0f;
// Always scale preview widget to this ratio
previewWidget->setAspectRatio(DESIGN_RATIO);
previewWidget->setPreviewWidth(400); previewWidget->setPreviewWidth(400);
// Initial scaling // Initial scaling
@ -181,22 +184,25 @@ void ArchidektApiResponseDeckEntryDisplayWidget::updateScaledPreview()
int baseWidth = 400; int baseWidth = 400;
int newWidth = baseWidth * scaleFactor / 100; int newWidth = baseWidth * scaleFactor / 100;
int newHeight = int(newWidth * (150.0 / 267.0));
// 1. Resize the preview widget itself (keeps aspect ratio) previewWidget->setFixedSize(newWidth, newHeight);
previewWidget->setPreviewWidth(newWidth);
// 2. Scale pixmap from the original // 1. Scale image to fill the preview area (crop edges)
QPixmap scaled = originalPixmap.scaled(previewWidget->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QPixmap scaled =
originalPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
picture->setPixmap(scaled); // 2. Crop to exact target size (for safety)
picture->setFixedSize(previewWidget->size()); QRect cropRect((scaled.width() - newWidth) / 2, (scaled.height() - newHeight) / 2, newWidth, newHeight);
QPixmap cropped = scaled.copy(cropRect);
picture->setPixmap(cropped);
picture->setFixedSize(newWidth, newHeight);
// 3. Scale the whole outer widget width (this)
setFixedWidth(newWidth); setFixedWidth(newWidth);
layout->invalidate(); layout->invalidate();
layout->activate(); layout->activate();
layout->update();
updateGeometry(); updateGeometry();
} }