From df861b59ad0e9847c7386567d89e08f807aa2d5f Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 7 Feb 2025 14:50:00 -0500 Subject: [PATCH] Shift events if map moves when resized --- include/editor.h | 2 ++ src/editor.cpp | 5 ++--- src/mainwindow.cpp | 11 +++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/editor.h b/include/editor.h index 81bf1611..d744ac99 100644 --- a/include/editor.h +++ b/include/editor.h @@ -180,6 +180,8 @@ public: qreal collisionOpacity = 0.5; static QList> collisionIcons; + int eventShiftActionId = 0; + void objectsView_onMousePress(QMouseEvent *event); int getBorderDrawDistance(int dimension); diff --git a/src/editor.cpp b/src/editor.cpp index ce8752c3..8a0f391b 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1379,10 +1379,9 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i // do nothing here, at least for now } else if (objectEditAction == EditAction::Shift) { static QPoint selection_origin; - static unsigned actionId = 0; if (event->type() == QEvent::GraphicsSceneMouseRelease) { - actionId++; + this->eventShiftActionId++; } else { if (event->type() == QEvent::GraphicsSceneMousePress) { selection_origin = QPoint(pos.x(), pos.y()); @@ -1398,7 +1397,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i } selection_origin = QPoint(pos.x(), pos.y()); - map->commit(new EventShift(selectedEvents, xDelta, yDelta, actionId)); + map->commit(new EventShift(selectedEvents, xDelta, yDelta, this->eventShiftActionId)); } } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 617fdccc..74f579c9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2609,6 +2609,8 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked() { popup.setupLayoutView(); if (popup.exec() == QDialog::Accepted) { Layout *layout = this->editor->layout; + Map *map = this->editor->map; + QMargins result = popup.getResult(); QSize borderResult = popup.getBorderResult(); QSize oldLayoutDimensions(layout->getWidth(), layout->getHeight()); @@ -2626,6 +2628,15 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked() { oldBorder, layout->border )); } + // If we're in map-editing mode, adjust the events' position by the same amount. + if (map) { + auto events = map->getEvents(); + int deltaX = result.left(); + int deltaY = result.top(); + if ((deltaX || deltaY) && !events.isEmpty()) { + map->commit(new EventShift(events, deltaX, deltaY, this->editor->eventShiftActionId++)); + } + } } }