mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-19 08:52:15 -07:00
create right click menu
This commit is contained in:
parent
a4db7abb17
commit
81a8a091f6
2 changed files with 42 additions and 1 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
#include "card_info_picture_widget.h"
|
#include "card_info_picture_widget.h"
|
||||||
|
|
||||||
|
#include "../../../../game/cards/card_database_manager.h"
|
||||||
#include "../../../../game/cards/card_item.h"
|
#include "../../../../game/cards/card_item.h"
|
||||||
#include "../../../../settings/cache_settings.h"
|
#include "../../../../settings/cache_settings.h"
|
||||||
#include "../../picture_loader.h"
|
#include "../../picture_loader.h"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QStylePainter>
|
#include <QStylePainter>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
@ -239,10 +241,46 @@ void CardInfoPictureWidget::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::mousePressEvent(event);
|
QWidget::mousePressEvent(event);
|
||||||
if (event->button() == Qt::RightButton) {
|
if (event->button() == Qt::RightButton) {
|
||||||
qDebug() << "TRACK clicked!";
|
createRightClickMenu()->popup(QCursor::pos());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QMenu *CardInfoPictureWidget::createRightClickMenu()
|
||||||
|
{
|
||||||
|
auto *cardMenu = new QMenu(this);
|
||||||
|
|
||||||
|
if (!info) {
|
||||||
|
return cardMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
return cardMenu;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto ¤tCardSet = CardDatabase::getSetInfoForCard(info);
|
||||||
|
|
||||||
|
auto viewRelatedCards = new QMenu(tr("View related cards"));
|
||||||
|
cardMenu->addMenu(viewRelatedCards);
|
||||||
|
for (const CardRelation *relatedCard : relatedCards) {
|
||||||
|
QString relatedCardName = relatedCard->getName();
|
||||||
|
// QAction *viewCard = viewRelatedCards->addAction(relatedCardName);
|
||||||
|
/*connect(viewCard, &QAction::triggered, game, [this, relatedCardName, currentCardSet] {
|
||||||
|
game->viewCardInfo(relatedCardName, currentCardSet.getProperty("uuid"));
|
||||||
|
});*/
|
||||||
|
}
|
||||||
|
return cardMenu;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Displays the enlarged version of the card's pixmap near the cursor.
|
* @brief Displays the enlarged version of the card's pixmap near the cursor.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
class AbstractCardItem;
|
class AbstractCardItem;
|
||||||
|
class QMenu;
|
||||||
|
|
||||||
class CardInfoPictureWidget : public QWidget
|
class CardInfoPictureWidget : public QWidget
|
||||||
{
|
{
|
||||||
|
|
@ -64,6 +65,8 @@ private:
|
||||||
CardInfoPictureEnlargedWidget *enlargedPixmapWidget;
|
CardInfoPictureEnlargedWidget *enlargedPixmapWidget;
|
||||||
int enlargedPixmapOffset = 10;
|
int enlargedPixmapOffset = 10;
|
||||||
QTimer *hoverTimer;
|
QTimer *hoverTimer;
|
||||||
|
|
||||||
|
QMenu *createRightClickMenu();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue