Shift events if map moves when resized

This commit is contained in:
GriffinR
2025-02-07 14:50:00 -05:00
parent ac6750de44
commit df861b59ad
3 changed files with 15 additions and 3 deletions

View File

@@ -180,6 +180,8 @@ public:
qreal collisionOpacity = 0.5;
static QList<QList<const QImage*>> collisionIcons;
int eventShiftActionId = 0;
void objectsView_onMousePress(QMouseEvent *event);
int getBorderDrawDistance(int dimension);

View File

@@ -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));
}
}
}

View File

@@ -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++));
}
}
}
}