Fix regression for dragging multiple events
This commit is contained in:
parent
1a456bc47b
commit
0b4f02779b
6 changed files with 60 additions and 41 deletions
|
@ -95,8 +95,7 @@ public:
|
||||||
Tileset *getCurrentMapPrimaryTileset();
|
Tileset *getCurrentMapPrimaryTileset();
|
||||||
|
|
||||||
DraggablePixmapItem *addMapEvent(Event *event);
|
DraggablePixmapItem *addMapEvent(Event *event);
|
||||||
void selectMapEvent(DraggablePixmapItem *object);
|
void selectMapEvent(DraggablePixmapItem *object, bool toggle = false);
|
||||||
void selectMapEvent(DraggablePixmapItem *object, bool toggle);
|
|
||||||
DraggablePixmapItem *addNewEvent(Event::Type type);
|
DraggablePixmapItem *addNewEvent(Event::Type type);
|
||||||
void updateSelectedEvents();
|
void updateSelectedEvents();
|
||||||
void duplicateSelectedEvents();
|
void duplicateSelectedEvents();
|
||||||
|
|
|
@ -24,13 +24,7 @@ public:
|
||||||
updatePosition();
|
updatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor *editor = nullptr;
|
|
||||||
Event *event = nullptr;
|
Event *event = nullptr;
|
||||||
QGraphicsItemAnimation *pos_anim = nullptr;
|
|
||||||
|
|
||||||
bool active;
|
|
||||||
int last_x;
|
|
||||||
int last_y;
|
|
||||||
|
|
||||||
void updatePosition();
|
void updatePosition();
|
||||||
void move(int dx, int dy);
|
void move(int dx, int dy);
|
||||||
|
@ -38,6 +32,12 @@ public:
|
||||||
void emitPositionChanged();
|
void emitPositionChanged();
|
||||||
void updatePixmap();
|
void updatePixmap();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Editor *editor = nullptr;
|
||||||
|
QPoint lastPos;
|
||||||
|
bool active = false;
|
||||||
|
bool releaseSelectionQueued = false;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void positionChanged(Event *event);
|
void positionChanged(Event *event);
|
||||||
void xChanged(int);
|
void xChanged(int);
|
||||||
|
|
|
@ -331,7 +331,7 @@ void EventCreate::redo() {
|
||||||
|
|
||||||
// select this event
|
// select this event
|
||||||
editor->selected_events->clear();
|
editor->selected_events->clear();
|
||||||
editor->selectMapEvent(event->getPixmapItem(), false);
|
editor->selectMapEvent(event->getPixmapItem());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventCreate::undo() {
|
void EventCreate::undo() {
|
||||||
|
|
|
@ -1358,7 +1358,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
||||||
if (newEvent) {
|
if (newEvent) {
|
||||||
newEvent->move(pos.x(), pos.y());
|
newEvent->move(pos.x(), pos.y());
|
||||||
emit objectsChanged();
|
emit objectsChanged();
|
||||||
selectMapEvent(newEvent, false);
|
selectMapEvent(newEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1994,10 +1994,6 @@ void Editor::updateSelectedEvents() {
|
||||||
emit objectsChanged();
|
emit objectsChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::selectMapEvent(DraggablePixmapItem *object) {
|
|
||||||
selectMapEvent(object, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
|
void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
|
||||||
if (!selected_events || !object)
|
if (!selected_events || !object)
|
||||||
return;
|
return;
|
||||||
|
@ -2228,10 +2224,8 @@ void Editor::objectsView_onMousePress(QMouseEvent *event) {
|
||||||
|
|
||||||
bool multiSelect = event->modifiers() & Qt::ControlModifier;
|
bool multiSelect = event->modifiers() & Qt::ControlModifier;
|
||||||
if (!selectingEvent && !multiSelect && selected_events->length() > 1) {
|
if (!selectingEvent && !multiSelect && selected_events->length() > 1) {
|
||||||
DraggablePixmapItem *first = selected_events->first();
|
// User is clearing group selection by clicking on the background
|
||||||
selected_events->clear();
|
this->selectMapEvent(selected_events->first());
|
||||||
selected_events->append(first);
|
|
||||||
updateSelectedEvents();
|
|
||||||
}
|
}
|
||||||
selectingEvent = false;
|
selectingEvent = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2014,7 +2014,7 @@ void MainWindow::addNewEvent(Event::Type type) {
|
||||||
auto centerPos = ui->graphicsView_Map->mapToScene(halfSize.width(), halfSize.height());
|
auto centerPos = ui->graphicsView_Map->mapToScene(halfSize.width(), halfSize.height());
|
||||||
object->moveTo(Metatile::coordFromPixmapCoord(centerPos));
|
object->moveTo(Metatile::coordFromPixmapCoord(centerPos));
|
||||||
updateObjects();
|
updateObjects();
|
||||||
editor->selectMapEvent(object, false);
|
editor->selectMapEvent(object);
|
||||||
} else {
|
} else {
|
||||||
QMessageBox msgBox(this);
|
QMessageBox msgBox(this);
|
||||||
msgBox.setText("Failed to add new event");
|
msgBox.setText("Failed to add new event");
|
||||||
|
|
|
@ -34,11 +34,26 @@ void DraggablePixmapItem::updatePixmap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
active = true;
|
if (this->active)
|
||||||
QPoint pos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
return;
|
||||||
last_x = pos.x();
|
this->active = true;
|
||||||
last_y = pos.y();
|
this->lastPos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
||||||
this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
|
|
||||||
|
bool selectionToggle = mouse->modifiers() & Qt::ControlModifier;
|
||||||
|
if (selectionToggle || !editor->selected_events->contains(this)) {
|
||||||
|
// User is either toggling this selection on/off as part of a group selection,
|
||||||
|
// or they're newly selecting just this item.
|
||||||
|
this->editor->selectMapEvent(this, selectionToggle);
|
||||||
|
} else {
|
||||||
|
// This item is already selected and the user isn't toggling the selection, so there are 4 possibilities:
|
||||||
|
// 1. This is the only selected event, and the selection is pointless.
|
||||||
|
// 2. This is the only selected event, and they want to drag the item around.
|
||||||
|
// 3. There's a group selection, and they want to start a new selection with just this item.
|
||||||
|
// 4. There's a group selection, and they want to drag the group around.
|
||||||
|
// 'selectMapEvent' will immediately clear the rest of the selection, which supports #1-3 but prevents #4.
|
||||||
|
// To support #4 we set the flag below, and we only call 'selectMapEvent' on mouse release if no move occurred.
|
||||||
|
this->releaseSelectionQueued = true;
|
||||||
|
}
|
||||||
this->editor->selectingEvent = true;
|
this->editor->selectingEvent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,10 +72,17 @@ void DraggablePixmapItem::moveTo(const QPoint &pos) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
if (active) {
|
if (!this->active)
|
||||||
|
return;
|
||||||
|
|
||||||
QPoint pos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
QPoint pos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
||||||
if (pos.x() != last_x || pos.y() != last_y) {
|
if (pos == this->lastPos)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QPoint moveDistance = pos - this->lastPos;
|
||||||
|
this->lastPos = pos;
|
||||||
emit this->editor->map_item->hoveredMapMetatileChanged(pos);
|
emit this->editor->map_item->hoveredMapMetatileChanged(pos);
|
||||||
|
|
||||||
QList <Event *> selectedEvents;
|
QList <Event *> selectedEvents;
|
||||||
if (editor->selected_events->contains(this)) {
|
if (editor->selected_events->contains(this)) {
|
||||||
for (DraggablePixmapItem *item : *editor->selected_events) {
|
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||||
|
@ -69,16 +91,20 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
} else {
|
} else {
|
||||||
selectedEvents.append(this->event);
|
selectedEvents.append(this->event);
|
||||||
}
|
}
|
||||||
editor->map->editHistory.push(new EventMove(selectedEvents, pos.x() - last_x, pos.y() - last_y, currentActionId));
|
editor->map->editHistory.push(new EventMove(selectedEvents, moveDistance.x(), moveDistance.y(), currentActionId));
|
||||||
last_x = pos.x();
|
this->releaseSelectionQueued = false;
|
||||||
last_y = pos.y();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
|
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||||
active = false;
|
if (!this->active)
|
||||||
|
return;
|
||||||
|
this->active = false;
|
||||||
currentActionId++;
|
currentActionId++;
|
||||||
|
if (this->releaseSelectionQueued) {
|
||||||
|
this->releaseSelectionQueued = false;
|
||||||
|
if (Metatile::coordFromPixmapCoord(mouse->scenePos()) == this->lastPos)
|
||||||
|
this->editor->selectMapEvent(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
|
void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
|
||||||
|
|
Loading…
Reference in a new issue