diff --git a/include/ui/montabwidget.h b/include/ui/montabwidget.h index e12d998d..4b66969c 100644 --- a/include/ui/montabwidget.h +++ b/include/ui/montabwidget.h @@ -24,6 +24,9 @@ public: QTableView *tableAt(int tabIndex); + void copy(int index); + void paste(int index); + public slots: void setTabActive(int index, bool active = true); void deactivateTab(int tabIndex); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8fb5d519..20a078a9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -17,6 +17,7 @@ #include "shortcut.h" #include "mapparser.h" #include "prefab.h" +#include "montabwidget.h" #include #include @@ -1443,7 +1444,8 @@ void MainWindow::copy() { copyObject["height"] = editor->metatile_selector_item->getSelectionDimensions().y(); setClipboardData(copyObject); logInfo("Copied metatile selection to clipboard"); - } else if (objectName == "graphicsView_Map") { + } + else if (objectName == "graphicsView_Map") { // which tab are we in? switch (ui->mainTabBar->currentIndex()) { @@ -1497,6 +1499,13 @@ void MainWindow::copy() { } } } + else if (this->ui->mainTabBar->currentIndex() == 4) { + QWidget *w = this->ui->stackedWidget_WildMons->currentWidget(); + if (w) { + MonTabWidget *mtw = static_cast(w); + mtw->copy(mtw->currentIndex()); + } + } } } @@ -1521,8 +1530,15 @@ void MainWindow::paste() { QClipboard *clipboard = QGuiApplication::clipboard(); QString clipboardText(clipboard->text()); - - if (!clipboardText.isEmpty()) { + if (ui->mainTabBar->currentIndex() == 4) { + QWidget *w = this->ui->stackedWidget_WildMons->currentWidget(); + if (w) { + w->setFocus(); + MonTabWidget *mtw = static_cast(w); + mtw->paste(mtw->currentIndex()); + } + } + else if (!clipboardText.isEmpty()) { // we only can paste json text // so, check if clipboard text is valid json QString parseError; diff --git a/src/ui/montabwidget.cpp b/src/ui/montabwidget.cpp index 45b0319b..6845a02b 100644 --- a/src/ui/montabwidget.cpp +++ b/src/ui/montabwidget.cpp @@ -56,25 +56,31 @@ void MonTabWidget::populate() { } } +void MonTabWidget::copy(int index) { + EncounterTableModel *model = static_cast(this->tableAt(index)->model()); + encounterClipboard = model->encounterData(); +} + +void MonTabWidget::paste(int index) { + if (!encounterClipboard.active) return; + + clearTableAt(index); + WildMonInfo newInfo = getDefaultMonInfo(this->editor->project->wildMonFields.at(index)); + combineEncounters(newInfo, encounterClipboard); + populateTab(index, newInfo); + emit editor->wildMonDataChanged(); +} + void MonTabWidget::actionCopyTab(int index) { QMenu contextMenu(this); QAction *actionCopy = new QAction("Copy", &contextMenu); - connect(actionCopy, &QAction::triggered, [=](){ - EncounterTableModel *model = static_cast(this->tableAt(index)->model()); - encounterClipboard = model->encounterData(); - }); + connect(actionCopy, &QAction::triggered, [=]() { copy(index); }); contextMenu.addAction(actionCopy); if (encounterClipboard.active) { QAction *actionPaste = new QAction("Paste", &contextMenu); - connect(actionPaste, &QAction::triggered, [=](){ - clearTableAt(index); - WildMonInfo newInfo = getDefaultMonInfo(editor->project->wildMonFields.at(index)); - combineEncounters(newInfo, encounterClipboard); - populateTab(index, newInfo); - emit editor->wildMonDataChanged(); - }); + connect(actionPaste, &QAction::triggered, [=]() { paste(index); }); contextMenu.addAction(actionPaste); }