From ea2bfa7274459a65b4dffd33447b3fac1cdd7905 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 9 Jul 2020 18:31:35 -0400 Subject: [PATCH] Add duplicate shortcut for events --- include/core/event.h | 1 + include/editor.h | 1 + include/mainwindow.h | 1 + src/core/event.cpp | 13 +++++++++++++ src/editor.cpp | 16 ++++++++++++++++ src/mainwindow.cpp | 5 +++++ 6 files changed, 37 insertions(+) diff --git a/include/core/event.h b/include/core/event.h index 8bbb7168..eb56dfbd 100644 --- a/include/core/event.h +++ b/include/core/event.h @@ -27,6 +27,7 @@ class Event { public: Event(); + Event(const Event&); Event(QJsonObject, QString); public: int x() { diff --git a/include/editor.h b/include/editor.h index 3447f8a3..ba54e917 100644 --- a/include/editor.h +++ b/include/editor.h @@ -100,6 +100,7 @@ public: Event* createNewEvent(QString event_type); void deleteEvent(Event *); void updateSelectedEvents(); + void duplicateSelectedEvents(); void redrawObject(DraggablePixmapItem *item); QList *getObjects(); diff --git a/include/mainwindow.h b/include/mainwindow.h index 79a504e4..fc0007f6 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -123,6 +123,7 @@ private slots: void undo(); void redo(); + void duplicate(); void openInTextEditor(); diff --git a/src/core/event.cpp b/src/core/event.cpp index a872a519..c35c37f5 100644 --- a/src/core/event.cpp +++ b/src/core/event.cpp @@ -19,6 +19,19 @@ Event::Event() this->usingSprite = false; } +Event::Event(const Event& toCopy) +{ + Event(); + this->values = toCopy.values; + this->customValues = toCopy.customValues; + this->pixmap = toCopy.pixmap; + this->spriteWidth = toCopy.spriteWidth; + this->spriteHeight = toCopy.spriteHeight; + this->frame = toCopy.frame; + this->hFlip = toCopy.hFlip; + this->usingSprite = toCopy.usingSprite; +} + Event::Event(QJsonObject obj, QString type) { Event(); diff --git a/src/editor.cpp b/src/editor.cpp index 91bf9166..1e303f02 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1881,6 +1881,22 @@ void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) { } } +void Editor::duplicateSelectedEvents() { + if (!selected_events || !selected_events->length() || !map || !current_view || map_item->paintingMode != MapPixmapItem::PaintMode::EventObjects) + return; + + QList *duplicates = new QList; + for (int i = 0; i < selected_events->length(); i++) { + Event *duplicate = new Event(*selected_events->at(i)->event); + map->addEvent(duplicate); + DraggablePixmapItem *object = addMapEvent(duplicate); + duplicates->append(object); + } + selected_events->clear(); + selected_events = duplicates; + updateSelectedEvents(); +} + DraggablePixmapItem* Editor::addNewEvent(QString event_type) { if (project && map && !event_type.isEmpty()) { Event *event = Event::createNewEvent(event_type, map->name, project); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2d200f68..af8fe381 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -77,6 +77,7 @@ void MainWindow::initExtraShortcuts() { new QShortcut(QKeySequence("Ctrl+Shift+Z"), this, SLOT(redo())); new QShortcut(QKeySequence("Ctrl+0"), this, SLOT(resetMapViewScale())); new QShortcut(QKeySequence("Ctrl+G"), ui->checkBox_ToggleGrid, SLOT(toggle())); + new QShortcut(QKeySequence("Ctrl+D"), this, SLOT(duplicate())); ui->actionZoom_In->setShortcuts({QKeySequence("Ctrl++"), QKeySequence("Ctrl+=")}); } @@ -1230,6 +1231,10 @@ void MainWindow::redo() { editor->redo(); } +void MainWindow::duplicate() { + editor->duplicateSelectedEvents(); +} + // Open current map scripts in system default editor for .inc files void MainWindow::openInTextEditor() { bool usePoryscript = projectConfig.getUsePoryScript();