From bef33426e889a9f8f550f85a40b15155ac263084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Wed, 18 Dec 2024 19:01:57 +0100 Subject: [PATCH] Rotate split cards and battles in the CardInfoWidget. --- .../cards/card_info_picture_widget.cpp | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/client/ui/widgets/cards/card_info_picture_widget.cpp b/cockatrice/src/client/ui/widgets/cards/card_info_picture_widget.cpp index 284660037..9a9f477e4 100644 --- a/cockatrice/src/client/ui/widgets/cards/card_info_picture_widget.cpp +++ b/cockatrice/src/client/ui/widgets/cards/card_info_picture_widget.cpp @@ -149,17 +149,33 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event) loadPixmap(); } - const QSize scaledSize = resizedPixmap.size().scaled(size(), Qt::KeepAspectRatio); - const QPoint topLeft{(width() - scaledSize.width()) / 2, (height() - scaledSize.height()) / 2}; + QPixmap transformedPixmap = resizedPixmap; // Default pixmap + if (info && (info->getProperty("layout") == "split" || info->getProperty("maintype") == "Battle")) { + // Rotate pixmap 90 degrees to the left + QTransform transform; + transform.rotate(90); + transformedPixmap = resizedPixmap.transformed(transform, Qt::SmoothTransformation); + } + + // 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 QPoint topLeft{(availableSize.width() - scaledSize.width()) / 2, + (availableSize.height() - scaledSize.height()) / 2}; const qreal radius = 0.05 * scaledSize.width(); QStylePainter painter(this); QPainterPath shape; shape.addRoundedRect(QRect(topLeft, scaledSize), radius, radius); painter.setClipPath(shape); - painter.drawItemPixmap(QRect(topLeft, scaledSize), Qt::AlignCenter, resizedPixmap); + painter.drawItemPixmap(QRect(topLeft, scaledSize), Qt::AlignCenter, + transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } + + /** * @brief Provides the recommended size for the widget based on the scale factor. * @return The recommended widget size.