mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-22 01:25:10 -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue