Right-click menu added for card database view (#3113)
This commit is contained in:
parent
65ef66cfa7
commit
3d2c7b6670
2 changed files with 34 additions and 0 deletions
|
@ -33,6 +33,7 @@
|
|||
#include <QPrintPreviewDialog>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QPushButton>
|
||||
#include <QSignalMapper>
|
||||
#include <QSplitter>
|
||||
#include <QTextEdit>
|
||||
#include <QTextStream>
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue