mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-30 18:43:55 -07:00
[UserListDelegate] Consider providerId (#7018)
Co-authored-by: Lukas Brübach <lukas.bruebach@bdosecurity.de>
This commit is contained in:
parent
2914874720
commit
6dc974a05d
19 changed files with 211 additions and 53 deletions
|
|
@ -5,9 +5,9 @@
|
|||
#include <QPointer>
|
||||
#include <libcockatrice/card/database/card_database_manager.h>
|
||||
|
||||
static QString makeKey(const QString &user, const QString &card)
|
||||
static QString makeKey(const QString &user, const QString &card, const QString &providerId)
|
||||
{
|
||||
return user + u'|' + card;
|
||||
return user + u'|' + card + u'|' + providerId;
|
||||
}
|
||||
|
||||
UserCardArtProvider::UserCardArtProvider(QObject *parent) : QObject(parent)
|
||||
|
|
@ -31,13 +31,13 @@ const QMap<QString, QPixmap> &UserCardArtProvider::cache() const
|
|||
return cardArtCache;
|
||||
}
|
||||
|
||||
void UserCardArtProvider::requestCardArt(const QString &userName, const QString &cardName)
|
||||
void UserCardArtProvider::requestCardArt(const QString &userName, const QString &cardName, const QString &providerId)
|
||||
{
|
||||
if (cardName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QString key = makeKey(userName, cardName);
|
||||
const QString key = makeKey(userName, cardName, providerId);
|
||||
|
||||
if (cardArtCache.contains(key) || pending.contains(key)) {
|
||||
return;
|
||||
|
|
@ -83,15 +83,16 @@ void UserCardArtProvider::processQueue()
|
|||
const QString key = queue.dequeue();
|
||||
|
||||
const QStringList parts = key.split(u'|');
|
||||
if (parts.size() != 2) {
|
||||
if (parts.size() != 3) {
|
||||
pending.remove(key);
|
||||
continue;
|
||||
}
|
||||
|
||||
const QString userName = parts.at(0);
|
||||
const QString cardName = parts.at(1);
|
||||
const QString providerId = parts.at(2);
|
||||
|
||||
ExactCard card = CardDatabaseManager::query()->getCard({cardName});
|
||||
ExactCard card = CardDatabaseManager::query()->getCard({cardName, providerId});
|
||||
|
||||
if (!card) {
|
||||
pending.remove(key);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class UserCardArtProvider : public QObject
|
|||
public:
|
||||
explicit UserCardArtProvider(QObject *parent = nullptr);
|
||||
|
||||
void requestCardArt(const QString &userName, const QString &cardName);
|
||||
void requestCardArt(const QString &userName, const QString &cardName, const QString &providerId);
|
||||
const QMap<QString, QPixmap> &cache() const;
|
||||
static QPixmap cropCardArt(const QPixmap &fullRes);
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ void CardArtPreviewWidget::paintEvent(QPaintEvent *)
|
|||
QString(), // userName not needed for override path
|
||||
nullptr, // no cache
|
||||
params,
|
||||
&sourcePixmap // 👈 direct pixmap
|
||||
&sourcePixmap // direct pixmap
|
||||
);
|
||||
|
||||
// Avatar placeholder so the left-margin interaction is visible
|
||||
|
|
@ -174,6 +174,13 @@ void UserCardArtSettingsDialog::setupUi()
|
|||
{
|
||||
initializeSearchBar();
|
||||
|
||||
providerComboBox = new QComboBox;
|
||||
connect(providerComboBox, &QComboBox::currentIndexChanged, this, [this]() {
|
||||
currentParams.cardProviderId = providerComboBox->currentData().toString();
|
||||
reloadPreview();
|
||||
onParamChanged();
|
||||
});
|
||||
|
||||
marginLSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctL, 0.01);
|
||||
marginRSpin = makeSpinBox(0.0, 0.95, currentParams.marginPctR, 0.01);
|
||||
verticalOffsetSpin = makeSpinBox(0.0, 1.0, currentParams.verticalOffset, 0.01);
|
||||
|
|
@ -181,6 +188,7 @@ void UserCardArtSettingsDialog::setupUi()
|
|||
|
||||
auto *form = new QFormLayout;
|
||||
form->addRow(tr("Card name:"), searchBar);
|
||||
form->addRow(tr("Card ProviderId:"), providerComboBox);
|
||||
form->addRow(tr("Left margin (%):"), marginLSpin);
|
||||
form->addRow(tr("Right margin (%):"), marginRSpin);
|
||||
form->addRow(tr("Vertical offset:"), verticalOffsetSpin);
|
||||
|
|
@ -219,6 +227,32 @@ void UserCardArtSettingsDialog::setupUi()
|
|||
connect(zoomSpin, &QDoubleSpinBox::valueChanged, this, &UserCardArtSettingsDialog::onParamChanged);
|
||||
}
|
||||
|
||||
void UserCardArtSettingsDialog::populateProviderCombo(const QString &cardName)
|
||||
{
|
||||
providerComboBox->clear();
|
||||
|
||||
auto card = CardDatabaseManager::query()->getCard({cardName});
|
||||
|
||||
const auto &sets = card.getInfo().getSets();
|
||||
|
||||
for (const auto &printings : sets) {
|
||||
for (const auto &p : printings) {
|
||||
|
||||
QString setName = p.getSet()->getLongName();
|
||||
QString collector = p.getProperty("num");
|
||||
QString uuid = p.getUuid();
|
||||
|
||||
QString label = setName;
|
||||
|
||||
if (!collector.isEmpty()) {
|
||||
label += " #" + collector;
|
||||
}
|
||||
|
||||
providerComboBox->addItem(label, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserCardArtSettingsDialog::onCardNameChanged(const QString &name)
|
||||
{
|
||||
if (name.isEmpty()) {
|
||||
|
|
@ -231,27 +265,68 @@ void UserCardArtSettingsDialog::onCardNameChanged(const QString &name)
|
|||
if (!card) {
|
||||
currentPixmap = QPixmap();
|
||||
preview->setPixmap(currentPixmap);
|
||||
providerComboBox->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
currentParams.cardName = name;
|
||||
|
||||
populateProviderCombo(name);
|
||||
|
||||
if (providerComboBox->count() == 0) {
|
||||
// No printings found for this card; nothing to preview.
|
||||
currentPixmap = QPixmap();
|
||||
preview->setPixmap(currentPixmap);
|
||||
currentParams.cardProviderId.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
currentParams.cardProviderId = providerComboBox->currentData().toString();
|
||||
reloadPreview();
|
||||
}
|
||||
|
||||
void UserCardArtSettingsDialog::reloadPreview()
|
||||
{
|
||||
if (currentParams.cardName.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ExactCard card = CardDatabaseManager::query()->getCard({currentParams.cardName, currentParams.cardProviderId});
|
||||
if (!card) {
|
||||
return;
|
||||
}
|
||||
|
||||
// CardPictureLoader::getPixmap() is async on a cache miss: it enqueues a
|
||||
// background download and returns a null pixmap immediately. When that
|
||||
// download finishes, CardPictureLoader::imageLoaded() caches the result
|
||||
// and calls card.emitPixmapUpdated(), which emits pixmapUpdated() on the
|
||||
// underlying CardInfo (see exact_card.h). Listen for that, scoped to
|
||||
// whichever CardInfo we just asked for, so the preview catches up once
|
||||
// the image actually arrives instead of staying on the placeholder.
|
||||
//
|
||||
// Disconnect any previous listener first -- otherwise switching cards
|
||||
// repeatedly stacks up connections to old CardInfo objects, each of
|
||||
// which would still fire reloadPreview() (harmlessly, but wastefully)
|
||||
// whenever ITS art finishes loading later.
|
||||
disconnect(pixmapUpdatedConnection);
|
||||
|
||||
QPixmap fullRes;
|
||||
CardPictureLoader::getPixmap(fullRes, card, QSize(745, 1040));
|
||||
|
||||
if (fullRes.isNull()) {
|
||||
connect(card.getCardPtr().data(), &CardInfo::pixmapUpdated, this, [this, card](const PrintingInfo &) {
|
||||
disconnect(card.getCardPtr().data(), &CardInfo::pixmapUpdated, this, nullptr);
|
||||
QPixmap loaded;
|
||||
CardPictureLoader::getPixmap(loaded, card, QSize(745, 1040));
|
||||
currentPixmap = UserCardArtProvider::cropCardArt(loaded);
|
||||
preview->setPixmap(currentPixmap);
|
||||
});
|
||||
// Not loaded yet -- wait for the signal instead of giving up.
|
||||
// card.getCardPtr() is a CardInfoPtr (QSharedPointer<CardInfo>);
|
||||
// .data() gives the raw QObject* needed for connect().
|
||||
CardInfo *cardInfo = card.getCardPtr().data();
|
||||
if (cardInfo) {
|
||||
pixmapUpdatedConnection = connect(cardInfo, &CardInfo::pixmapUpdated, this, [this]() { reloadPreview(); });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
currentPixmap = UserCardArtProvider::cropCardArt(fullRes);
|
||||
preview->setPixmap(currentPixmap);
|
||||
preview->setParams(currentParams);
|
||||
}
|
||||
|
||||
void UserCardArtSettingsDialog::onParamChanged()
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include "user_list_painter.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QDialog>
|
||||
#include <QPixmap>
|
||||
|
||||
|
|
@ -43,10 +44,12 @@ public:
|
|||
|
||||
private slots:
|
||||
void onCardNameChanged(const QString &name);
|
||||
void reloadPreview();
|
||||
void onParamChanged();
|
||||
|
||||
private:
|
||||
void setupUi();
|
||||
void populateProviderCombo(const QString &cardName);
|
||||
void initializeSearchBar();
|
||||
QDoubleSpinBox *makeSpinBox(double min, double max, double value, double step);
|
||||
|
||||
|
|
@ -57,6 +60,10 @@ private:
|
|||
CardSearchModel *searchModel;
|
||||
CardCompleterProxyModel *proxyModel;
|
||||
|
||||
QComboBox *providerComboBox;
|
||||
|
||||
QMetaObject::Connection pixmapUpdatedConnection;
|
||||
|
||||
QDoubleSpinBox *marginLSpin;
|
||||
QDoubleSpinBox *marginRSpin;
|
||||
QDoubleSpinBox *verticalOffsetSpin;
|
||||
|
|
|
|||
|
|
@ -542,7 +542,7 @@ void UserInfoPopup::showForUser(const QString &userName,
|
|||
const CardArtParams params = (m_cardArtParamsMap && m_cardArtParamsMap->contains(userName))
|
||||
? m_cardArtParamsMap->value(userName)
|
||||
: CardArtParams{};
|
||||
const QString artKey = userName + u'|' + params.cardName;
|
||||
const QString artKey = userName + u'|' + params.cardName + u'|' + params.cardProviderId;
|
||||
const QPixmap cardArt = (m_cardArtCache && !params.cardName.isEmpty()) ? m_cardArtCache->value(artKey) : QPixmap{};
|
||||
m_header->setUserData(userInfo, online, avatar, cardArt, params);
|
||||
|
||||
|
|
|
|||
|
|
@ -73,9 +73,9 @@ void UserListPainter::drawBackground(QPainter *painter,
|
|||
painter->drawRoundedRect(QRectF(cardRect.left(), cardRect.top(), 3, cardRect.height()), 2, 2);
|
||||
}
|
||||
|
||||
static QString makeKey(const QString &user, const QString &card)
|
||||
static QString makeKey(const QString &user, const QString &card, const QString &providerId)
|
||||
{
|
||||
return user + u'|' + card;
|
||||
return user + u'|' + card + u'|' + providerId;
|
||||
}
|
||||
|
||||
void UserListPainter::drawCardArt(QPainter *painter,
|
||||
|
|
@ -95,7 +95,7 @@ void UserListPainter::drawCardArt(QPainter *painter,
|
|||
return;
|
||||
}
|
||||
|
||||
const QString key = makeKey(userName, params.cardName);
|
||||
const QString key = makeKey(userName, params.cardName, params.cardProviderId);
|
||||
|
||||
if (!cardArtCache->contains(key)) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class ServerInfo_User;
|
|||
struct CardArtParams
|
||||
{
|
||||
QString cardName = "";
|
||||
QString cardProviderId = "";
|
||||
double marginPctL = 0.33;
|
||||
double marginPctR = 0.02;
|
||||
double verticalOffset = 0.35;
|
||||
|
|
|
|||
|
|
@ -904,12 +904,13 @@ void UserListWidget::processUserInfo(const ServerInfo_User &user, bool online)
|
|||
const auto &cap = user.card_art_params();
|
||||
CardArtParams params;
|
||||
params.cardName = QString::fromStdString(cap.card_name());
|
||||
params.cardProviderId = QString::fromStdString(cap.card_provider_id());
|
||||
params.marginPctL = cap.margin_pct_l();
|
||||
params.marginPctR = cap.margin_pct_r();
|
||||
params.verticalOffset = cap.vertical_offset();
|
||||
params.zoom = cap.zoom();
|
||||
cardArtParamsMap.insert(userName, params);
|
||||
cardArtProvider->requestCardArt(userName, params.cardName);
|
||||
cardArtProvider->requestCardArt(userName, params.cardName, params.cardProviderId);
|
||||
} else {
|
||||
cardArtParamsMap.remove(userName); // clear stale params on removal
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ int CardArtRulesModel::rowCount(const QModelIndex &parent) const
|
|||
int CardArtRulesModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
QVariant CardArtRulesModel::data(const QModelIndex &index, int role) const
|
||||
|
|
@ -43,8 +43,10 @@ QVariant CardArtRulesModel::data(const QModelIndex &index, int role) const
|
|||
case 0:
|
||||
return e.cardName;
|
||||
case 1:
|
||||
return e.mode;
|
||||
return e.cardProviderId;
|
||||
case 2:
|
||||
return e.mode;
|
||||
case 3:
|
||||
return e.reason;
|
||||
}
|
||||
}
|
||||
|
|
@ -62,8 +64,10 @@ QVariant CardArtRulesModel::headerData(int section, Qt::Orientation orientation,
|
|||
case 0:
|
||||
return tr("Card");
|
||||
case 1:
|
||||
return tr("Mode");
|
||||
return tr("ProviderId");
|
||||
case 2:
|
||||
return tr("Mode");
|
||||
case 3:
|
||||
return tr("Reason");
|
||||
default:
|
||||
return {};
|
||||
|
|
@ -97,6 +101,15 @@ QString CardArtRulesModel::cardAt(int row) const
|
|||
return entries[row].cardName;
|
||||
}
|
||||
|
||||
const CardArtRulesModel::Entry *CardArtRulesModel::entryAt(int row) const
|
||||
{
|
||||
if (row < 0 || row >= static_cast<int>(entries.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return &entries[row];
|
||||
}
|
||||
|
||||
void CardArtRulesModel::onRefreshFinished(const Response &r)
|
||||
{
|
||||
if (r.response_code() != Response::RespOk) {
|
||||
|
|
@ -109,8 +122,8 @@ void CardArtRulesModel::onRefreshFinished(const Response &r)
|
|||
entries.clear();
|
||||
|
||||
for (const auto &e : resp.entries()) {
|
||||
entries.push_back({QString::fromStdString(e.card_name()), QString::fromStdString(e.mode()),
|
||||
QString::fromStdString(e.reason())});
|
||||
entries.push_back({QString::fromStdString(e.card_name()), QString::fromStdString(e.card_provider_id()),
|
||||
QString::fromStdString(e.mode()), QString::fromStdString(e.reason())});
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
|
|
@ -128,6 +141,7 @@ void TabCardArtRules::setupUi()
|
|||
|
||||
initSearchBar();
|
||||
|
||||
providerComboBox = new QComboBox;
|
||||
modeBox = new QComboBox;
|
||||
reasonEdit = new QLineEdit;
|
||||
|
||||
|
|
@ -146,6 +160,7 @@ void TabCardArtRules::setupUi()
|
|||
|
||||
auto *form = new QFormLayout;
|
||||
form->addRow(tr("Card:"), searchEdit);
|
||||
form->addRow(tr("ProviderId:"), providerComboBox);
|
||||
form->addRow(tr("Mode:"), modeBox);
|
||||
form->addRow(tr("Reason:"), reasonEdit);
|
||||
|
||||
|
|
@ -204,6 +219,34 @@ void TabCardArtRules::initSearchBar()
|
|||
});
|
||||
connect(searchCompleter, static_cast<void (QCompleter::*)(const QString &)>(&QCompleter::activated), this,
|
||||
[this](const QString &name) { searchEdit->setText(name); });
|
||||
connect(searchEdit, &QLineEdit::editingFinished, this,
|
||||
[this]() { populateProviderCombo(searchEdit->text().trimmed()); });
|
||||
}
|
||||
|
||||
void TabCardArtRules::populateProviderCombo(const QString &cardName)
|
||||
{
|
||||
providerComboBox->clear();
|
||||
|
||||
auto card = CardDatabaseManager::query()->getCard({cardName});
|
||||
|
||||
const auto &sets = card.getInfo().getSets();
|
||||
|
||||
for (const auto &printings : sets) {
|
||||
for (const auto &p : printings) {
|
||||
|
||||
QString setName = p.getSet()->getLongName();
|
||||
QString collector = p.getProperty("num");
|
||||
QString uuid = p.getUuid();
|
||||
|
||||
QString label = setName;
|
||||
|
||||
if (!collector.isEmpty()) {
|
||||
label += " #" + collector;
|
||||
}
|
||||
|
||||
providerComboBox->addItem(label, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TabCardArtRules::retranslateUi()
|
||||
|
|
@ -222,6 +265,7 @@ void TabCardArtRules::addRule()
|
|||
{
|
||||
Command_AddCardArtRule cmd;
|
||||
cmd.set_card_name(searchEdit->text().toStdString());
|
||||
cmd.set_card_provider_id(providerComboBox->currentData().toString().toStdString());
|
||||
cmd.set_mode(modeBox->currentText().toStdString());
|
||||
cmd.set_reason(reasonEdit->text().toStdString());
|
||||
|
||||
|
|
@ -238,7 +282,10 @@ void TabCardArtRules::removeSelected()
|
|||
}
|
||||
|
||||
Command_RemoveCardArtRule cmd;
|
||||
cmd.set_card_name(tableModel->cardAt(idx.row()).toStdString());
|
||||
const auto e = tableModel->entryAt(idx.row());
|
||||
|
||||
cmd.set_card_name(e->cardName.toStdString());
|
||||
cmd.set_card_provider_id(e->cardProviderId.toStdString());
|
||||
|
||||
client->sendCommand(client->prepareModeratorCommand(cmd));
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ public:
|
|||
struct Entry
|
||||
{
|
||||
QString cardName;
|
||||
QString cardProviderId;
|
||||
QString mode;
|
||||
QString reason;
|
||||
};
|
||||
|
|
@ -35,6 +36,7 @@ public:
|
|||
void clear();
|
||||
|
||||
QString cardAt(int row) const;
|
||||
const Entry *entryAt(int row) const;
|
||||
|
||||
private slots:
|
||||
void onRefreshFinished(const Response &r);
|
||||
|
|
@ -70,11 +72,13 @@ private:
|
|||
|
||||
QLineEdit *searchEdit;
|
||||
void initSearchBar();
|
||||
void populateProviderCombo(const QString &cardName);
|
||||
QCompleter *searchCompleter;
|
||||
CardDatabaseModel *cardDbModel;
|
||||
CardDatabaseDisplayModel *cardDbDisplayModel;
|
||||
CardSearchModel *cardSearchModel;
|
||||
CardCompleterProxyModel *cardProxyModel;
|
||||
QComboBox *providerComboBox;
|
||||
QComboBox *modeBox;
|
||||
QLineEdit *reasonEdit;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue