mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-11 04:23:29 -08:00
[Card] Elide long tag lists in the card info and drop the Scryfall label from the tag filter tooltip
This commit is contained in:
parent
d34fd04897
commit
0f45dfa12a
3 changed files with 44 additions and 3 deletions
|
|
@ -23,12 +23,25 @@
|
||||||
#include <qnamespace.h>
|
#include <qnamespace.h>
|
||||||
#include <qobjectdefs.h>
|
#include <qobjectdefs.h>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr int TAGS_PREVIEW_LIMIT = 3;
|
||||||
|
const QString SHOW_ALL_TAGS_LINK = QStringLiteral("cockatrice://show-all-tags");
|
||||||
|
} // namespace
|
||||||
|
|
||||||
CardInfoTextWidget::CardInfoTextWidget(QWidget *parent) : QFrame(parent)
|
CardInfoTextWidget::CardInfoTextWidget(QWidget *parent) : QFrame(parent)
|
||||||
{
|
{
|
||||||
propsLabel = new QLabel;
|
propsLabel = new QLabel;
|
||||||
propsLabel->setOpenExternalLinks(false);
|
propsLabel->setOpenExternalLinks(false);
|
||||||
propsLabel->setWordWrap(true);
|
propsLabel->setWordWrap(true);
|
||||||
connect(propsLabel, SIGNAL(linkActivated(const QString &)), this, SIGNAL(linkActivated(const QString &)));
|
connect(propsLabel, &QLabel::linkActivated, this, [this](const QString &link) {
|
||||||
|
if (link == SHOW_ALL_TAGS_LINK) {
|
||||||
|
showAllTags = true;
|
||||||
|
setCard(currentCard);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit linkActivated(link);
|
||||||
|
});
|
||||||
|
|
||||||
textLabel = new QTextEdit();
|
textLabel = new QTextEdit();
|
||||||
textLabel->setReadOnly(true);
|
textLabel->setReadOnly(true);
|
||||||
|
|
@ -75,6 +88,12 @@ void CardInfoTextWidget::setCard(const ExactCard &exactCard)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expanding the tag list re-renders the same card, so only reset the
|
||||||
|
// collapsed state when a genuinely different card is shown.
|
||||||
|
if (exactCard != currentCard) {
|
||||||
|
showAllTags = false;
|
||||||
|
}
|
||||||
|
|
||||||
QString text = "<table width=\"100%\" border=0 cellspacing=0 cellpadding=0>";
|
QString text = "<table width=\"100%\" border=0 cellspacing=0 cellpadding=0>";
|
||||||
text += QString("<tr><td>%1</td><td width=\"5\"></td><td>%2</td></tr>")
|
text += QString("<tr><td>%1</td><td width=\"5\"></td><td>%2</td></tr>")
|
||||||
.arg(tr("Name:"), CardLocalization::displayName(card).toHtmlEscaped());
|
.arg(tr("Name:"), CardLocalization::displayName(card).toHtmlEscaped());
|
||||||
|
|
@ -94,6 +113,27 @@ void CardInfoTextWidget::setCard(const ExactCard &exactCard)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
QString keyText = Mtg::getNicePropertyName(key).toHtmlEscaped() + ":";
|
QString keyText = Mtg::getNicePropertyName(key).toHtmlEscaped() + ":";
|
||||||
|
|
||||||
|
if (key == Mtg::Tags) {
|
||||||
|
const QStringList tags = card->getProperty(Mtg::Tags).split(" ", Qt::SkipEmptyParts);
|
||||||
|
|
||||||
|
QString tagsText;
|
||||||
|
if (!showAllTags && tags.size() > TAGS_PREVIEW_LIMIT) {
|
||||||
|
const QStringList preview = tags.mid(0, TAGS_PREVIEW_LIMIT);
|
||||||
|
const int remaining = tags.size() - preview.size();
|
||||||
|
// Join with non-breaking spaces so "… and N more" never wraps mid-phrase.
|
||||||
|
const QString moreText =
|
||||||
|
tr("and %n more", nullptr, remaining).toHtmlEscaped().split(" ").join(" ");
|
||||||
|
tagsText = preview.join(", ").toHtmlEscaped() +
|
||||||
|
QString(" <a href=\"%1\">… %2</a>").arg(SHOW_ALL_TAGS_LINK, moreText);
|
||||||
|
} else {
|
||||||
|
tagsText = tags.join(", ").toHtmlEscaped();
|
||||||
|
}
|
||||||
|
|
||||||
|
text += QString("<tr><td>%1</td><td></td><td>%2</td></tr>").arg(keyText, tagsText);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
text +=
|
text +=
|
||||||
QString("<tr><td>%1</td><td></td><td>%2</td></tr>").arg(keyText, card->getProperty(key).toHtmlEscaped());
|
QString("<tr><td>%1</td><td></td><td>%2</td></tr>").arg(keyText, card->getProperty(key).toHtmlEscaped());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,8 @@ private:
|
||||||
QLabel *propsLabel;
|
QLabel *propsLabel;
|
||||||
QScrollArea *propsScroll;
|
QScrollArea *propsScroll;
|
||||||
QTextEdit *textLabel;
|
QTextEdit *textLabel;
|
||||||
ExactCard currentCard; ///< Last card set, re-rendered when the card language changes.
|
ExactCard currentCard; ///< Last card set, re-rendered when the card language changes.
|
||||||
|
bool showAllTags = false; ///< Whether the potentially long tag list is fully expanded.
|
||||||
void setTexts(const QString &propsText, const QString &textText);
|
void setTexts(const QString &propsText, const QString &textText);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ void VisualDatabaseDisplayFilterToolbarWidget::retranslateUi()
|
||||||
quickFilterSubTypeWidget->setToolTip(tr("Filter by card sub-type"));
|
quickFilterSubTypeWidget->setToolTip(tr("Filter by card sub-type"));
|
||||||
quickFilterSetWidget->setToolTip(tr("Filter by set"));
|
quickFilterSetWidget->setToolTip(tr("Filter by set"));
|
||||||
quickFilterFormatLegalityWidget->setToolTip(tr("Filter by format legality"));
|
quickFilterFormatLegalityWidget->setToolTip(tr("Filter by format legality"));
|
||||||
quickFilterTagWidget->setToolTip(tr("Filter by Scryfall Tagger tag"));
|
quickFilterTagWidget->setToolTip(tr("Filter by card tag"));
|
||||||
|
|
||||||
quickFilterSaveLoadWidget->setButtonText(tr("Save/Load"));
|
quickFilterSaveLoadWidget->setButtonText(tr("Save/Load"));
|
||||||
quickFilterNameWidget->setButtonText(tr("Name"));
|
quickFilterNameWidget->setButtonText(tr("Name"));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue