change encounter copy behavior
This commit is contained in:
parent
5de1bbd44c
commit
7973c91bcd
2 changed files with 19 additions and 13 deletions
|
@ -14,7 +14,7 @@ class MonTabWidget : public QTabWidget {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MonTabWidget(Editor *editor = nullptr, QWidget *parent = nullptr);
|
explicit MonTabWidget(Editor *editor = nullptr, QWidget *parent = nullptr);
|
||||||
~MonTabWidget(){};
|
~MonTabWidget();
|
||||||
|
|
||||||
void populate();
|
void populate();
|
||||||
void populateTab(int tabIndex, WildMonInfo monInfo);
|
void populateTab(int tabIndex, WildMonInfo monInfo);
|
||||||
|
|
|
@ -6,12 +6,18 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static WildMonInfo encounterClipboard;
|
||||||
|
|
||||||
MonTabWidget::MonTabWidget(Editor *editor, QWidget *parent) : QTabWidget(parent) {
|
MonTabWidget::MonTabWidget(Editor *editor, QWidget *parent) : QTabWidget(parent) {
|
||||||
this->editor = editor;
|
this->editor = editor;
|
||||||
populate();
|
populate();
|
||||||
this->tabBar()->installEventFilter(this);
|
this->tabBar()->installEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MonTabWidget::~MonTabWidget() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool MonTabWidget::eventFilter(QObject *, QEvent *event) {
|
bool MonTabWidget::eventFilter(QObject *, QEvent *event) {
|
||||||
if (event->type() == QEvent::Wheel) {
|
if (event->type() == QEvent::Wheel) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -53,25 +59,25 @@ void MonTabWidget::populate() {
|
||||||
void MonTabWidget::actionCopyTab(int index) {
|
void MonTabWidget::actionCopyTab(int index) {
|
||||||
QMenu contextMenu(this);
|
QMenu contextMenu(this);
|
||||||
|
|
||||||
for (int i = 0; i < this->tabBar()->count(); i++) {
|
QAction *actionCopy = new QAction("Copy", &contextMenu);
|
||||||
if (index == i) continue;
|
connect(actionCopy, &QAction::triggered, [=](){
|
||||||
if (!activeTabs[i]) continue;
|
EncounterTableModel *model = static_cast<EncounterTableModel *>(this->tableAt(index)->model());
|
||||||
|
encounterClipboard = model->encounterData();
|
||||||
|
});
|
||||||
|
contextMenu.addAction(actionCopy);
|
||||||
|
|
||||||
QString tabText = this->tabBar()->tabText(i);
|
if (encounterClipboard.active) {
|
||||||
QAction *actionCopyFrom = new QAction(QString("Copy encounters from %1").arg(tabText), &contextMenu);
|
QAction *actionPaste = new QAction("Paste", &contextMenu);
|
||||||
|
connect(actionPaste, &QAction::triggered, [=](){
|
||||||
connect(actionCopyFrom, &QAction::triggered, [=](){
|
|
||||||
EncounterTableModel *model = static_cast<EncounterTableModel *>(this->tableAt(i)->model());
|
|
||||||
WildMonInfo copyInfo = model->encounterData();
|
|
||||||
clearTableAt(index);
|
clearTableAt(index);
|
||||||
WildMonInfo newInfo = getDefaultMonInfo(editor->project->wildMonFields.at(index));
|
WildMonInfo newInfo = getDefaultMonInfo(editor->project->wildMonFields.at(index));
|
||||||
combineEncounters(newInfo, copyInfo);
|
combineEncounters(newInfo, encounterClipboard);
|
||||||
populateTab(index, newInfo);
|
populateTab(index, newInfo);
|
||||||
emit editor->wildMonDataChanged();
|
emit editor->wildMonDataChanged();
|
||||||
});
|
});
|
||||||
|
contextMenu.addAction(actionPaste);
|
||||||
contextMenu.addAction(actionCopyFrom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contextMenu.exec(mapToGlobal(this->copyTabButtons[index]->pos() + QPoint(0, this->copyTabButtons[index]->height())));
|
contextMenu.exec(mapToGlobal(this->copyTabButtons[index]->pos() + QPoint(0, this->copyTabButtons[index]->height())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue