[Refactor] Add card name, printing id, and color to CardState (#7433)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-31 18:44:13 +01:00 • committed by GitHub
parent edb5caec8a
commit 5d0d466930
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 8 deletions

View file

@ -20,6 +20,12 @@ void CardState::resetState(bool keepAnnotations)
emit stateReset();
}
void CardState::setColor(const QString &_color)
{
color = _color;
emit colorChanged();
}
void CardState::deleteView()
{
emit viewDeleteRequested();

View file

@ -32,6 +32,7 @@ private:
QString pt;
bool doesntUntap = false;
bool destroyOnZoneChange = false;
QString color;
CardState *attachedTo = nullptr;
QList<CardItem *> attachedCards;
@ -46,6 +47,7 @@ signals:
void tappedChanged(bool newTapped, bool canAnimate);
void facedownChanged(bool newFaceDown);
void stateReset();
void colorChanged();
void attackingChanged(bool newValue);
void countersChanged(const QMap<int, int> &newCounters);
@ -92,6 +94,16 @@ public:
void setCardRef(const CardRef &_cardRef);
QString getName() const
{
return cardRef.name;
}
QString getProviderId() const
{
return cardRef.providerId;
}
ExactCard getCard() const
{
return exactCard;
@ -186,6 +198,13 @@ public:
*/
static QVariantList parsePT(const QString &pt);
[[nodiscard]] QString getColor() const
{
return color;
}
void setColor(const QString &_color);
bool getDoesntUntap() const
{
return doesntUntap;

View file

@ -54,6 +54,10 @@ AbstractCardItem::AbstractCardItem(QGraphicsItem *parent, const CardRef &cardRef
connect(state, &CardState::cardRefChanged, this, &AbstractCardItem::onCardRefChanged);
connect(state, &CardState::tappedChanged, this, &AbstractCardItem::onTappedChanged);
connect(state, &CardState::facedownChanged, this, [this] { update(); });
connect(state, &CardState::colorChanged, this, [this] {
cacheBgColor();
update();
});
connect(&SettingsCache::instance().cardsDisplay(), &CardsDisplaySettings::displayCardNamesChanged, this,
[this] { update(); });
@ -265,18 +269,17 @@ void AbstractCardItem::setHovered(bool _hovered)
void AbstractCardItem::setColor(const QString &_color)
{
color = _color;
cacheBgColor();
update();
state->setColor(_color);
}
void AbstractCardItem::cacheBgColor()
{
QChar colorChar;
if (color.isEmpty()) {
const QString cardColor = state->getColor();
if (cardColor.isEmpty()) {
colorChar = state->getCardInfo().getColorChar();
} else {
colorChar = color.at(0);
colorChar = cardColor.at(0);
}
switch (colorChar.toLower().toLatin1()) {

View file

@ -23,7 +23,6 @@ class AbstractCardItem : public ArrowTarget, public IAnimatedItem
protected:
CardState *state;
int tapAngle;
QString color;
QColor bgColor;
private:
@ -114,9 +113,9 @@ public:
{
return isHovered;
}
QString getColor() const
[[nodiscard]] QString getColor() const
{
return color;
return state->getColor();
}
void setColor(const QString &_color);
bool getTapped() const