allow copy/paste from mainwindow actions in encounter tab

This commit is contained in:
garakmon 2023-02-05 17:04:16 -05:00 committed by t
parent 7973c91bcd
commit 62a6fe8515
3 changed files with 39 additions and 14 deletions

View file

@ -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);

View file

@ -17,6 +17,7 @@
#include "shortcut.h"
#include "mapparser.h"
#include "prefab.h"
#include "montabwidget.h"
#include <QFileDialog>
#include <QClipboard>
@ -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<MonTabWidget *>(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<MonTabWidget *>(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;

View file

@ -56,25 +56,31 @@ void MonTabWidget::populate() {
}
}
void MonTabWidget::copy(int index) {
EncounterTableModel *model = static_cast<EncounterTableModel *>(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<EncounterTableModel *>(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);
}