Add an option to keep the folio row and column headers visible (#1034)

Affichage > "Garder les en-têtes visibles" adds a bar along the top and
the left of the diagram view that repeats the folio's column numbers and
row letters, aligned with the cells at any zoom, so they stay in sight
when the folio's own headers are scrolled away. Off by default; the
choice is stored as diagrameditor/cell_rulers.

The bars are CellRuler widgets in the view's margins
(setViewportMargins), not scene items, so printing and PDF/PNG/DXF
export never see them, and they paint with the application palette
outside of the dark-palette inversion. They keep a constant thickness;
when cells get narrower than their labels, only every 2nd, 5th, 10th...
label is written. A bar is hidden when the folio hides that header.
Showing or hiding them keeps the centre of the view where it was.

The labels come from BorderCellLabels, now also used by
BorderTitleBlock::draw(), so the bars and the border cannot disagree.
PNG export of all 133 folios of the examples is pixel-identical to
master, with border-columns_0 true and false.

Known limits: changing border-columns_0 repaints the bars at the next
scroll or zoom; the menu toggle updates the views of its own editor
window only, like the grid toggle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2d2Zi8BfrYRPX88zhaoFG
This commit is contained in:
ispyisail
2026-09-26 08:22:12 +12:00
parent 5f0b015186
commit 9738345b45
11 changed files with 460 additions and 11 deletions
+91
View File
@@ -16,6 +16,7 @@
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
*/
#include "diagramview.h"
#include "cellruler.h"
#include "lastusedstyle.h"
#include "qetproject.h"
#include "QPropertyUndoCommand/qpropertyundocommand.h"
@@ -107,6 +108,13 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
connect(&(m_diagram -> border_and_titleblock), &BorderTitleBlock::informationChanged, this, &DiagramView::updateWindowTitle);
connect(diagram, &Diagram::findElementRequired, this, &DiagramView::findElementRequired);
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();
connect(&m_diagram->border_and_titleblock, &BorderTitleBlock::borderChanged, this, &DiagramView::updateCellRulers);
connect(&m_diagram->border_and_titleblock, &BorderTitleBlock::displayChanged, this, &DiagramView::updateCellRulers);
updateCellRulers();
QShortcut *edit_conductor_color_shortcut = new QShortcut(QKeySequence(Qt::Key_F2), this);
connect(edit_conductor_color_shortcut, &QShortcut::activated, [this]()
{
@@ -1170,6 +1178,82 @@ void DiagramView::paintingInverted(bool inverted)
m_diagram->setInvertedLightness(inverted);
}
/**
@brief DiagramView::setCellRulersShown
Show or hide the rulers that keep the column numbers and the row
letters of the folio border in sight along the edges of this view.
@param shown
*/
void DiagramView::setCellRulersShown(bool shown)
{
m_cell_rulers_shown = shown;
updateCellRulers();
}
/**
@brief DiagramView::updateCellRulers
Show each ruler when the rulers are wanted and the folio shows the
matching header, and give it room in the margins of the view. The
part of the folio in sight stays in sight when the viewport resizes.
*/
void DiagramView::updateCellRulers()
{
const BorderTitleBlock &border = m_diagram->border_and_titleblock;
const bool top = m_cell_rulers_shown
&& border.borderIsDisplayed() && border.columnsAreDisplayed();
const bool side = m_cell_rulers_shown
&& border.borderIsDisplayed() && border.rowsAreDisplayed();
const int thickness = m_top_ruler->thickness();
m_top_ruler->setVisible(top);
m_side_ruler->setVisible(side);
m_side_ruler->setLeadingSpace(top ? thickness : 0);
const QMargins margins(side ? thickness : 0, top ? thickness : 0, 0, 0);
if (margins != viewportMargins()) {
const QPointF centre = mapToScene(viewport()->rect().center());
setViewportMargins(margins);
centerOn(centre);
}
placeCellRulers();
m_top_ruler->update();
m_side_ruler->update();
}
/**
@brief DiagramView::placeCellRulers
Lay the rulers along the top and the left edges of the viewport, the
side ruler covering the corner too when both are shown.
*/
void DiagramView::placeCellRulers()
{
if (!m_top_ruler) {
return;
}
const QRect viewport_rect = viewport()->geometry();
const int thickness = m_top_ruler->thickness();
const int corner = m_top_ruler->isHidden() ? 0 : thickness;
m_top_ruler->setGeometry(viewport_rect.left(), viewport_rect.top() - thickness,
viewport_rect.width(), thickness);
m_side_ruler->setGeometry(viewport_rect.left() - thickness, viewport_rect.top() - corner,
thickness, viewport_rect.height() + corner);
}
/**
@brief DiagramView::viewportEvent
Keep the rulers along the viewport when it resizes, which it also does
without the view resizing, when the scroll bars come and go.
@param event
@return what QGraphicsView::viewportEvent() returns
*/
bool DiagramView::viewportEvent(QEvent *event)
{
if (event->type() == QEvent::Resize) {
placeCellRulers();
}
return PaletteGraphicsView::viewportEvent(event);
}
/**
@brief DiagramView::paintEvent
Reimplemented from QGraphicsView
@@ -1179,6 +1263,13 @@ void DiagramView::paintEvent(QPaintEvent *event)
{
PaletteGraphicsView::paintEvent(event);
//Scrolling and zooming both repaint the viewport: follow them
if (viewportTransform() != m_rulers_transform) {
m_rulers_transform = viewportTransform();
m_top_ruler->update();
m_side_ruler->update();
}
if (m_free_rubberbanding && m_free_rubberband.count() >= 3)
{
QPainter painter(viewport());