From 3d2c7b6670f5096c746c9a2ebd5265050082ebb0 Mon Sep 17 00:00:00 2001 From: Vafthrudnir Date: Thu, 15 Feb 2018 09:25:44 +0100 Subject: [PATCH] Right-click menu added for card database view (#3113) --- cockatrice/src/tab_deck_editor.cpp | 33 ++++++++++++++++++++++++++++++ cockatrice/src/tab_deck_editor.h | 1 + 2 files changed, 34 insertions(+) diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 75d7f22d..2696f719 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -380,6 +381,8 @@ void TabDeckEditor::createCentralFrame() databaseView->setSortingEnabled(true); databaseView->sortByColumn(0, Qt::AscendingOrder); databaseView->setModel(databaseDisplayModel); + databaseView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(databaseView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(databaseCustomMenu(QPoint))); connect(databaseView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(updateCardInfoLeft(const QModelIndex &, const QModelIndex &))); connect(databaseView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actAddCard())); @@ -440,6 +443,36 @@ void TabDeckEditor::createCentralFrame() setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowNestedDocks | QMainWindow::AllowTabbedDocks); } +void TabDeckEditor::databaseCustomMenu(QPoint point) +{ + QMenu menu; + const CardInfoPtr info = currentCardInfo(); + + // add to deck and sideboard options + QAction *addToDeck, *addToSideboard; + addToDeck = menu.addAction(tr("Add to Deck")); + addToSideboard = menu.addAction(tr("Add to Sideboard")); + connect(addToDeck, SIGNAL(triggered()), this, SLOT(actAddCard())); + connect(addToSideboard, SIGNAL(triggered()), this, SLOT(actAddCardToSideboard())); + + // filling out the related cards submenu + auto *relatedMenu = new QMenu(tr("Show Related cards")); + menu.addMenu(relatedMenu); + if (info->getRelatedCards().isEmpty()) { + relatedMenu->setDisabled(true); + } else { + auto *signalMapper = new QSignalMapper(this); + for (const CardRelation *rel : info->getRelatedCards()) { + QAction *relatedCard; + relatedCard = relatedMenu->addAction(rel->getName()); + connect(relatedCard, SIGNAL(triggered()), signalMapper, SLOT(map())); + signalMapper->setMapping(relatedCard, rel->getName()); + } + connect(signalMapper, SIGNAL(mapped(const QString &)), cardInfo, SLOT(setCard(const QString &))); + } + menu.exec(databaseView->mapToGlobal(point)); +} + void TabDeckEditor::restartLayout() { deckDock->setVisible(true); diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index 955b657d..8faca7aa 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -55,6 +55,7 @@ private slots: void updateCardInfoLeft(const QModelIndex ¤t, const QModelIndex &previous); void updateCardInfoRight(const QModelIndex ¤t, const QModelIndex &previous); void updateSearch(const QString &search); + void databaseCustomMenu(QPoint point); void actNewDeck(); void actLoadDeck();