Place a template under the cursor, and list it as soon as it is saved

A template (.qetmak) was previewed and placed offset from the cursor by
the position its items had on the folio it was saved from: the preview
pixmap kept that offset, and addMacro() added it back before handing the
position to fromXml(). A template saved from the middle or the lower
right of a folio therefore landed far below and to the right of the
click, often off the folio, which reads as "the template does not drop"
(forum topic 3190). Anchor both the preview and the placement on the
template's own top-left corner instead.

fromXml() skips translating for a null position, so a click on the folio
origin is nudged by a fraction of a pixel that the grid snap removes.

Also:
- a template saved with "Create a template" only appeared in the
  templates tab after reloading the collections or restarting; it is
  now added to the tab of every open editor when it is saved;
- the placement status bar message ended in an untranslated
  "(Makro-Anker)"; it now reads "x : y" like element placement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-09-30 13:47:45 +13:00
parent 63196bf4ac
commit cb5247e07c
6 changed files with 44 additions and 3 deletions
+15 -3
View File
@@ -88,7 +88,12 @@ m_preview_item(nullptr)
dummy_diagram->render(&painter, QRectF(QPointF(0,0), scene_rect.size()), scene_rect);
m_preview_item = new QGraphicsPixmapItem(pixmap);
m_preview_item->setOffset(scene_rect.topLeft());
// Anchor the preview on the template's own top-left
// corner, where addMacro() puts it, not on the origin of
// the folio it was saved from: a template saved from the
// middle of a folio was otherwise shown, and placed, that
// far below and to the right of the cursor.
m_preview_item->setOffset(scene_rect.topLeft() - m_items_top_left);
}
}
@@ -134,7 +139,7 @@ void DiagramEventAddMacro::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
m_preview_item->setPos(pos_);
if (m_status_bar) {
m_status_bar->showMessage(QString("x %1 : y %2 (Makro-Anker)").arg(QString::number(pos_.x()), QString::number(pos_.y())));
m_status_bar->showMessage(QString("x %1 : y %2").arg(QString::number(pos_.x()), QString::number(pos_.y())));
}
}
event->setAccepted(true);
@@ -255,7 +260,14 @@ void DiagramEventAddMacro::addMacro(QPointF final_pos)
QDomElement cloned_node = diagram_node.cloneNode(true).toElement();
DiagramContent pasted_content;
m_diagram->fromXml(cloned_node, final_pos + m_items_top_left, false, &pasted_content);
// fromXml() puts the template's top-left corner on final_pos,
// under the cursor. It skips that for a null position, which
// would leave the items where they were saved, so a click on
// the folio origin is nudged by less than it snaps away.
if (final_pos.isNull()) {
final_pos = QPointF(0.1, 0.1);
}
m_diagram->fromXml(cloned_node, final_pos, false, &pasted_content);
m_diagram->refreshContents();
// Prevent PasteDiagramCommand from erasing labels (BMK)