mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 08:22:15 -07:00
DeckDock can handle its own menu.
This commit is contained in:
parent
c62fad7dae
commit
a868d37438
4 changed files with 39 additions and 30 deletions
|
|
@ -48,18 +48,6 @@ void TabGenericDeckEditor::updateCard(CardInfoPtr _card)
|
|||
printingSelectorDockWidget->printingSelector->setCard(_card, DECK_ZONE_MAIN);
|
||||
}
|
||||
|
||||
void TabGenericDeckEditor::decklistCustomMenu(QPoint point)
|
||||
{
|
||||
QMenu menu;
|
||||
const CardInfoPtr info = cardInfoDockWidget->cardInfo->getInfo();
|
||||
|
||||
QAction *selectPrinting = menu.addAction(tr("Select Printing"));
|
||||
|
||||
connect(selectPrinting, &QAction::triggered, this, &TabGenericDeckEditor::showPrintingSelector);
|
||||
|
||||
menu.exec(deckDockWidget->deckView->mapToGlobal(point));
|
||||
}
|
||||
|
||||
bool TabGenericDeckEditor::confirmClose()
|
||||
{
|
||||
if (modified) {
|
||||
|
|
@ -225,7 +213,7 @@ void TabGenericDeckEditor::openDeckFromFile(const QString &fileName, DeckOpenLoc
|
|||
|
||||
bool TabGenericDeckEditor::actSaveDeck()
|
||||
{
|
||||
DeckLoader *const deck = deckDockWidget->deckModel->getDeckList();
|
||||
DeckLoader *const deck = getDeckList();
|
||||
if (deck->getLastRemoteDeckId() != -1) {
|
||||
QString deckString = deck->writeToString_Native();
|
||||
if (deckString.length() > MAX_FILE_LENGTH) {
|
||||
|
|
@ -262,14 +250,14 @@ bool TabGenericDeckEditor::actSaveDeckAs()
|
|||
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
dialog.setDefaultSuffix("cod");
|
||||
dialog.setNameFilters(DeckLoader::fileNameFilters);
|
||||
dialog.selectFile(deckDockWidget->deckModel->getDeckList()->getName().trimmed() + ".cod");
|
||||
dialog.selectFile(getDeckList()->getName().trimmed() + ".cod");
|
||||
if (!dialog.exec())
|
||||
return false;
|
||||
|
||||
QString fileName = dialog.selectedFiles().at(0);
|
||||
DeckLoader::FileFormat fmt = DeckLoader::getFormatFromName(fileName);
|
||||
|
||||
if (!deckDockWidget->deckModel->getDeckList()->saveToFile(fileName, fmt)) {
|
||||
if (!getDeckList()->saveToFile(fileName, fmt)) {
|
||||
QMessageBox::critical(
|
||||
this, tr("Error"),
|
||||
tr("The deck could not be saved.\nPlease check that the directory is writable and try again."));
|
||||
|
|
@ -316,7 +304,7 @@ void TabGenericDeckEditor::actSaveDeckToClipboard()
|
|||
{
|
||||
QString buffer;
|
||||
QTextStream stream(&buffer);
|
||||
deckDockWidget->deckModel->getDeckList()->saveToStream_Plain(stream);
|
||||
getDeckList()->saveToStream_Plain(stream);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Clipboard);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Selection);
|
||||
}
|
||||
|
|
@ -325,7 +313,7 @@ void TabGenericDeckEditor::actSaveDeckToClipboardNoSetNameAndNumber()
|
|||
{
|
||||
QString buffer;
|
||||
QTextStream stream(&buffer);
|
||||
deckDockWidget->deckModel->getDeckList()->saveToStream_Plain(stream, true, false);
|
||||
getDeckList()->saveToStream_Plain(stream, true, false);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Clipboard);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Selection);
|
||||
}
|
||||
|
|
@ -334,7 +322,7 @@ void TabGenericDeckEditor::actSaveDeckToClipboardRaw()
|
|||
{
|
||||
QString buffer;
|
||||
QTextStream stream(&buffer);
|
||||
deckDockWidget->deckModel->getDeckList()->saveToStream_Plain(stream, false);
|
||||
getDeckList()->saveToStream_Plain(stream, false);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Clipboard);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Selection);
|
||||
}
|
||||
|
|
@ -343,7 +331,7 @@ void TabGenericDeckEditor::actSaveDeckToClipboardRawNoSetNameAndNumber()
|
|||
{
|
||||
QString buffer;
|
||||
QTextStream stream(&buffer);
|
||||
deckDockWidget->deckModel->getDeckList()->saveToStream_Plain(stream, false, false);
|
||||
getDeckList()->saveToStream_Plain(stream, false, false);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Clipboard);
|
||||
QApplication::clipboard()->setText(buffer, QClipboard::Selection);
|
||||
}
|
||||
|
|
@ -359,7 +347,7 @@ void TabGenericDeckEditor::actPrintDeck()
|
|||
void TabGenericDeckEditor::actExportDeckDecklist()
|
||||
{
|
||||
// Get the decklist class for the deck.
|
||||
DeckLoader *const deck = deckDockWidget->deckModel->getDeckList();
|
||||
DeckLoader *const deck = getDeckList();
|
||||
// create a string to load the decklist url into.
|
||||
QString decklistUrlString;
|
||||
// check if deck is not null
|
||||
|
|
@ -389,14 +377,14 @@ void TabGenericDeckEditor::actAnalyzeDeckDeckstats()
|
|||
{
|
||||
auto *interface = new DeckStatsInterface(*databaseDisplayDockWidget->databaseModel->getDatabase(),
|
||||
this); // it deletes itself when done
|
||||
interface->analyzeDeck(deckDockWidget->deckModel->getDeckList());
|
||||
interface->analyzeDeck(getDeckList());
|
||||
}
|
||||
|
||||
void TabGenericDeckEditor::actAnalyzeDeckTappedout()
|
||||
{
|
||||
auto *interface = new TappedOutInterface(*databaseDisplayDockWidget->databaseModel->getDatabase(),
|
||||
this); // it deletes itself when done
|
||||
interface->analyzeDeck(deckDockWidget->deckModel->getDeckList());
|
||||
interface->analyzeDeck(getDeckList());
|
||||
}
|
||||
|
||||
void TabGenericDeckEditor::addCardHelper(const CardInfoPtr info, QString zoneName)
|
||||
|
|
|
|||
|
|
@ -83,8 +83,6 @@ signals:
|
|||
void deckEditorClosing(TabGenericDeckEditor *tab);
|
||||
|
||||
protected slots:
|
||||
void decklistCustomMenu(QPoint point);
|
||||
|
||||
// Deck Operations
|
||||
virtual void actNewDeck();
|
||||
void cleanDeckAndResetModified();
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
|||
connect(deckView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||
&DeckEditorDeckDockWidget::updateCard);
|
||||
connect(deckView, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(actSwapCard()));
|
||||
connect(deckView, SIGNAL(customContextMenuRequested(QPoint)), deckEditor, SLOT(decklistCustomMenu(QPoint)));
|
||||
connect(deckView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(decklistCustomMenu(QPoint)));
|
||||
connect(&deckViewKeySignals, SIGNAL(onShiftS()), this, SLOT(actSwapCard()));
|
||||
connect(&deckViewKeySignals, SIGNAL(onEnter()), this, SLOT(actIncrement()));
|
||||
connect(&deckViewKeySignals, SIGNAL(onCtrlAltEqual()), this, SLOT(actIncrement()));
|
||||
|
|
@ -164,16 +164,17 @@ void DeckEditorDeckDockWidget::createDeckDock()
|
|||
retranslateUi();
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::updateCard(const QModelIndex ¤t, const QModelIndex & /*previous*/)
|
||||
CardInfoPtr DeckEditorDeckDockWidget::getCurrentCard()
|
||||
{
|
||||
QModelIndex current = deckView->selectionModel()->currentIndex();
|
||||
if (!current.isValid())
|
||||
return;
|
||||
return {};
|
||||
const QString cardName = current.sibling(current.row(), 1).data().toString();
|
||||
const QString cardProviderID = current.sibling(current.row(), 4).data().toString();
|
||||
const QModelIndex gparent = current.parent().parent();
|
||||
|
||||
if (!gparent.isValid()) {
|
||||
return;
|
||||
return {};
|
||||
}
|
||||
|
||||
const QString zoneName = gparent.sibling(gparent.row(), 1).data(Qt::EditRole).toString();
|
||||
|
|
@ -183,9 +184,17 @@ void DeckEditorDeckDockWidget::updateCard(const QModelIndex ¤t, const QMod
|
|||
QString providerId = current.sibling(current.row(), 4).data().toString();
|
||||
if (CardInfoPtr selectedCard =
|
||||
CardDatabaseManager::getInstance()->getCardByNameAndProviderId(cardName, providerId)) {
|
||||
emit cardChanged(selectedCard);
|
||||
return selectedCard;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::updateCard(const QModelIndex /*¤t*/, const QModelIndex & /*previous*/)
|
||||
{
|
||||
if (CardInfoPtr card = getCurrentCard()) {
|
||||
emit cardChanged(card);
|
||||
}
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::updateName(const QString &name)
|
||||
|
|
@ -464,6 +473,18 @@ void DeckEditorDeckDockWidget::offsetCountAtIndex(const QModelIndex &idx, int of
|
|||
// setModified(true);
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::decklistCustomMenu(QPoint point)
|
||||
{
|
||||
QMenu menu;
|
||||
const CardInfoPtr info = getCurrentCard();
|
||||
|
||||
QAction *selectPrinting = menu.addAction(tr("Select Printing"));
|
||||
|
||||
connect(selectPrinting, &QAction::triggered, deckEditor, &TabGenericDeckEditor::showPrintingSelector);
|
||||
|
||||
menu.exec(deckView->mapToGlobal(point));
|
||||
}
|
||||
|
||||
void DeckEditorDeckDockWidget::refreshShortcuts()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public:
|
|||
QTreeView *deckView;
|
||||
QComboBox *bannerCardComboBox;
|
||||
void createDeckDock();
|
||||
CardInfoPtr getCurrentCard();
|
||||
void retranslateUi();
|
||||
QString getDeckName()
|
||||
{
|
||||
|
|
@ -67,7 +68,8 @@ private:
|
|||
QModelIndexList getSelectedCardNodes() const;
|
||||
|
||||
private slots:
|
||||
void updateCard(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
void decklistCustomMenu(QPoint point);
|
||||
void updateCard(QModelIndex, const QModelIndex ¤t);
|
||||
void updateName(const QString &name);
|
||||
void updateComments();
|
||||
void setBannerCard(int);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue