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_EventCreate,
|
||||||
ID_EventDelete,
|
ID_EventDelete,
|
||||||
ID_EventDuplicate,
|
ID_EventDuplicate,
|
||||||
|
ID_EventPaste,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define IDMask_EventType_Object (1 << 8)
|
#define IDMask_EventType_Object (1 << 8)
|
||||||
|
@ -322,7 +323,7 @@ public:
|
||||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||||
int id() const override;
|
int id() const override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
Map *map;
|
Map *map;
|
||||||
QList<Event *> selectedEvents; // allow multiple deletion of events
|
QList<Event *> selectedEvents; // allow multiple deletion of events
|
||||||
Editor *editor;
|
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.
|
/// Implements a command to commit map edits from the scripting API.
|
||||||
/// The scripting api can edit metatiles and map dimensions.
|
/// The scripting api can edit metatiles and map dimensions.
|
||||||
class ScriptEditMap : public QUndoCommand {
|
class ScriptEditMap : public QUndoCommand {
|
||||||
|
|
|
@ -414,7 +414,11 @@ int EventDelete::id() const {
|
||||||
EventDuplicate::EventDuplicate(Editor *editor, Map *map,
|
EventDuplicate::EventDuplicate(Editor *editor, Map *map,
|
||||||
QList<Event *> selectedEvents,
|
QList<Event *> selectedEvents,
|
||||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||||
setText("Duplicate Event");
|
if (selectedEvents.size() > 1) {
|
||||||
|
setText("Duplicate Events");
|
||||||
|
} else {
|
||||||
|
setText("Duplicate Event");
|
||||||
|
}
|
||||||
|
|
||||||
this->editor = editor;
|
this->editor = editor;
|
||||||
|
|
||||||
|
@ -462,6 +466,24 @@ int EventDuplicate::id() const {
|
||||||
return CommandId::ID_EventDuplicate | getEventTypeMask(this->selectedEvents);
|
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()));
|
auto *shortcut_Copy = new Shortcut(QKeySequence("Ctrl+C"), this, SLOT(copy()));
|
||||||
shortcut_Copy->setObjectName("shortcut_Copy");
|
shortcut_Copy->setObjectName("shortcut_Copy");
|
||||||
|
shortcut_Copy->setWhatsThis("Copy");
|
||||||
|
|
||||||
auto *shortcut_Paste = new Shortcut(QKeySequence("Ctrl+V"), this, SLOT(paste()));
|
auto *shortcut_Paste = new Shortcut(QKeySequence("Ctrl+V"), this, SLOT(paste()));
|
||||||
shortcut_Paste->setObjectName("shortcut_Paste");
|
shortcut_Paste->setObjectName("shortcut_Paste");
|
||||||
|
shortcut_Copy->setWhatsThis("Paste");
|
||||||
}
|
}
|
||||||
|
|
||||||
QObjectList MainWindow::shortcutableObjects() const {
|
QObjectList MainWindow::shortcutableObjects() const {
|
||||||
|
@ -1583,18 +1585,8 @@ void MainWindow::paste() {
|
||||||
newEvents.append(pasteEvent);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue