change encounter copy behavior

This commit is contained in:
garakmon 2023-01-26 15:46:44 -05:00 committed by t
parent 5de1bbd44c
commit 7973c91bcd
2 changed files with 19 additions and 13 deletions

View file

@ -14,7 +14,7 @@ class MonTabWidget : public QTabWidget {
public:
explicit MonTabWidget(Editor *editor = nullptr, QWidget *parent = nullptr);
~MonTabWidget(){};
~MonTabWidget();
void populate();
void populateTab(int tabIndex, WildMonInfo monInfo);

View file

@ -6,12 +6,18 @@
static WildMonInfo encounterClipboard;
MonTabWidget::MonTabWidget(Editor *editor, QWidget *parent) : QTabWidget(parent) {
this->editor = editor;
populate();
this->tabBar()->installEventFilter(this);
}
MonTabWidget::~MonTabWidget() {
}
bool MonTabWidget::eventFilter(QObject *, QEvent *event) {
if (event->type() == QEvent::Wheel) {
return true;
@ -53,25 +59,25 @@ void MonTabWidget::populate() {
void MonTabWidget::actionCopyTab(int index) {
QMenu contextMenu(this);
for (int i = 0; i < this->tabBar()->count(); i++) {
if (index == i) continue;
if (!activeTabs[i]) continue;
QAction *actionCopy = new QAction("Copy", &contextMenu);
connect(actionCopy, &QAction::triggered, [=](){
EncounterTableModel *model = static_cast<EncounterTableModel *>(this->tableAt(index)->model());
encounterClipboard = model->encounterData();
});
contextMenu.addAction(actionCopy);
QString tabText = this->tabBar()->tabText(i);
QAction *actionCopyFrom = new QAction(QString("Copy encounters from %1").arg(tabText), &contextMenu);
connect(actionCopyFrom, &QAction::triggered, [=](){
EncounterTableModel *model = static_cast<EncounterTableModel *>(this->tableAt(i)->model());
WildMonInfo copyInfo = model->encounterData();
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, copyInfo);
combineEncounters(newInfo, encounterClipboard);
populateTab(index, newInfo);
emit editor->wildMonDataChanged();
});
contextMenu.addAction(actionCopyFrom);
contextMenu.addAction(actionPaste);
}
contextMenu.exec(mapToGlobal(this->copyTabButtons[index]->pos() + QPoint(0, this->copyTabButtons[index]->height())));
}