mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-25 08:03:58 -05:00
Fix the image shrinking due to repeated scaling and FP precision loss. (#5284)
* Fix the image shrinking due to repeated scaling and FP precision loss. * Add a setting for auto-rotating sideways layout cards. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
3cf0904651
commit
a0e5871c6e
|
|
@ -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 <QMouseEvent>
|
||||
|
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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]"));
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ private:
|
|||
QLabel maxFontSizeForCardsLabel;
|
||||
QCheckBox showShortcutsCheckBox;
|
||||
QCheckBox displayCardNamesCheckBox;
|
||||
QCheckBox autoRotateSidewaysLayoutCardsCheckBox;
|
||||
QCheckBox overrideAllCardArtWithPersonalPreferenceCheckBox;
|
||||
QCheckBox bumpSetsWithCardsInDeckToTopCheckBox;
|
||||
QCheckBox cardScalingCheckBox;
|
||||
|
|
|
|||
|
|
@ -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<bool>(_autoRotateSidewaysLayoutCards);
|
||||
settings->setValue("cards/autorotatesidewayslayoutcards", autoRotateSidewaysLayoutCards);
|
||||
}
|
||||
|
||||
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab)
|
||||
{
|
||||
openDeckInNewTab = static_cast<bool>(_openDeckInNewTab);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 */)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 */)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user