add edit command for event pastes
This commit is contained in:
parent
296d697df0
commit
47887aca4d
3 changed files with 39 additions and 13 deletions
|
@ -30,6 +30,7 @@ enum CommandId {
|
|||
ID_EventCreate,
|
||||
ID_EventDelete,
|
||||
ID_EventDuplicate,
|
||||
ID_EventPaste,
|
||||
};
|
||||
|
||||
#define IDMask_EventType_Object (1 << 8)
|
||||
|
@ -322,7 +323,7 @@ public:
|
|||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override;
|
||||
|
||||
private:
|
||||
protected:
|
||||
Map *map;
|
||||
QList<Event *> selectedEvents; // allow multiple deletion of events
|
||||
Editor *editor;
|
||||
|
@ -330,6 +331,17 @@ private:
|
|||
|
||||
|
||||
|
||||
/// Implements a command to commit Event pastes from clipboard.
|
||||
class EventPaste : public EventDuplicate {
|
||||
public:
|
||||
EventPaste(Editor *editor, Map *map, QList<Event *> pastedEvents,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
int id() const override;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Implements a command to commit map edits from the scripting API.
|
||||
/// The scripting api can edit metatiles and map dimensions.
|
||||
class ScriptEditMap : public QUndoCommand {
|
||||
|
|
|
@ -414,7 +414,11 @@ int EventDelete::id() const {
|
|||
EventDuplicate::EventDuplicate(Editor *editor, Map *map,
|
||||
QList<Event *> selectedEvents,
|
||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
setText("Duplicate Event");
|
||||
if (selectedEvents.size() > 1) {
|
||||
setText("Duplicate Events");
|
||||
} else {
|
||||
setText("Duplicate Event");
|
||||
}
|
||||
|
||||
this->editor = editor;
|
||||
|
||||
|
@ -462,6 +466,24 @@ int EventDuplicate::id() const {
|
|||
return CommandId::ID_EventDuplicate | getEventTypeMask(this->selectedEvents);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
EventPaste::EventPaste(Editor *editor, Map *map,
|
||||
QList<Event *> pastedEvents,
|
||||
QUndoCommand *parent) : EventDuplicate(editor, map, pastedEvents) {
|
||||
if (pastedEvents.size() > 1) {
|
||||
setText("Paste Events");
|
||||
} else {
|
||||
setText("Paste Event");
|
||||
}
|
||||
}
|
||||
|
||||
int EventPaste::id() const {
|
||||
return CommandId::ID_EventPaste | getEventTypeMask(this->selectedEvents);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
|
|
@ -156,9 +156,11 @@ void MainWindow::initExtraShortcuts() {
|
|||
|
||||
auto *shortcut_Copy = new Shortcut(QKeySequence("Ctrl+C"), this, SLOT(copy()));
|
||||
shortcut_Copy->setObjectName("shortcut_Copy");
|
||||
shortcut_Copy->setWhatsThis("Copy");
|
||||
|
||||
auto *shortcut_Paste = new Shortcut(QKeySequence("Ctrl+V"), this, SLOT(paste()));
|
||||
shortcut_Paste->setObjectName("shortcut_Paste");
|
||||
shortcut_Copy->setWhatsThis("Paste");
|
||||
}
|
||||
|
||||
QObjectList MainWindow::shortcutableObjects() const {
|
||||
|
@ -1583,18 +1585,8 @@ void MainWindow::paste() {
|
|||
newEvents.append(pasteEvent);
|
||||
}
|
||||
|
||||
editor->project->loadEventPixmaps(editor->map->getAllEvents());
|
||||
editor->map->editHistory.push(new EventPaste(this->editor, editor->map, newEvents));
|
||||
|
||||
for (Event *event : newEvents) {
|
||||
editor->addMapEvent(event);
|
||||
}
|
||||
|
||||
// select these events
|
||||
editor->selected_events->clear();
|
||||
for (Event *event : newEvents) {
|
||||
editor->selected_events->append(event->pixmapItem);
|
||||
}
|
||||
editor->shouldReselectEvents();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue