mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
add "view related cards" right click menu to card info widget (#5375)
This commit is contained in:
parent
b4036c8671
commit
ac3aa949ad
3 changed files with 56 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include "../../../../game/cards/card_database_manager.h"
|
||||
#include "../../../../game/cards/card_item.h"
|
||||
#include "../../../../settings/cache_settings.h"
|
||||
#include "card_info_display_widget.h"
|
||||
#include "card_info_picture_widget.h"
|
||||
#include "card_info_text_widget.h"
|
||||
|
||||
|
|
@ -16,6 +17,8 @@ CardInfoFrameWidget::CardInfoFrameWidget(const QString &cardName, QWidget *paren
|
|||
setContentsMargins(3, 3, 3, 3);
|
||||
pic = new CardInfoPictureWidget();
|
||||
pic->setObjectName("pic");
|
||||
connect(pic, &CardInfoPictureWidget::cardChanged, this, qOverload<CardInfoPtr>(&CardInfoFrameWidget::setCard));
|
||||
|
||||
text = new CardInfoTextWidget();
|
||||
text->setObjectName("text");
|
||||
connect(text, SIGNAL(linkActivated(const QString &)), this, SLOT(setCard(const QString &)));
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
#include "card_info_picture_widget.h"
|
||||
|
||||
#include "../../../../game/cards/card_database_manager.h"
|
||||
#include "../../../../game/cards/card_item.h"
|
||||
#include "../../../../settings/cache_settings.h"
|
||||
#include "../../picture_loader.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QStylePainter>
|
||||
#include <QWidget>
|
||||
|
|
@ -235,6 +237,52 @@ void CardInfoPictureWidget::mouseMoveEvent(QMouseEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
void CardInfoPictureWidget::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
QWidget::mousePressEvent(event);
|
||||
if (event->button() == Qt::RightButton) {
|
||||
createRightClickMenu()->popup(QCursor::pos());
|
||||
}
|
||||
}
|
||||
|
||||
QMenu *CardInfoPictureWidget::createRightClickMenu()
|
||||
{
|
||||
auto *cardMenu = new QMenu(this);
|
||||
|
||||
if (!info) {
|
||||
return cardMenu;
|
||||
}
|
||||
|
||||
auto viewRelatedCards = new QMenu(tr("View related cards"));
|
||||
cardMenu->addMenu(viewRelatedCards);
|
||||
|
||||
bool atLeastOneGoodRelationFound = false;
|
||||
QList<CardRelation *> relatedCards = info->getAllRelatedCards();
|
||||
for (const CardRelation *cardRelation : relatedCards) {
|
||||
CardInfoPtr relatedCard = CardDatabaseManager::getInstance()->getCard(cardRelation->getName());
|
||||
if (relatedCard != nullptr) {
|
||||
atLeastOneGoodRelationFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!atLeastOneGoodRelationFound) {
|
||||
viewRelatedCards->setEnabled(false);
|
||||
return cardMenu;
|
||||
}
|
||||
|
||||
for (const auto &relatedCard : relatedCards) {
|
||||
const auto &relatedCardName = relatedCard->getName();
|
||||
QAction *viewCard = viewRelatedCards->addAction(relatedCardName);
|
||||
connect(viewCard, &QAction::triggered, this, [this, &relatedCardName] {
|
||||
emit cardChanged(CardDatabaseManager::getInstance()->getCard(relatedCardName));
|
||||
});
|
||||
viewRelatedCards->addAction(viewCard);
|
||||
}
|
||||
|
||||
return cardMenu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Displays the enlarged version of the card's pixmap near the cursor.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <QWidget>
|
||||
|
||||
class AbstractCardItem;
|
||||
class QMenu;
|
||||
|
||||
class CardInfoPictureWidget : public QWidget
|
||||
{
|
||||
|
|
@ -30,6 +31,7 @@ public slots:
|
|||
signals:
|
||||
void hoveredOnCard(CardInfoPtr hoveredCard);
|
||||
void cardScaleFactorChanged(int _scale);
|
||||
void cardChanged(CardInfoPtr card);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
|
|
@ -41,6 +43,7 @@ protected:
|
|||
#endif
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void mouseMoveEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void loadPixmap();
|
||||
[[nodiscard]] const QPixmap &getResizedPixmap() const
|
||||
{
|
||||
|
|
@ -63,6 +66,8 @@ private:
|
|||
CardInfoPictureEnlargedWidget *enlargedPixmapWidget;
|
||||
int enlargedPixmapOffset = 10;
|
||||
QTimer *hoverTimer;
|
||||
|
||||
QMenu *createRightClickMenu();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue