Hide non-existent card values in infowidget and cardframe (#3239)

This commit is contained in:
Bers 2018-05-15 07:53:53 +02:00 committed by Zach H
parent 9acf606e93
commit 3b3f5a639c
3 changed files with 67 additions and 12 deletions

View file

@ -54,28 +54,78 @@ CardInfoText::CardInfoText(QWidget *parent) : QFrame(parent), info(nullptr)
retranslateUi(); retranslateUi();
} }
// Reset every label which is optionally hidden
void CardInfoText::resetLabels()
{
nameLabel1->show();
nameLabel2->show();
manacostLabel1->show();
manacostLabel2->show();
colorLabel1->show();
colorLabel2->show();
cardtypeLabel1->show();
cardtypeLabel2->show();
powtoughLabel1->show();
powtoughLabel2->show();
loyaltyLabel1->show();
loyaltyLabel2->show();
textLabel->show();
}
void CardInfoText::setCard(CardInfoPtr card) void CardInfoText::setCard(CardInfoPtr card)
{ {
if (card) { if (card) {
resetLabels();
nameLabel2->setText(card->getName()); nameLabel2->setText(card->getName());
if (!card->getManaCost().isEmpty()) {
manacostLabel2->setText(card->getManaCost()); manacostLabel2->setText(card->getManaCost());
} else {
manacostLabel1->hide();
manacostLabel2->hide();
}
if (!card->getColors().isEmpty()) {
colorLabel2->setText(card->getColors().join("")); colorLabel2->setText(card->getColors().join(""));
} else {
colorLabel2->setText("Colorless");
}
cardtypeLabel2->setText(card->getCardType()); cardtypeLabel2->setText(card->getCardType());
if (!card->getPowTough().isEmpty()) {
powtoughLabel2->setText(card->getPowTough()); powtoughLabel2->setText(card->getPowTough());
} else {
powtoughLabel1->hide();
powtoughLabel2->hide();
}
if (!card->getLoyalty().isEmpty()) {
loyaltyLabel2->setText(card->getLoyalty()); loyaltyLabel2->setText(card->getLoyalty());
} else {
loyaltyLabel1->hide();
loyaltyLabel2->hide();
}
textLabel->setText(card->getText()); textLabel->setText(card->getText());
} else { } else {
nameLabel2->setText(""); nameLabel1->hide();
manacostLabel2->setText(""); nameLabel2->hide();
colorLabel2->setText(""); manacostLabel1->hide();
cardtypeLabel2->setText(""); manacostLabel2->hide();
powtoughLabel2->setText(""); colorLabel1->hide();
loyaltyLabel2->setText(""); colorLabel2->hide();
textLabel->setText(""); cardtypeLabel1->hide();
cardtypeLabel2->hide();
powtoughLabel1->hide();
powtoughLabel2->hide();
loyaltyLabel1->hide();
loyaltyLabel2->hide();
textLabel->hide();
} }
} }
void CardInfoText::setInvalidCardName(const QString &cardName)
{
nameLabel1->setText(tr("Unknown card:"));
nameLabel1->show();
nameLabel2->setText(cardName);
nameLabel2->show();
}
void CardInfoText::retranslateUi() void CardInfoText::retranslateUi()
{ {
nameLabel1->setText(tr("Name:")); nameLabel1->setText(tr("Name:"));

View file

@ -22,9 +22,12 @@ private:
CardInfoPtr info; CardInfoPtr info;
void resetLabels();
public: public:
CardInfoText(QWidget *parent = 0); CardInfoText(QWidget *parent = 0);
void retranslateUi(); void retranslateUi();
void setInvalidCardName(const QString &cardName);
public slots: public slots:
void setCard(CardInfoPtr card); void setCard(CardInfoPtr card);

View file

@ -52,6 +52,8 @@ void CardInfoWidget::setCard(CardInfoPtr card)
void CardInfoWidget::setCard(const QString &cardName) void CardInfoWidget::setCard(const QString &cardName)
{ {
setCard(db->getCardBySimpleName(cardName)); setCard(db->getCardBySimpleName(cardName));
if (!info)
text->setInvalidCardName(cardName);
} }
void CardInfoWidget::setCard(AbstractCardItem *card) void CardInfoWidget::setCard(AbstractCardItem *card)