diff --git a/sources/diagram.h b/sources/diagram.h index d2e0f0e12..aa9cb1d9f 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -216,6 +216,7 @@ class Diagram : public QGraphicsScene // methods related to graphics items addition/removal on the diagram virtual void addItem (QGraphicsItem *item); virtual void removeItem (QGraphicsItem *item); + bool hasEventInterface() const { return m_event_interface != nullptr; } // methods related to graphics options ExportProperties applyProperties(const ExportProperties &); diff --git a/sources/diagramevent/diagrameventaddpaste.cpp b/sources/diagramevent/diagrameventaddpaste.cpp index b08406b68..d9be0f159 100644 --- a/sources/diagramevent/diagrameventaddpaste.cpp +++ b/sources/diagramevent/diagrameventaddpaste.cpp @@ -87,12 +87,12 @@ DiagramEventAddPaste::DiagramEventAddPaste(Diagram *diagram, const QPointF &star */ DiagramEventAddPaste::~DiagramEventAddPaste() { - if (!m_finished && m_diagram) { - cancel(); - } - if (m_status_bar) { - m_status_bar->clearMessage(); + if (!m_finished) { + removeItems(); + m_finished = true; + m_running = false; } + if (m_status_bar) m_status_bar->clearMessage(); } /** @@ -139,6 +139,10 @@ void DiagramEventAddPaste::moveTo(const QPointF &scene_pos) it.key()->setPos(anchor + it.value()); } } + const auto conductors = m_content.conductors(); // AnyConductor by default + for (auto *cond : conductors) { + cond->updatePath(); + } } void DiagramEventAddPaste::mouseMoveEvent(QGraphicsSceneMouseEvent *event) @@ -216,13 +220,14 @@ void DiagramEventAddPaste::commit() void DiagramEventAddPaste::cancel() { if (m_finished || !m_diagram) return; + removeItems(); m_finished = true; m_running = false; + emit finish(); // only the user-driven path signals +} - //Conductors first: they hold pointers to the terminals of the - //elements below, so removing an element out from under one would - //leave it pointing at freed memory for as long as it is still in the - //scene. +void DiagramEventAddPaste::removeItems() +{ const QList conductors = m_content.conductors(DiagramContent::AnyConductor); for (auto *conductor : conductors) { m_diagram->removeItem(conductor); @@ -237,5 +242,4 @@ void DiagramEventAddPaste::cancel() m_content.clear(); m_relative_pos.clear(); - emit finish(); } diff --git a/sources/diagramevent/diagrameventaddpaste.h b/sources/diagramevent/diagrameventaddpaste.h index a200ca04d..8c7bcf86f 100644 --- a/sources/diagramevent/diagrameventaddpaste.h +++ b/sources/diagramevent/diagrameventaddpaste.h @@ -73,6 +73,7 @@ class DiagramEventAddPaste : public DiagramEventInterface void commit(); void cancel(); void showHint(); + void removeItems(); DiagramContent m_content; ///Each movable item's position relative to the group's top left, diff --git a/sources/diagramevent/diagrameventaddshape.cpp b/sources/diagramevent/diagrameventaddshape.cpp index d19669e76..9795d86f8 100644 --- a/sources/diagramevent/diagrameventaddshape.cpp +++ b/sources/diagramevent/diagrameventaddshape.cpp @@ -317,10 +317,16 @@ void DiagramEventAddShape::mouseMoveEvent(QGraphicsSceneMouseEvent *event) did anything. Re-running the last known mouse position through applyPosition() here makes the key press or release itself the trigger, giving immediate feedback instead of waiting on chance. + Any other key falls back to standard handling, e.g. pressing ESC aborts the operation. */ void DiagramEventAddShape::keyPressEvent(QKeyEvent *event) { - reapplyLastPosition(event); + if (event->key() == Qt::Key_Shift || event->key() == Qt::Key_Control) { + reapplyLastPosition(event); + event->setAccepted(true); + } else { + DiagramEventInterface::keyPressEvent(event); + } } void DiagramEventAddShape::keyReleaseEvent(QKeyEvent *event) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index e16a02840..3d2a6d340 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -733,6 +733,10 @@ void DiagramView::keyPressEvent(QKeyEvent *e) //way off the canvas for someone working without a mouse. //Escape steps back out: first it drops the selection, then it //hands focus to the next widget. + if (m_diagram && m_diagram->hasEventInterface()) { + QGraphicsView::keyPressEvent(e); // let the active tool see it + return; + } if (m_diagram && !m_diagram->selectedItems().isEmpty()) { m_diagram->clearSelection(); } else { diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index c9f4c868e..247d889ad 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1754,6 +1754,10 @@ void QETDiagramEditor::addItemGroupTriggered(QAction *action) // here makes the button's appearance match its actual state // regardless of whether Qt's own change notification fired // correctly. + + if (DiagramView *dv = currentDiagramView()) + dv->setFocus(); // so the view (and the active tool) actually receives Escape etc + if (QWidget *button = m_add_item_tool_bar->widgetForAction(action)) button->update(); }