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();
|
||||
|
||||
DraggablePixmapItem *addMapEvent(Event *event);
|
||||
void selectMapEvent(DraggablePixmapItem *object);
|
||||
void selectMapEvent(DraggablePixmapItem *object, bool toggle);
|
||||
void selectMapEvent(DraggablePixmapItem *object, bool toggle = false);
|
||||
DraggablePixmapItem *addNewEvent(Event::Type type);
|
||||
void updateSelectedEvents();
|
||||
void duplicateSelectedEvents();
|
||||
|
|
|
@ -24,13 +24,7 @@ public:
|
|||
updatePosition();
|
||||
}
|
||||
|
||||
Editor *editor = nullptr;
|
||||
Event *event = nullptr;
|
||||
QGraphicsItemAnimation *pos_anim = nullptr;
|
||||
|
||||
bool active;
|
||||
int last_x;
|
||||
int last_y;
|
||||
|
||||
void updatePosition();
|
||||
void move(int dx, int dy);
|
||||
|
@ -38,6 +32,12 @@ public:
|
|||
void emitPositionChanged();
|
||||
void updatePixmap();
|
||||
|
||||
private:
|
||||
Editor *editor = nullptr;
|
||||
QPoint lastPos;
|
||||
bool active = false;
|
||||
bool releaseSelectionQueued = false;
|
||||
|
||||
signals:
|
||||
void positionChanged(Event *event);
|
||||
void xChanged(int);
|
||||
|
|
|
@ -331,7 +331,7 @@ void EventCreate::redo() {
|
|||
|
||||
// select this event
|
||||
editor->selected_events->clear();
|
||||
editor->selectMapEvent(event->getPixmapItem(), false);
|
||||
editor->selectMapEvent(event->getPixmapItem());
|
||||
}
|
||||
|
||||
void EventCreate::undo() {
|
||||
|
|
|
@ -1358,7 +1358,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
if (newEvent) {
|
||||
newEvent->move(pos.x(), pos.y());
|
||||
emit objectsChanged();
|
||||
selectMapEvent(newEvent, false);
|
||||
selectMapEvent(newEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1994,10 +1994,6 @@ void Editor::updateSelectedEvents() {
|
|||
emit objectsChanged();
|
||||
}
|
||||
|
||||
void Editor::selectMapEvent(DraggablePixmapItem *object) {
|
||||
selectMapEvent(object, false);
|
||||
}
|
||||
|
||||
void Editor::selectMapEvent(DraggablePixmapItem *object, bool toggle) {
|
||||
if (!selected_events || !object)
|
||||
return;
|
||||
|
@ -2228,10 +2224,8 @@ void Editor::objectsView_onMousePress(QMouseEvent *event) {
|
|||
|
||||
bool multiSelect = event->modifiers() & Qt::ControlModifier;
|
||||
if (!selectingEvent && !multiSelect && selected_events->length() > 1) {
|
||||
DraggablePixmapItem *first = selected_events->first();
|
||||
selected_events->clear();
|
||||
selected_events->append(first);
|
||||
updateSelectedEvents();
|
||||
// User is clearing group selection by clicking on the background
|
||||
this->selectMapEvent(selected_events->first());
|
||||
}
|
||||
selectingEvent = false;
|
||||
}
|
||||
|
|
|
@ -2014,7 +2014,7 @@ void MainWindow::addNewEvent(Event::Type type) {
|
|||
auto centerPos = ui->graphicsView_Map->mapToScene(halfSize.width(), halfSize.height());
|
||||
object->moveTo(Metatile::coordFromPixmapCoord(centerPos));
|
||||
updateObjects();
|
||||
editor->selectMapEvent(object, false);
|
||||
editor->selectMapEvent(object);
|
||||
} else {
|
||||
QMessageBox msgBox(this);
|
||||
msgBox.setText("Failed to add new event");
|
||||
|
|
|
@ -34,11 +34,26 @@ void DraggablePixmapItem::updatePixmap() {
|
|||
}
|
||||
|
||||
void DraggablePixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||
active = true;
|
||||
QPoint pos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
||||
last_x = pos.x();
|
||||
last_y = pos.y();
|
||||
this->editor->selectMapEvent(this, mouse->modifiers() & Qt::ControlModifier);
|
||||
if (this->active)
|
||||
return;
|
||||
this->active = true;
|
||||
this->lastPos = Metatile::coordFromPixmapCoord(mouse->scenePos());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -57,10 +72,17 @@ void DraggablePixmapItem::moveTo(const QPoint &pos) {
|
|||
}
|
||||
|
||||
void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||
if (active) {
|
||||
if (!this->active)
|
||||
return;
|
||||
|
||||
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);
|
||||
|
||||
QList <Event *> selectedEvents;
|
||||
if (editor->selected_events->contains(this)) {
|
||||
for (DraggablePixmapItem *item : *editor->selected_events) {
|
||||
|
@ -69,16 +91,20 @@ void DraggablePixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *mouse) {
|
|||
} else {
|
||||
selectedEvents.append(this->event);
|
||||
}
|
||||
editor->map->editHistory.push(new EventMove(selectedEvents, pos.x() - last_x, pos.y() - last_y, currentActionId));
|
||||
last_x = pos.x();
|
||||
last_y = pos.y();
|
||||
}
|
||||
}
|
||||
editor->map->editHistory.push(new EventMove(selectedEvents, moveDistance.x(), moveDistance.y(), currentActionId));
|
||||
this->releaseSelectionQueued = false;
|
||||
}
|
||||
|
||||
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *) {
|
||||
active = false;
|
||||
void DraggablePixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouse) {
|
||||
if (!this->active)
|
||||
return;
|
||||
this->active = false;
|
||||
currentActionId++;
|
||||
if (this->releaseSelectionQueued) {
|
||||
this->releaseSelectionQueued = false;
|
||||
if (Metatile::coordFromPixmapCoord(mouse->scenePos()) == this->lastPos)
|
||||
this->editor->selectMapEvent(this);
|
||||
}
|
||||
}
|
||||
|
||||
void DraggablePixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
|
||||
|
|
Loading…
Reference in a new issue