mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-27 00:53:55 -07: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
7 changed files with 50 additions and 19 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
#include "card_info_picture_widget.h"
|
#include "card_info_picture_widget.h"
|
||||||
|
|
||||||
#include "../../../../game/cards/card_item.h"
|
#include "../../../../game/cards/card_item.h"
|
||||||
|
#include "../../../../settings/cache_settings.h"
|
||||||
#include "../../picture_loader.h"
|
#include "../../picture_loader.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
@ -141,6 +142,7 @@ void CardInfoPictureWidget::loadPixmap()
|
||||||
void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::paintEvent(event);
|
QWidget::paintEvent(event);
|
||||||
|
|
||||||
if (width() == 0 || height() == 0) {
|
if (width() == 0 || height() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -150,28 +152,30 @@ void CardInfoPictureWidget::paintEvent(QPaintEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap transformedPixmap = resizedPixmap; // Default pixmap
|
QPixmap transformedPixmap = resizedPixmap; // Default pixmap
|
||||||
if (info && info->getLandscapeOrientation()) {
|
if (SettingsCache::instance().getAutoRotateSidewaysLayoutCards()) {
|
||||||
// Rotate pixmap 90 degrees to the left
|
if (info && info->getLandscapeOrientation()) {
|
||||||
QTransform transform;
|
// Rotate pixmap 90 degrees to the left
|
||||||
transform.rotate(90);
|
QTransform transform;
|
||||||
transformedPixmap = resizedPixmap.transformed(transform, Qt::SmoothTransformation);
|
transform.rotate(90);
|
||||||
|
transformedPixmap = resizedPixmap.transformed(transform, Qt::SmoothTransformation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust scaling after rotation
|
// Adjust scaling after rotation
|
||||||
const QSize availableSize = size(); // Size of the widget
|
const QSize availableSize = size(); // Size of the widget
|
||||||
const QSize pixmapSize = transformedPixmap.size();
|
const QSize scaledSize = transformedPixmap.size().scaled(availableSize, Qt::KeepAspectRatio);
|
||||||
const QSize scaledSize = pixmapSize.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();
|
const qreal radius = 0.05 * scaledSize.width();
|
||||||
|
|
||||||
|
// Draw the pixmap with rounded corners
|
||||||
QStylePainter painter(this);
|
QStylePainter painter(this);
|
||||||
QPainterPath shape;
|
QPainterPath shape;
|
||||||
shape.addRoundedRect(QRect(topLeft, scaledSize), radius, radius);
|
shape.addRoundedRect(targetRect, radius, radius);
|
||||||
painter.setClipPath(shape);
|
painter.setClipPath(shape);
|
||||||
painter.drawItemPixmap(QRect(topLeft, scaledSize), Qt::AlignCenter,
|
painter.drawPixmap(targetRect, transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
transformedPixmap.scaled(scaledSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -338,6 +338,10 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
displayCardNamesCheckBox.setChecked(settings.getDisplayCardNames());
|
displayCardNamesCheckBox.setChecked(settings.getDisplayCardNames());
|
||||||
connect(&displayCardNamesCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings, &SettingsCache::setDisplayCardNames);
|
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());
|
overrideAllCardArtWithPersonalPreferenceCheckBox.setChecked(settings.getOverrideAllCardArtWithPersonalPreference());
|
||||||
connect(&overrideAllCardArtWithPersonalPreferenceCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings,
|
connect(&overrideAllCardArtWithPersonalPreferenceCheckBox, &QCheckBox::QT_STATE_CHANGED, &settings,
|
||||||
&SettingsCache::setOverrideAllCardArtWithPersonalPreference);
|
&SettingsCache::setOverrideAllCardArtWithPersonalPreference);
|
||||||
|
|
@ -361,13 +365,14 @@ AppearanceSettingsPage::AppearanceSettingsPage()
|
||||||
|
|
||||||
auto *cardsGrid = new QGridLayout;
|
auto *cardsGrid = new QGridLayout;
|
||||||
cardsGrid->addWidget(&displayCardNamesCheckBox, 0, 0, 1, 2);
|
cardsGrid->addWidget(&displayCardNamesCheckBox, 0, 0, 1, 2);
|
||||||
cardsGrid->addWidget(&cardScalingCheckBox, 1, 0, 1, 2);
|
cardsGrid->addWidget(&autoRotateSidewaysLayoutCardsCheckBox, 1, 0, 1, 2);
|
||||||
cardsGrid->addWidget(&overrideAllCardArtWithPersonalPreferenceCheckBox, 2, 0, 1, 2);
|
cardsGrid->addWidget(&cardScalingCheckBox, 2, 0, 1, 2);
|
||||||
cardsGrid->addWidget(&bumpSetsWithCardsInDeckToTopCheckBox, 3, 0, 1, 2);
|
cardsGrid->addWidget(&overrideAllCardArtWithPersonalPreferenceCheckBox, 3, 0, 1, 2);
|
||||||
cardsGrid->addWidget(&verticalCardOverlapPercentLabel, 4, 0, 1, 1);
|
cardsGrid->addWidget(&bumpSetsWithCardsInDeckToTopCheckBox, 4, 0, 1, 2);
|
||||||
cardsGrid->addWidget(&verticalCardOverlapPercentBox, 4, 1, 1, 1);
|
cardsGrid->addWidget(&verticalCardOverlapPercentLabel, 5, 0, 1, 1);
|
||||||
cardsGrid->addWidget(&cardViewInitialRowsMaxLabel, 5, 0);
|
cardsGrid->addWidget(&verticalCardOverlapPercentBox, 5, 1, 1, 1);
|
||||||
cardsGrid->addWidget(&cardViewInitialRowsMaxBox, 5, 1);
|
cardsGrid->addWidget(&cardViewInitialRowsMaxLabel, 6, 0);
|
||||||
|
cardsGrid->addWidget(&cardViewInitialRowsMaxBox, 6, 1);
|
||||||
|
|
||||||
cardsGroupBox = new QGroupBox;
|
cardsGroupBox = new QGroupBox;
|
||||||
cardsGroupBox->setLayout(cardsGrid);
|
cardsGroupBox->setLayout(cardsGrid);
|
||||||
|
|
@ -462,6 +467,7 @@ void AppearanceSettingsPage::retranslateUi()
|
||||||
|
|
||||||
cardsGroupBox->setTitle(tr("Card rendering"));
|
cardsGroupBox->setTitle(tr("Card rendering"));
|
||||||
displayCardNamesCheckBox.setText(tr("Display card names on cards having a picture"));
|
displayCardNamesCheckBox.setText(tr("Display card names on cards having a picture"));
|
||||||
|
autoRotateSidewaysLayoutCardsCheckBox.setText(tr("Auto-Rotate cards with sideways layout"));
|
||||||
overrideAllCardArtWithPersonalPreferenceCheckBox.setText(
|
overrideAllCardArtWithPersonalPreferenceCheckBox.setText(
|
||||||
tr("Override all card art with personal set preference (Pre-ProviderID change behavior) [Requires Client "
|
tr("Override all card art with personal set preference (Pre-ProviderID change behavior) [Requires Client "
|
||||||
"restart]"));
|
"restart]"));
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ private:
|
||||||
QLabel maxFontSizeForCardsLabel;
|
QLabel maxFontSizeForCardsLabel;
|
||||||
QCheckBox showShortcutsCheckBox;
|
QCheckBox showShortcutsCheckBox;
|
||||||
QCheckBox displayCardNamesCheckBox;
|
QCheckBox displayCardNamesCheckBox;
|
||||||
|
QCheckBox autoRotateSidewaysLayoutCardsCheckBox;
|
||||||
QCheckBox overrideAllCardArtWithPersonalPreferenceCheckBox;
|
QCheckBox overrideAllCardArtWithPersonalPreferenceCheckBox;
|
||||||
QCheckBox bumpSetsWithCardsInDeckToTopCheckBox;
|
QCheckBox bumpSetsWithCardsInDeckToTopCheckBox;
|
||||||
QCheckBox cardScalingCheckBox;
|
QCheckBox cardScalingCheckBox;
|
||||||
|
|
|
||||||
|
|
@ -258,6 +258,8 @@ SettingsCache::SettingsCache()
|
||||||
invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool();
|
invertVerticalCoordinate = settings->value("table/invert_vertical", false).toBool();
|
||||||
minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt();
|
minPlayersForMultiColumnLayout = settings->value("interface/min_players_multicolumn", 4).toInt();
|
||||||
tapAnimation = settings->value("cards/tapanimation", true).toBool();
|
tapAnimation = settings->value("cards/tapanimation", true).toBool();
|
||||||
|
autoRotateSidewaysLayoutCards = settings->value("cards/autorotatesidewayslayoutcards", true).toBool();
|
||||||
|
|
||||||
openDeckInNewTab = settings->value("editor/openDeckInNewTab", false).toBool();
|
openDeckInNewTab = settings->value("editor/openDeckInNewTab", false).toBool();
|
||||||
rewindBufferingMs = settings->value("replay/rewindBufferingMs", 200).toInt();
|
rewindBufferingMs = settings->value("replay/rewindBufferingMs", 200).toInt();
|
||||||
chatMention = settings->value("chat/mention", true).toBool();
|
chatMention = settings->value("chat/mention", true).toBool();
|
||||||
|
|
@ -629,6 +631,12 @@ void SettingsCache::setTapAnimation(QT_STATE_CHANGED_T _tapAnimation)
|
||||||
settings->setValue("cards/tapanimation", 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)
|
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab)
|
||||||
{
|
{
|
||||||
openDeckInNewTab = static_cast<bool>(_openDeckInNewTab);
|
openDeckInNewTab = static_cast<bool>(_openDeckInNewTab);
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,7 @@ private:
|
||||||
bool invertVerticalCoordinate;
|
bool invertVerticalCoordinate;
|
||||||
int minPlayersForMultiColumnLayout;
|
int minPlayersForMultiColumnLayout;
|
||||||
bool tapAnimation;
|
bool tapAnimation;
|
||||||
|
bool autoRotateSidewaysLayoutCards;
|
||||||
bool openDeckInNewTab;
|
bool openDeckInNewTab;
|
||||||
int rewindBufferingMs;
|
int rewindBufferingMs;
|
||||||
bool chatMention;
|
bool chatMention;
|
||||||
|
|
@ -369,6 +370,10 @@ public:
|
||||||
{
|
{
|
||||||
return tapAnimation;
|
return tapAnimation;
|
||||||
}
|
}
|
||||||
|
bool getAutoRotateSidewaysLayoutCards() const
|
||||||
|
{
|
||||||
|
return autoRotateSidewaysLayoutCards;
|
||||||
|
}
|
||||||
bool getOpenDeckInNewTab() const
|
bool getOpenDeckInNewTab() const
|
||||||
{
|
{
|
||||||
return openDeckInNewTab;
|
return openDeckInNewTab;
|
||||||
|
|
@ -649,6 +654,7 @@ public slots:
|
||||||
void setInvertVerticalCoordinate(QT_STATE_CHANGED_T _invertVerticalCoordinate);
|
void setInvertVerticalCoordinate(QT_STATE_CHANGED_T _invertVerticalCoordinate);
|
||||||
void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout);
|
void setMinPlayersForMultiColumnLayout(int _minPlayersForMultiColumnLayout);
|
||||||
void setTapAnimation(QT_STATE_CHANGED_T _tapAnimation);
|
void setTapAnimation(QT_STATE_CHANGED_T _tapAnimation);
|
||||||
|
void setAutoRotateSidewaysLayoutCards(QT_STATE_CHANGED_T _autoRotateSidewaysLayoutCards);
|
||||||
void setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab);
|
void setOpenDeckInNewTab(QT_STATE_CHANGED_T _openDeckInNewTab);
|
||||||
void setRewindBufferingMs(int _rewindBufferingMs);
|
void setRewindBufferingMs(int _rewindBufferingMs);
|
||||||
void setChatMention(QT_STATE_CHANGED_T _chatMention);
|
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::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
void SettingsCache::setAutoRotateSidewaysLayoutCards(QT_STATE_CHANGED_T /* _autoRotateSidewaysLayoutCards */)
|
||||||
|
{
|
||||||
|
}
|
||||||
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */)
|
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::setTapAnimation(QT_STATE_CHANGED_T /* _tapAnimation */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
void SettingsCache::setAutoRotateSidewaysLayoutCards(QT_STATE_CHANGED_T /* _autoRotateSidewaysLayoutCards */)
|
||||||
|
{
|
||||||
|
}
|
||||||
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */)
|
void SettingsCache::setOpenDeckInNewTab(QT_STATE_CHANGED_T /* _openDeckInNewTab */)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue