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 f9d4d68bf..1cb000d7c 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 @@ -1,6 +1,7 @@ #include "card_info_picture_widget.h" #include "../../../../game/cards/card_item.h" +#include "../../../../settings/cache_settings.h" #include "../../picture_loader.h" #include @@ -141,6 +142,7 @@ void CardInfoPictureWidget::loadPixmap() void CardInfoPictureWidget::paintEvent(QPaintEvent *event) { QWidget::paintEvent(event); + if (width() == 0 || height() == 0) { return; } @@ -150,28 +152,30 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event) } QPixmap transformedPixmap = resizedPixmap; // Default pixmap - if (info && info->getLandscapeOrientation()) { - // Rotate pixmap 90 degrees to the left - QTransform transform; - transform.rotate(90); - transformedPixmap = resizedPixmap.transformed(transform, Qt::SmoothTransformation); + if (SettingsCache::instance().getAutoRotateSidewaysLayoutCards()) { + if (info && info->getLandscapeOrientation()) { + // 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 QSize scaledSize = transformedPixmap.size().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(); + // Draw the pixmap with rounded corners QStylePainter painter(this); QPainterPath shape; - shape.addRoundedRect(QRect(topLeft, scaledSize), radius, radius); + shape.addRoundedRect(targetRect, radius, radius); painter.setClipPath(shape); - painter.drawItemPixmap(QRect(topLeft, scaledSize), Qt::AlignCenter, - transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + painter.drawPixmap(targetRect, transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation)); } /** diff --git a/cockatrice/src/dialogs/dlg_settings.cpp b/cockatrice/src/dialogs/dlg_settings.cpp index b48f6a670..cc4a0b4bb 100644 --- a/cockatrice/src/dialogs/dlg_settings.cpp +++ b/cockatrice/src/dialogs/dlg_settings.cpp @@ -338,6 +338,10 @@ AppearanceSettingsPage::AppearanceSettingsPage() displayCardNamesCheckBox.setChecked(settings.getDisplayCardNames()); connect(&displayCardNamesCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, &SettingsCache::setDisplayCardNames); + autoRotateSidewaysLayoutCardsCheckBox.setChecked(settings.getAutoRotateSidewaysLayoutCards()); + connect(&autoRotateSidewaysLayoutCardsCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, + &SettingsCache::setAutoRotateSidewaysLayoutCards); + overrideAllCardArtWithPersonalPreferenceCheckBox.setChecked(settings.getOverrideAllCardArtWithPersonalPreference()); connect(&overrideAllCardArtWithPersonalPreferenceCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, &SettingsCache::setOverrideAllCardArtWithPersonalPreference); @@ -361,13 +365,14 @@ AppearanceSettingsPage::AppearanceSettingsPage() auto *cardsGrid = new QGridLayout; cardsGrid->addWidget(&displayCardNamesCheckBox, 0, 0, 1, 2); - cardsGrid->addWidget(&cardScalingCheckBox, 1, 0, 1, 2); - cardsGrid->addWidget(&overrideAllCardArtWithPersonalPreferenceCheckBox, 2, 0, 1, 2); - cardsGrid->addWidget(&bumpSetsWithCardsInDeckToTopCheckBox, 3, 0, 1, 2); - cardsGrid->addWidget(&verticalCardOverlapPercentLabel, 4, 0, 1, 1); - cardsGrid->addWidget(&verticalCardOverlapPercentBox, 4, 1, 1, 1); - cardsGrid->addWidget(&cardViewInitialRowsMaxLabel, 5, 0); - cardsGrid->addWidget(&cardViewInitialRowsMaxBox, 5, 1); + cardsGrid->addWidget(&autoRotateSidewaysLayoutCardsCheckBox, 1, 0, 1, 2); + cardsGrid->addWidget(&cardScalingCheckBox, 2, 0, 1, 2); + cardsGrid->addWidget(&overrideAllCardArtWithPersonalPreferenceCheckBox, 3, 0, 1, 2); + cardsGrid->addWidget(&bumpSetsWithCardsInDeckToTopCheckBox, 4, 0, 1, 2); + cardsGrid->addWidget(&verticalCardOverlapPercentLabel, 5, 0, 1, 1); + cardsGrid->addWidget(&verticalCardOverlapPercentBox, 5, 1, 1, 1); + cardsGrid->addWidget(&cardViewInitialRowsMaxLabel, 6, 0); + cardsGrid->addWidget(&cardViewInitialRowsMaxBox, 6, 1); cardsGroupBox = new QGroupBox; cardsGroupBox->setLayout(cardsGrid); @@ -462,6 +467,7 @@ void AppearanceSettingsPage::retranslateUi() cardsGroupBox->setTitle(tr("Card rendering")); displayCardNamesCheckBox.setText(tr("Display card names on cards having a picture")); + autoRotateSidewaysLayoutCardsCheckBox.setText(tr("Auto-Rotate cards with sideways layout")); overrideAllCardArtWithPersonalPreferenceCheckBox.setText( tr("Override all card art with personal set preference (Pre-ProviderID change behavior) [Requires Client " "restart]")); diff --git a/cockatrice/src/dialogs/dlg_settings.h b/cockatrice/src/dialogs/dlg_settings.h index 969abc3c1..c85094581 100644 --- a/cockatrice/src/dialogs/dlg_settings.h +++ b/cockatrice/src/dialogs/dlg_settings.h @@ -93,6 +93,7 @@ private: QLabel maxFontSizeForCardsLabel; QCheckBox showShortcutsCheckBox; QCheckBox displayCardNamesCheckBox; + QCheckBox autoRotateSidewaysLayoutCardsCheckBox; QCheckBox overrideAllCardArtWithPersonalPreferenceCheckBox; QCheckBox bumpSetsWithCardsInDeckToTopCheckBox; QCheckBox cardScalingCheckBox; diff --git a/cockatrice/src/settings/cache_settings.cpp b/cockatrice/src/settings/cache_settings.cpp index 56abfb866..683b2d721 100644 --- a/cockatrice/src/settings/cache_settings.cpp +++ b/cockatrice/src/settings/cache_settings.cpp @@ -258,6 +258,8 @@ SettingsCache::SettingsCache() invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool(); minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt(); tapAnimation = settings->value("cards/tapanimation", true).toBool(); + autoRotateSidewaysLayoutCards = settings->value("cards/autorotatesidewayslayoutcards", true).toBool(); + openDeckInNewTab = settings->value("editor/openDeckInNewTab", false).toBool(); rewindBufferingMs = settings->value("replay/rewindBufferingMs", 200).toInt(); chatMention = settings->value("chat/mention", true).toBool(); @@ -629,6 +631,12 @@ void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T _tapAnimation) settings->setValue("cards/tapanimation", tapAnimation); } +void SettingsCache::setAutoRotateSidewaysLayoutCards(QT_STATE_CHANGED_T _autoRotateSidewaysLayoutCards) +{ + autoRotateSidewaysLayoutCards = static_cast(_autoRotateSidewaysLayoutCards); + settings->setValue("cards/autorotatesidewayslayoutcards", autoRotateSidewaysLayoutCards); +} + void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab) { openDeckInNewTab = static_cast(_openDeckInNewTab); diff --git a/cockatrice/src/settings/cache_settings.h b/cockatrice/src/settings/cache_settings.h index 4382f2b1c..59373b890 100644 --- a/cockatrice/src/settings/cache_settings.h +++ b/cockatrice/src/settings/cache_settings.h @@ -120,6 +120,7 @@ private: bool invertVerticalCoordinate; int minPlayersForMultiColumnLayout; bool tapAnimation; + bool autoRotateSidewaysLayoutCards; bool openDeckInNewTab; int rewindBufferingMs; bool chatMention; @@ -369,6 +370,10 @@ public: { return tapAnimation; } + bool getAutoRotateSidewaysLayoutCards() const + { + return autoRotateSidewaysLayoutCards; + } bool getOpenDeckInNewTab() const { return openDeckInNewTab; @@ -649,6 +654,7 @@ public slots: void setInvertVerticalCoordinate(QT_STATE_CHANGED_T _invertVerticalCoordinate); void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout); void setTapAnimation(QT_STATE_CHANGED_T _tapAnimation); + void setAutoRotateSidewaysLayoutCards(QT_STATE_CHANGED_T _autoRotateSidewaysLayoutCards); void setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab); void setRewindBufferingMs(int _rewindBufferingMs); void setChatMention(QT_STATE_CHANGED_T _chatMention); diff --git a/dbconverter/src/mocks.cpp b/dbconverter/src/mocks.cpp index d82a4ff04..a8d4cbf90 100644 --- a/dbconverter/src/mocks.cpp +++ b/dbconverter/src/mocks.cpp @@ -196,6 +196,9 @@ void SettingsCache::setMinPlayersForMultiColumnLayout(int /* _minPlayersForMulti void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) { } +void SettingsCache::setAutoRotateSidewaysLayoutCards(QT_STATE_CHANGED_T /* _autoRotateSidewaysLayoutCards */) +{ +} void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */) { } diff --git a/tests/carddatabase/mocks.cpp b/tests/carddatabase/mocks.cpp index c0d7ba918..b251bbd7f 100644 --- a/tests/carddatabase/mocks.cpp +++ b/tests/carddatabase/mocks.cpp @@ -200,6 +200,9 @@ void SettingsCache::setMinPlayersForMultiColumnLayout(int /* _minPlayersForMulti void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */) { } +void SettingsCache::setAutoRotateSidewaysLayoutCards(QT_STATE_CHANGED_T /* _autoRotateSidewaysLayoutCards */) +{ +} void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */) { }