From a245411f9fcf1da2b5fbee9817ca7a6f3b452911 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Mon, 3 Aug 2026 11:15:50 +1200 Subject: [PATCH] Add adjustable background frame to the element editor Adds a toggleable, visual-only background frame to help proportion an element's drawing against a representative folio surface, instead of guessing against a bare grid. Follows the exact precedent of the existing hotspot indicator (ElementScene::drawForeground()): drawn by ElementView::drawBackground(), centered on the same origin, and never written to the saved .elmt file. - "Afficher le cadre de fond" toggles the frame on/off. - "Taille du cadre de fond..." opens a small width/height dialog to resize it, defaulting to a representative folio's drawable area derived from BorderProperties::defaultProperties() (columns_count * columns_width by rows_count * rows_height). - Both the visibility and the last-used size persist via QSettings, the same way the existing grid-dot rendering prefs (elementeditor/grid_pointsize_min/max) already do. Implements the scope proposed in discussion #604. --- sources/editor/elementscene.cpp | 44 ++++++++++++++++++++++++++ sources/editor/elementscene.h | 8 +++++ sources/editor/elementview.cpp | 13 ++++++++ sources/editor/ui/qetelementeditor.cpp | 44 ++++++++++++++++++++++++++ 4 files changed, 109 insertions(+) diff --git a/sources/editor/elementscene.cpp b/sources/editor/elementscene.cpp index 393d280b9..072ef6c5b 100644 --- a/sources/editor/elementscene.cpp +++ b/sources/editor/elementscene.cpp @@ -17,6 +17,7 @@ */ #include "elementscene.h" +#include "../borderproperties.h" #include "../NameList/ui/namelistdialog.h" #include "../NameList/ui/namelistwidget.h" #include "../QPropertyUndoCommand/qpropertyundocommand.h" @@ -73,6 +74,49 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) : this, SLOT(managePrimitivesGroups())); connect(this, SIGNAL(selectionChanged()), this, SLOT(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 97ec4812a..5059f778f 100644 --- a/sources/editor/elementscene.h +++ b/sources/editor/elementscene.h @@ -90,6 +90,9 @@ class ElementScene : public QGraphicsScene m_y_grid; QPointer m_single_selected_item; + + bool m_background_frame_visible = false; + QSizeF m_background_frame_size; // methods public: @@ -132,6 +135,11 @@ class ElementScene : public QGraphicsScene QETElementEditor* editor() const; void addItems(QVector items); void removeItems(QVector items); + + 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 a2cc8af58..0b1332c18 100644 --- a/sources/editor/elementview.cpp +++ b/sources/editor/elementview.cpp @@ -598,6 +598,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 ba8d80f19..c8e311085 100644 --- a/sources/editor/ui/qetelementeditor.cpp +++ b/sources/editor/ui/qetelementeditor.cpp @@ -53,6 +53,10 @@ #include #include +#include +#include +#include +#include /** * @brief QETElementEditor::QETElementEditor @@ -1076,6 +1080,46 @@ 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(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())); + } + }); + ui->m_display_menu->addAction(configure_background_frame_action); } /**