Better elision.

This commit is contained in:
Brübach, Lukas 2025-11-25 12:17:11 +01:00
parent 3cad29bbe2
commit 919da0663f

View file

@ -192,13 +192,20 @@ void ArchidektApiResponseDeckEntryDisplayWidget::updateScaledPreview()
QPixmap scaled =
originalPixmap.scaled(newWidth, newHeight, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
// 2. Crop to exact target size (for safety)
// 2. Crop to exact target 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);
// Update the elided deck name based on new width
int textMaxWidth = int(newWidth * 0.7); // allow 70% of width for text
QFontMetrics fm(previewWidget->topLeftLabel->font());
QString elided = fm.elidedText(response.getName(), Qt::ElideRight, textMaxWidth);
previewWidget->topLeftLabel->setText(elided);
previewWidget->topLeftLabel->setToolTip(response.getName());
setFixedWidth(newWidth);
layout->invalidate();