From 53706a80d8a13c8bab3361eadd3193228c67fda4 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Sat, 26 Sep 2026 21:17:19 +1200 Subject: [PATCH] Add an option to draw the folio cell limits across the drawing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Affichage › "Afficher les limites des cases" draws a faint dashed line at every column and row limit of the folio border, so that zoomed into the middle of a folio you can see where a cell ends, not only which one the headers name. Off by default, remembered once set (diagrameditor/cell_lines). Drawn by DiagramView::drawBackground(), under every item and only in the view: printing and export render the Diagram, never the view, so they cannot pick the lines up. PaletteGraphicsView gains scenePainter() so a subclass can draw there on the inverted (dark palette) path too. The lines follow the border's own cell positions, and each direction is hidden when the folio hides that header. Co-Authored-By: Claude Opus 5.5 --- sources/diagramview.cpp | 68 +++++++++++++++++++++++++++++++++++ sources/diagramview.h | 7 ++-- sources/palettegraphicsview.h | 5 +++ sources/qetdiagrameditor.cpp | 14 ++++++++ sources/qetdiagrameditor.h | 1 + 5 files changed, 93 insertions(+), 2 deletions(-) diff --git a/sources/diagramview.cpp b/sources/diagramview.cpp index 918b6bbbf..2d44211b5 100644 --- a/sources/diagramview.cpp +++ b/sources/diagramview.cpp @@ -30,6 +30,7 @@ #include "qetgraphicsitem/conductortextitem.h" #include "qetgraphicsitem/independenttextitem.h" #include "qeticons.h" +#include "qetpalette.h" #include "titleblock/integrationmovetemplateshandler.h" #include "ui/diagrampropertiesdialog.h" #include "ui/multipastedialog.h" @@ -112,6 +113,7 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) : m_top_ruler = new CellRuler(Qt::Horizontal, this); m_side_ruler = new CellRuler(Qt::Vertical, this); m_cell_rulers_shown = QSettings().value("diagrameditor/cell_rulers", false).toBool(); + m_cell_lines_shown = QSettings().value("diagrameditor/cell_lines", false).toBool(); connect(&m_diagram->border_and_titleblock, &BorderTitleBlock::borderChanged, this, &DiagramView::updateCellRulers); connect(&m_diagram->border_and_titleblock, &BorderTitleBlock::displayChanged, this, &DiagramView::updateCellRulers); updateCellRulers(); @@ -1196,6 +1198,72 @@ void DiagramView::paintingInverted(bool inverted) m_diagram->setInvertedLightness(inverted); } +/** + @brief DiagramView::setCellLinesShown + Show or hide the lines that mark the columns and the rows of the folio + border across the drawing, in this view only: printing and exporting + never draw them. + @param shown +*/ +void DiagramView::setCellLinesShown(bool shown) +{ + m_cell_lines_shown = shown; + viewport()->update(); +} + +/** + @brief DiagramView::drawBackground + Reimplemented from PaletteGraphicsView: over the folio background, the + cell lines when they are shown. Dashed and faint, so they do not read + as conductors, and under every item. + @param painter + @param rect +*/ +void DiagramView::drawBackground(QPainter *painter, const QRectF &rect) +{ + PaletteGraphicsView::drawBackground(painter, rect); + + const BorderTitleBlock &border = m_diagram->border_and_titleblock; + if (!m_cell_lines_shown || !border.borderIsDisplayed()) { + return; + } + + //Where the border draws its cells, whether or not the other + //header is displayed + const QPointF origin(Diagram::margin + border.rowsHeaderWidth(), + Diagram::margin + border.columnsHeaderHeight()); + const qreal right = origin.x() + border.columnsCount() * border.columnsWidth(); + const qreal bottom = origin.y() + border.rowsCount() * border.rowsHeight(); + + QPainter *p = scenePainter(painter); + p->save(); + p->setRenderHint(QPainter::Antialiasing, false); + QColor color = QET::Palette::gridDotColor(Diagram::background_color, + invertsLightness()); + color.setAlpha(70); + QPen pen(color, 1, Qt::DashLine); + pen.setCosmetic(true); + p->setPen(pen); + + if (border.columnsAreDisplayed()) { + for (int i = 1 ; i < border.columnsCount() ; ++i) { + const qreal x = origin.x() + i * border.columnsWidth(); + if (x >= rect.left() && x <= rect.right()) { + p->drawLine(QPointF(x, origin.y()), QPointF(x, bottom)); + } + } + } + if (border.rowsAreDisplayed()) { + for (int i = 1 ; i < border.rowsCount() ; ++i) { + const qreal y = origin.y() + i * border.rowsHeight(); + if (y >= rect.top() && y <= rect.bottom()) { + p->drawLine(QPointF(origin.x(), y), QPointF(right, y)); + } + } + } + p->restore(); +} + /** @brief DiagramView::setCellRulersShown Show or hide the rulers that keep the column numbers and the row diff --git a/sources/diagramview.h b/sources/diagramview.h index 9550e4898..f2abdd505 100644 --- a/sources/diagramview.h +++ b/sources/diagramview.h @@ -68,7 +68,8 @@ class DiagramView : public PaletteGraphicsView bool m_cell_rulers_shown = false; /// Last viewport transform the rulers were painted for QTransform m_rulers_transform; - + bool m_cell_lines_shown = false; + public: QString title() const; @@ -85,7 +86,8 @@ class DiagramView : public PaletteGraphicsView /// several window managers and compositors, Wayland included). QPoint lastMousePos() const { return m_last_mouse_pos; } void setCellRulersShown(bool shown); - + void setCellLinesShown(bool shown); + protected: void mouseDoubleClickEvent(QMouseEvent *) override; void contextMenuEvent(QContextMenuEvent *) override; @@ -99,6 +101,7 @@ class DiagramView : public PaletteGraphicsView bool m_releasing_focus = false; void paintEvent(QPaintEvent *event) override; bool viewportEvent(QEvent *event) override; + void drawBackground(QPainter *painter, const QRectF &rect) override; void paintingInverted(bool inverted) override; void mousePressEvent(QMouseEvent *) override; void mouseMoveEvent(QMouseEvent *) override; diff --git a/sources/palettegraphicsview.h b/sources/palettegraphicsview.h index 080897545..96d2ace36 100644 --- a/sources/palettegraphicsview.h +++ b/sources/palettegraphicsview.h @@ -80,6 +80,11 @@ class PaletteGraphicsView : public QGraphicsView nothing by default. */ virtual void paintingInverted(bool inverted); + /// @return the painter the scene really paints with: the + /// off-screen image's while painting inverted, else \a painter. + /// For subclasses that draw more in drawBackground(). + QPainter *scenePainter(QPainter *painter) + { return m_inverting ? &m_buffer_painter : painter; } private: void paintInverted(QPaintEvent *event); diff --git a/sources/qetdiagrameditor.cpp b/sources/qetdiagrameditor.cpp index c97613ba7..852ea9612 100644 --- a/sources/qetdiagrameditor.cpp +++ b/sources/qetdiagrameditor.cpp @@ -534,6 +534,18 @@ void QETDiagramEditor::setUpActions() dv->setCellRulersShown(checked); }); + //Draw the limits of the folio columns and rows across the drawing + m_cell_lines = new QAction(tr("Afficher les limites des cases"), this); + m_cell_lines->setStatusTip(tr("Trace les limites des colonnes et des lignes du folio sur le schéma, à l'écran seulement")); + m_cell_lines->setCheckable(true); + m_cell_lines->setChecked(settings.value("diagrameditor/cell_lines", false).toBool()); + connect(m_cell_lines, &QAction::triggered, [this](bool checked) { + QSettings().setValue("diagrameditor/cell_lines", checked); + foreach (ProjectView *prjv, this->openedProjects()) + foreach (DiagramView *dv, prjv->diagram_views()) + dv->setCellLinesShown(checked); + }); + //Edit current diagram properties m_edit_diagram_properties = new QAction(QET::Icons::DialogInformation, tr("Propriétés du folio"), this); ShortcutManager::instance().registerAction(m_edit_diagram_properties, "diagrameditor.edit_diagram_properties", tr("Éditeur de schémas"), Qt::CTRL | Qt::Key_L); @@ -1160,6 +1172,7 @@ void QETDiagramEditor::setUpMenu() menu_affichage -> addMenu(m_text_grid_menu); menu_affichage -> addAction(m_draw_guides); menu_affichage -> addAction(m_cell_rulers); + menu_affichage -> addAction(m_cell_lines); menu_affichage -> addMenu(m_background_color_button->menu()); menu_affichage -> addSeparator(); menu_affichage -> addActions(m_zoom_actions_group.actions()); @@ -1992,6 +2005,7 @@ void QETDiagramEditor::slot_updateActions() m_draw_grid-> setEnabled(opened_diagram); m_draw_guides-> setEnabled(opened_diagram); m_cell_rulers-> setEnabled(opened_diagram); + m_cell_lines-> setEnabled(opened_diagram); //Project menu m_project_edit_properties -> setEnabled(opened_project); diff --git a/sources/qetdiagrameditor.h b/sources/qetdiagrameditor.h index c0bece505..2907f7484 100644 --- a/sources/qetdiagrameditor.h +++ b/sources/qetdiagrameditor.h @@ -213,6 +213,7 @@ class QETDiagramEditor : public QETMainWindow *m_draw_grid, ///< Switch the background grid display or not *m_draw_guides = nullptr, ///< Switch the custom guides display or not *m_cell_rulers = nullptr, ///< Keep the folio column/row headers in sight or not + *m_cell_lines = nullptr, ///< Draw the folio column/row limits across the drawing or not *m_project_edit_properties, ///< Edit the properties of the current project. *m_project_add_diagram, ///< Add a diagram to the current project. *m_remove_diagram_from_project, ///< Delete a diagram from the current project