allow copy/paste from mainwindow actions in encounter tab
This commit is contained in:
parent
7973c91bcd
commit
62a6fe8515
3 changed files with 39 additions and 14 deletions
|
@ -24,6 +24,9 @@ public:
|
||||||
|
|
||||||
QTableView *tableAt(int tabIndex);
|
QTableView *tableAt(int tabIndex);
|
||||||
|
|
||||||
|
void copy(int index);
|
||||||
|
void paste(int index);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setTabActive(int index, bool active = true);
|
void setTabActive(int index, bool active = true);
|
||||||
void deactivateTab(int tabIndex);
|
void deactivateTab(int tabIndex);
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "shortcut.h"
|
#include "shortcut.h"
|
||||||
#include "mapparser.h"
|
#include "mapparser.h"
|
||||||
#include "prefab.h"
|
#include "prefab.h"
|
||||||
|
#include "montabwidget.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
@ -1443,7 +1444,8 @@ void MainWindow::copy() {
|
||||||
copyObject["height"] = editor->metatile_selector_item->getSelectionDimensions().y();
|
copyObject["height"] = editor->metatile_selector_item->getSelectionDimensions().y();
|
||||||
setClipboardData(copyObject);
|
setClipboardData(copyObject);
|
||||||
logInfo("Copied metatile selection to clipboard");
|
logInfo("Copied metatile selection to clipboard");
|
||||||
} else if (objectName == "graphicsView_Map") {
|
}
|
||||||
|
else if (objectName == "graphicsView_Map") {
|
||||||
// which tab are we in?
|
// which tab are we in?
|
||||||
switch (ui->mainTabBar->currentIndex())
|
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();
|
QClipboard *clipboard = QGuiApplication::clipboard();
|
||||||
QString clipboardText(clipboard->text());
|
QString clipboardText(clipboard->text());
|
||||||
|
|
||||||
|
if (ui->mainTabBar->currentIndex() == 4) {
|
||||||
if (!clipboardText.isEmpty()) {
|
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
|
// we only can paste json text
|
||||||
// so, check if clipboard text is valid json
|
// so, check if clipboard text is valid json
|
||||||
QString parseError;
|
QString parseError;
|
||||||
|
|
|
@ -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) {
|
void MonTabWidget::actionCopyTab(int index) {
|
||||||
QMenu contextMenu(this);
|
QMenu contextMenu(this);
|
||||||
|
|
||||||
QAction *actionCopy = new QAction("Copy", &contextMenu);
|
QAction *actionCopy = new QAction("Copy", &contextMenu);
|
||||||
connect(actionCopy, &QAction::triggered, [=](){
|
connect(actionCopy, &QAction::triggered, [=]() { copy(index); });
|
||||||
EncounterTableModel *model = static_cast<EncounterTableModel *>(this->tableAt(index)->model());
|
|
||||||
encounterClipboard = model->encounterData();
|
|
||||||
});
|
|
||||||
contextMenu.addAction(actionCopy);
|
contextMenu.addAction(actionCopy);
|
||||||
|
|
||||||
if (encounterClipboard.active) {
|
if (encounterClipboard.active) {
|
||||||
QAction *actionPaste = new QAction("Paste", &contextMenu);
|
QAction *actionPaste = new QAction("Paste", &contextMenu);
|
||||||
connect(actionPaste, &QAction::triggered, [=](){
|
connect(actionPaste, &QAction::triggered, [=]() { paste(index); });
|
||||||
clearTableAt(index);
|
|
||||||
WildMonInfo newInfo = getDefaultMonInfo(editor->project->wildMonFields.at(index));
|
|
||||||
combineEncounters(newInfo, encounterClipboard);
|
|
||||||
populateTab(index, newInfo);
|
|
||||||
emit editor->wildMonDataChanged();
|
|
||||||
});
|
|
||||||
contextMenu.addAction(actionPaste);
|
contextMenu.addAction(actionPaste);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue