From 47c70e8b536e00c371cdd0a9d86bf06a8495fbf4 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Mon, 3 Aug 2026 11:15:50 +1200 Subject: [PATCH] Add an adjustable background frame to the element editor Discussion #604. Revives #643, closed on 2026-09-10 only to clear the review backlog, ported onto current master. The element editor shows an infinite grid, with nothing to judge how big a symbol will look on a real folio. Affichage > "Afficher le cadre de fond" draws a dashed blue rectangle centred on the element's origin (the hotspot), sized by default to the drawing area of a default folio (BorderProperties: columns x column width by rows x row height, 1020 x 640). Affichage > "Taille du cadre de fond..." sets another size. Both persist in QSettings (elementeditor/background_frame_*). The frame is drawn in ElementView::drawBackground(), so it is not part of the scene: it is never written to the .elmt file and never in the SVG export (scene render). Changed from #643: resolved against master's new-style connects and the hotspot visibility switch; the toggle gets the unused document-print-frame theme icon (light and dark), without which it showed as a text button in the icon toolbar; the size action is registered with ShortcutManager like the toggle. (cherry picked from commit a245411f9fcf1da2b5fbee9817ca7a6f3b452911) Co-Authored-By: Claude Opus 5.5 --- sources/editor/elementscene.cpp | 44 +++++++++++++++++++++++++ sources/editor/elementscene.h | 7 ++++ sources/editor/elementview.cpp | 13 ++++++++ sources/editor/ui/qetelementeditor.cpp | 45 ++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index c0105ae83..1ae830123 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -18,6 +18,7 @@ #include "elementscene.h" #include "../ElementsCollection/terminaluuids.h" +#include "../borderproperties.h" #include "../NameList/ui/namelistdialog.h" #include "../NameList/ui/namelistwidget.h" #include "../QPropertyUndoCommand/qpropertyundocommand.h" @@ -72,6 +73,49 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : m_decorator_lock = new QMutex(); connect(&m_undo_stack, &QUndoStack::indexChanged, this, &ElementScene::managePrimitivesGroups); connect(this, &ElementScene::selectionChanged, this, &ElementScene::managePrimitivesGroups); + + QSettings settings; + m_background_frame_visible = settings.value( + QStringLiteral("elementeditor/background_frame_visible"), false).toBool(); + BorderProperties bp = BorderProperties::defaultProperties(); + m_background_frame_size = QSizeF( + settings.value(QStringLiteral("elementeditor/background_frame_width"), + bp.columns_count * bp.columns_width).toReal(), + settings.value(QStringLiteral("elementeditor/background_frame_height"), + bp.rows_count * bp.rows_height).toReal()); +} + +/** + @brief ElementScene::setBackgroundFrameVisible + Toggle the visual-only background frame used to proportion this + element's drawing against a representative folio surface. Like the + hotspot indicator, this frame is never written to the saved .elmt file. + @param visible +*/ +void ElementScene::setBackgroundFrameVisible(bool visible) +{ + if (m_background_frame_visible == visible) { + return; + } + m_background_frame_visible = visible; + QSettings().setValue(QStringLiteral("elementeditor/background_frame_visible"), visible); + update(); +} + +/** + @brief ElementScene::setBackgroundFrameSize + @param size the new size (in scene/grid units) of the background frame +*/ +void ElementScene::setBackgroundFrameSize(const QSizeF &size) +{ + if (m_background_frame_size == size) { + return; + } + m_background_frame_size = size; + QSettings settings; + settings.setValue(QStringLiteral("elementeditor/background_frame_width"), size.width()); + settings.setValue(QStringLiteral("elementeditor/background_frame_height"), size.height()); + update(); } /** diff --git a/sources/editor/elementscene.h b/sources/editor/elementscene.h index a53afff6f..e4f086078 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -92,6 +92,8 @@ class ElementScene : public QGraphicsScene QPointer m_single_selected_item; bool m_hotspot_visible = true; + bool m_background_frame_visible = false; + QSizeF m_background_frame_size; // methods public: @@ -142,6 +144,11 @@ class ElementScene : public QGraphicsScene /// not part of the drawn symbol. void setHotspotVisible(bool visible) {m_hotspot_visible = visible;} bool hotspotVisible() const {return m_hotspot_visible;} + + bool backgroundFrameVisible() const {return m_background_frame_visible;} + void setBackgroundFrameVisible(bool visible); + QSizeF backgroundFrameSize() const {return m_background_frame_size;} + void setBackgroundFrameSize(const QSizeF &size); protected: void mouseMoveEvent (QGraphicsSceneMouseEvent *) override; diff --git a/sources/editor/elementview.cpp b/sources/editor/elementview.cpp index c9d254f70..6eed40457 100644 --- a/sources/editor/elementview.cpp +++ b/sources/editor/elementview.cpp @@ -606,6 +606,19 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) { } } } + + if (m_scene->backgroundFrameVisible()) { + const QSizeF frame_size = m_scene->backgroundFrameSize(); + const QRectF frame_rect(-frame_size.width() / 2.0, -frame_size.height() / 2.0, + frame_size.width(), frame_size.height()); + QPen frame_pen(Qt::blue); + frame_pen.setCosmetic(true); + frame_pen.setStyle(Qt::DashLine); + p -> setPen(frame_pen); + p -> setBrush(Qt::NoBrush); + p -> drawRect(frame_rect); + } + p -> restore(); } diff --git a/sources/editor/ui/qetelementeditor.cpp b/sources/editor/ui/qetelementeditor.cpp index 5428ec1b9..8489f8def 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -59,6 +59,10 @@ #include #include #include +#include +#include +#include +#include /** * @brief QETElementEditor::QETElementEditor @@ -1138,6 +1142,47 @@ void QETElementEditor::setupActions() parts_toolbar -> setObjectName("parts"); parts_toolbar -> addActions(m_add_part_action_grp -> actions()); addToolBar(Qt::LeftToolBarArea, parts_toolbar); + + //Background frame action: a visual-only reference rectangle, never + //written to the saved .elmt file, to help proportion the drawing + //against a representative folio surface. + auto *toggle_background_frame_action = new QAction(QET::Icons::DocumentPrintFrame, tr("Afficher le cadre de fond"), this); + toggle_background_frame_action -> setCheckable(true); + toggle_background_frame_action -> setChecked(m_elmt_scene -> backgroundFrameVisible()); + connect(toggle_background_frame_action, &QAction::toggled, m_elmt_scene, &ElementScene::setBackgroundFrameVisible); + ShortcutManager::instance().registerAction(toggle_background_frame_action, "elementeditor.toggle_background_frame", tr("Éditeur d'élément"), QKeySequence()); + ui->m_display_menu->addAction(toggle_background_frame_action); + ui->m_view_toolbar->addAction(toggle_background_frame_action); + + auto *configure_background_frame_action = new QAction(tr("Taille du cadre de fond..."), this); + connect(configure_background_frame_action, &QAction::triggered, this, [this]() { + QDialog dialog(this); + dialog.setWindowTitle(tr("Taille du cadre de fond")); + auto *layout = new QFormLayout(&dialog); + + auto *width_spin = new QDoubleSpinBox(&dialog); + width_spin -> setRange(1.0, 100000.0); + width_spin -> setSuffix(tr(" px")); + width_spin -> setValue(m_elmt_scene -> backgroundFrameSize().width()); + layout -> addRow(tr("Largeur"), width_spin); + + auto *height_spin = new QDoubleSpinBox(&dialog); + height_spin -> setRange(1.0, 100000.0); + height_spin -> setSuffix(tr(" px")); + height_spin -> setValue(m_elmt_scene -> backgroundFrameSize().height()); + layout -> addRow(tr("Hauteur"), height_spin); + + auto *buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, &dialog); + connect(buttons, &QDialogButtonBox::accepted, &dialog, &QDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, &dialog, &QDialog::reject); + layout -> addRow(buttons); + + if (dialog.exec() == QDialog::Accepted) { + m_elmt_scene -> setBackgroundFrameSize(QSizeF(width_spin -> value(), height_spin -> value())); + } + }); + ShortcutManager::instance().registerAction(configure_background_frame_action, "elementeditor.configure_background_frame", tr("Éditeur d'élément"), QKeySequence()); + ui->m_display_menu->addAction(configure_background_frame_action); } /**