From 2580163e337358244ddf4bf6e850519b5fb7a445 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Thu, 1 Oct 2026 10:29:28 +1300 Subject: [PATCH] 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 --- sources/diagramview.cpp | 16 ++++++++++++++++ sources/diagramview.h | 1 + sources/qetdiagrameditor.cpp | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 044a24759..0b63fd105 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -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 diff --git a/sources/diagramview.h b/sources/diagramview.h index 11f53ddf2..ebf3fd1f8 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -185,6 +185,7 @@ class DiagramView : public PaletteGraphicsView void zoomContent(); void zoomReset(); void zoomToRect(const QRectF &rect); + void centerOnCursor(); void cut(); void copy(); void paste(const QPointF & = QPointF(), QClipboard::Mode = QClipboard::Clipboard); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index f826bbc52..2282dd859 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -1000,6 +1000,7 @@ void QETDiagramEditor::setUpActions() QAction *zoom_content = m_zoom_actions_group.addAction( QET::Icons::ZoomDraw, tr("Zoom sur le contenu")); QAction *zoom_fit = m_zoom_actions_group.addAction( QET::Icons::ZoomFitBest, tr("Zoom adapté")); QAction *zoom_reset = m_zoom_actions_group.addAction( QET::Icons::ZoomOriginal, tr("Pas de zoom")); + QAction *center_on_cursor = m_zoom_actions_group.addAction(tr("Centrer sur le curseur")); m_zoom_action_toolBar << zoom_content << zoom_fit << zoom_reset; ShortcutManager::instance().registerAction(zoom_in, "diagrameditor.zoom_in", tr("Éditeur de schémas"), QKeySequence::ZoomIn); @@ -1007,18 +1008,21 @@ void QETDiagramEditor::setUpActions() ShortcutManager::instance().registerAction(zoom_content, "diagrameditor.zoom_content", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_8); ShortcutManager::instance().registerAction(zoom_fit, "diagrameditor.zoom_fit", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_9); ShortcutManager::instance().registerAction(zoom_reset, "diagrameditor.zoom_reset", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_0); + ShortcutManager::instance().registerAction(center_on_cursor, "diagrameditor.center_on_cursor", tr("Éditeur de schémas"), QKeySequence()); zoom_in ->setStatusTip(tr("Agrandit le folio", "status bar tip")); zoom_out ->setStatusTip(tr("Rétrécit le folio", "status bar tip")); zoom_content->setStatusTip(tr("Adapte le zoom de façon à afficher tout le contenu du folio indépendamment du cadre")); zoom_fit ->setStatusTip(tr("Adapte le zoom exactement sur le cadre du folio", "status bar tip")); zoom_reset ->setStatusTip(tr("Restaure le zoom par défaut", "status bar tip")); + center_on_cursor->setStatusTip(tr("Centre le folio sur le point sous le curseur de la souris, sans changer le zoom", "status bar tip")); zoom_in ->setData("zoom_in"); zoom_out ->setData("zoom_out"); zoom_content->setData("zoom_content"); zoom_fit ->setData("zoom_fit"); zoom_reset ->setData("zoom_reset"); + center_on_cursor->setData("center_on_cursor"); connect(&m_zoom_actions_group, &QActionGroup::triggered, this, &QETDiagramEditor::zoomGroupTriggered); @@ -1944,6 +1948,8 @@ void QETDiagramEditor::zoomGroupTriggered(QAction *action) dv->zoomFit(); else if (value == "zoom_reset") dv->zoomReset(); + else if (value == "center_on_cursor") + dv->centerOnCursor(); } /**