Add a "Centre on cursor" view command

Scrolls the folio so the point under the mouse becomes the centre of the
view, keeping the current zoom. Requested on the forum (topic 3199) for
moving around a zoomed-in folio the way KiCad and EasyEDA allow;
"Zoom sur le contenu" (Ctrl+8) was the closest existing command, but it
also refits the zoom.

The command is in the Affichage menu and in the shortcut editor. It has
no default key: F4 and the single letters are already taken or would
clash with typing. It does nothing when the cursor is not over the view,
so choosing it from the menu is harmless. Near the folio border the view
cannot scroll past the edge, so the point ends up as close to the centre
as the scroll bars allow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-01 10:29:28 +13:00
parent ee781f8dc3
commit 2580163e33
3 changed files with 23 additions and 0 deletions
+16
View File
@@ -509,6 +509,22 @@ void DiagramView::zoomToRect(const QRectF &rect)
adjustGridToZoom();
}
/**
@brief DiagramView::centerOnCursor
Scroll the view so the point under the mouse cursor becomes the centre
of the view, keeping the current zoom.
Does nothing when the cursor is not over the view, e.g. when the action
is triggered from a menu.
*/
void DiagramView::centerOnCursor()
{
const QPoint local = viewport()->mapFromGlobal(QCursor::pos());
if (!viewport()->rect().contains(local)) {
return;
}
centerOn(mapToScene(local));
}
/**
Copie les elements selectionnes du schema dans le presse-papier puis les supprime
Copies the selected elements from the diagram to the clipboard and then deletes them