Show correct art on middle mouse popup (#5385)

This commit is contained in:
Zach H 2024-12-29 18:24:32 -05:00 committed by GitHub
parent dec001114a
commit dad1aea128
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 33 additions and 24 deletions

View file

@ -12,14 +12,16 @@ Tab::Tab(TabSupervisor *_tabSupervisor, QWidget *parent)
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
} }
void Tab::showCardInfoPopup(const QPoint &pos, const QString &cardName) void Tab::showCardInfoPopup(const QPoint &pos, const QString &cardName, const QString &providerId)
{ {
if (infoPopup) { if (infoPopup) {
infoPopup->deleteLater(); infoPopup->deleteLater();
} }
currentCardName = cardName; currentCardName = cardName;
infoPopup = new CardInfoDisplayWidget( currentProviderId = providerId;
cardName, 0, Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint | Qt::WindowStaysOnTopHint); infoPopup = new CardInfoDisplayWidget(cardName, providerId, nullptr,
Qt::Widget | Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint |
Qt::WindowStaysOnTopHint);
infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents); infoPopup->setAttribute(Qt::WA_TransparentForMouseEvents);
auto screenRect = qApp->primaryScreen()->geometry(); auto screenRect = qApp->primaryScreen()->geometry();

View file

@ -21,11 +21,11 @@ protected:
tabMenus.append(menu); tabMenus.append(menu);
} }
protected slots: protected slots:
void showCardInfoPopup(const QPoint &pos, const QString &cardName); void showCardInfoPopup(const QPoint &pos, const QString &cardName, const QString &providerId);
void deleteCardInfoPopup(const QString &cardName); void deleteCardInfoPopup(const QString &cardName);
private: private:
QString currentCardName; QString currentCardName, currentProviderId;
bool contentsChanged; bool contentsChanged;
CardInfoDisplayWidget *infoPopup; CardInfoDisplayWidget *infoPopup;
QList<QMenu *> tabMenus; QList<QMenu *> tabMenus;

View file

@ -1410,7 +1410,7 @@ void TabGame::eventSetActivePhase(const Event_SetActivePhase &event,
void TabGame::newCardAdded(AbstractCardItem *card) void TabGame::newCardAdded(AbstractCardItem *card)
{ {
connect(card, SIGNAL(hovered(AbstractCardItem *)), cardInfoFrameWidget, SLOT(setCard(AbstractCardItem *))); connect(card, SIGNAL(hovered(AbstractCardItem *)), cardInfoFrameWidget, SLOT(setCard(AbstractCardItem *)));
connect(card, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(card, &AbstractCardItem::showCardInfoPopup, this, &TabGame::showCardInfoPopup);
connect(card, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); connect(card, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
connect(card, SIGNAL(cardShiftClicked(QString)), this, SLOT(linkCardToChat(QString))); connect(card, SIGNAL(cardShiftClicked(QString)), this, SLOT(linkCardToChat(QString)));
} }
@ -1892,7 +1892,7 @@ void TabGame::createMessageDock(bool bReplay)
{ {
messageLog = new MessageLogWidget(tabSupervisor, tabSupervisor, this); messageLog = new MessageLogWidget(tabSupervisor, tabSupervisor, this);
connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfoFrameWidget, SLOT(setCard(QString))); connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfoFrameWidget, SLOT(setCard(QString)));
connect(messageLog, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(messageLog, &MessageLogWidget::showCardInfoPopup, this, &TabGame::showCardInfoPopup);
connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); connect(messageLog, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
if (!bReplay) { if (!bReplay) {

View file

@ -26,7 +26,7 @@ TabMessage::TabMessage(TabSupervisor *_tabSupervisor,
otherUserInfo(new ServerInfo_User(_otherUserInfo)), userOnline(true) otherUserInfo(new ServerInfo_User(_otherUserInfo)), userOnline(true)
{ {
chatView = new ChatView(tabSupervisor, tabSupervisor, 0, true); chatView = new ChatView(tabSupervisor, tabSupervisor, 0, true);
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(chatView, &ChatView::showCardInfoPopup, this, &TabMessage::showCardInfoPopup);
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
connect(chatView, SIGNAL(addMentionTag(QString)), this, SLOT(addMentionTag(QString))); connect(chatView, SIGNAL(addMentionTag(QString)), this, SLOT(addMentionTag(QString)));
sayEdit = new LineEditUnfocusable; sayEdit = new LineEditUnfocusable;

View file

@ -55,7 +55,7 @@ TabRoom::TabRoom(TabSupervisor *_tabSupervisor,
connect(chatView, SIGNAL(showMentionPopup(const QString &)), this, SLOT(actShowMentionPopup(const QString &))); connect(chatView, SIGNAL(showMentionPopup(const QString &)), this, SLOT(actShowMentionPopup(const QString &)));
connect(chatView, SIGNAL(messageClickedSignal()), this, SLOT(focusTab())); connect(chatView, SIGNAL(messageClickedSignal()), this, SLOT(focusTab()));
connect(chatView, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool))); connect(chatView, SIGNAL(openMessageDialog(QString, bool)), this, SIGNAL(openMessageDialog(QString, bool)));
connect(chatView, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(chatView, &ChatView::showCardInfoPopup, this, &TabRoom::showCardInfoPopup);
connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); connect(chatView, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString)));
connect(chatView, SIGNAL(addMentionTag(QString)), this, SLOT(addMentionTag(QString))); connect(chatView, SIGNAL(addMentionTag(QString)), this, SLOT(addMentionTag(QString)));
connect(&SettingsCache::instance(), SIGNAL(chatMentionCompleterChanged()), this, SLOT(actCompleterChanged())); connect(&SettingsCache::instance(), SIGNAL(chatMentionCompleterChanged()), this, SLOT(actCompleterChanged()));

View file

@ -11,7 +11,10 @@
#include <QVBoxLayout> #include <QVBoxLayout>
#include <utility> #include <utility>
CardInfoDisplayWidget::CardInfoDisplayWidget(const QString &cardName, QWidget *parent, Qt::WindowFlags flags) CardInfoDisplayWidget::CardInfoDisplayWidget(const QString &cardName,
const QString &providerId,
QWidget *parent,
Qt::WindowFlags flags)
: QFrame(parent, flags), aspectRatio((qreal)CARD_HEIGHT / (qreal)CARD_WIDTH), info(nullptr) : QFrame(parent, flags), aspectRatio((qreal)CARD_HEIGHT / (qreal)CARD_WIDTH), info(nullptr)
{ {
setContentsMargins(3, 3, 3, 3); setContentsMargins(3, 3, 3, 3);
@ -37,7 +40,7 @@ CardInfoDisplayWidget::CardInfoDisplayWidget(const QString &cardName, QWidget *p
pic->setFixedHeight(pixmapHeight); pic->setFixedHeight(pixmapHeight);
setFixedWidth(pixmapWidth + 150); setFixedWidth(pixmapWidth + 150);
setCard(cardName); setCard(cardName, providerId);
// ensure our parent gets a valid size to position us correctly // ensure our parent gets a valid size to position us correctly
resize(width(), sizeHint().height()); resize(width(), sizeHint().height());
@ -55,9 +58,9 @@ void CardInfoDisplayWidget::setCard(CardInfoPtr card)
pic->setCard(info); pic->setCard(info);
} }
void CardInfoDisplayWidget::setCard(const QString &cardName) void CardInfoDisplayWidget::setCard(const QString &cardName, const QString &providerId)
{ {
setCard(CardDatabaseManager::getInstance()->guessCard(cardName)); setCard(CardDatabaseManager::getInstance()->guessCard(cardName, providerId));
if (info == nullptr) { if (info == nullptr) {
text->setInvalidCardName(cardName); text->setInvalidCardName(cardName);
} }

View file

@ -22,11 +22,14 @@ private:
CardInfoTextWidget *text; CardInfoTextWidget *text;
public: public:
explicit CardInfoDisplayWidget(const QString &cardName, QWidget *parent = nullptr, Qt::WindowFlags f = {}); explicit CardInfoDisplayWidget(const QString &cardName,
const QString &providerId,
QWidget *parent = nullptr,
Qt::WindowFlags f = {});
public slots: public slots:
void setCard(CardInfoPtr card); void setCard(CardInfoPtr card);
void setCard(const QString &cardName); void setCard(const QString &cardName, const QString &providerId = QString());
void setCard(AbstractCardItem *card); void setCard(AbstractCardItem *card);
private slots: private slots:

View file

@ -296,7 +296,7 @@ void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
setCursor(Qt::ClosedHandCursor); setCursor(Qt::ClosedHandCursor);
else if (event->button() == Qt::MiddleButton) else if (event->button() == Qt::MiddleButton)
emit showCardInfoPopup(event->screenPos(), name); emit showCardInfoPopup(event->screenPos(), name, providerId);
event->accept(); event->accept();
} }

View file

@ -35,7 +35,7 @@ private slots:
} }
signals: signals:
void hovered(AbstractCardItem *card); void hovered(AbstractCardItem *card);
void showCardInfoPopup(QPoint pos, QString cardName); void showCardInfoPopup(const QPoint &pos, const QString &cardName, const QString &providerId);
void deleteCardInfoPopup(QString cardName); void deleteCardInfoPopup(QString cardName);
void sigPixmapUpdated(); void sigPixmapUpdated();
void cardShiftClicked(QString cardName); void cardShiftClicked(QString cardName);

View file

@ -501,13 +501,14 @@ CardInfoPtr CardDatabase::getCardBySimpleName(const QString &cardName) const
return getCardFromMap(simpleNameCards, CardInfo::simplifyName(cardName)); return getCardFromMap(simpleNameCards, CardInfo::simplifyName(cardName));
} }
CardInfoPtr CardDatabase::guessCard(const QString &cardName) const CardInfoPtr CardDatabase::guessCard(const QString &cardName, const QString &providerId) const
{ {
CardInfoPtr temp = getCard(cardName); CardInfoPtr temp = providerId.isEmpty() ? getCard(cardName) : getCardByNameAndProviderId(cardName, providerId);
if (temp == nullptr) { // get card by simple name instead if (temp == nullptr) { // get card by simple name instead
temp = getCardBySimpleName(cardName); temp = getCardBySimpleName(cardName);
if (temp == nullptr) { // still could not find the card, so simplify the cardName too if (temp == nullptr) { // still could not find the card, so simplify the cardName too
QString simpleCardName = CardInfo::simplifyName(cardName); const auto &simpleCardName = CardInfo::simplifyName(cardName);
temp = getCardBySimpleName(simpleCardName); temp = getCardBySimpleName(simpleCardName);
} }
} }

View file

@ -466,7 +466,7 @@ public:
[[nodiscard]] CardInfoPerSet getPreferredSetForCard(const QString &cardName) const; [[nodiscard]] CardInfoPerSet getPreferredSetForCard(const QString &cardName) const;
[[nodiscard]] CardInfoPerSet getSpecificSetForCard(const QString &cardName, const QString &providerId) const; [[nodiscard]] CardInfoPerSet getSpecificSetForCard(const QString &cardName, const QString &providerId) const;
QString getPreferredPrintingProviderIdForCard(const QString &cardName); QString getPreferredPrintingProviderIdForCard(const QString &cardName);
[[nodiscard]] CardInfoPtr guessCard(const QString &cardName) const; [[nodiscard]] CardInfoPtr guessCard(const QString &cardName, const QString &providerId = QString()) const;
/* /*
* Get a card by its simple name. The name will be simplified in this * Get a card by its simple name. The name will be simplified in this

View file

@ -580,9 +580,9 @@ void ChatView::mousePressEvent(QMouseEvent *event)
case HoveredCard: { case HoveredCard: {
if ((event->button() == Qt::MiddleButton) || (event->button() == Qt::LeftButton)) if ((event->button() == Qt::MiddleButton) || (event->button() == Qt::LeftButton))
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
emit showCardInfoPopup(event->globalPosition().toPoint(), hoveredContent); emit showCardInfoPopup(event->globalPosition().toPoint(), hoveredContent, QString());
#else #else
emit showCardInfoPopup(event->globalPos(), hoveredContent); emit showCardInfoPopup(event->globalPos(), hoveredContent, QString());
#endif #endif
break; break;
} }

View file

@ -115,7 +115,7 @@ protected:
signals: signals:
void openMessageDialog(const QString &userName, bool focus); void openMessageDialog(const QString &userName, bool focus);
void cardNameHovered(QString cardName); void cardNameHovered(QString cardName);
void showCardInfoPopup(QPoint pos, QString cardName); void showCardInfoPopup(const QPoint &pos, const QString &cardName, const QString &providerId);
void deleteCardInfoPopup(QString cardName); void deleteCardInfoPopup(QString cardName);
void addMentionTag(QString mentionTag); void addMentionTag(QString mentionTag);
void messageClickedSignal(); void messageClickedSignal();