Share the text grid choices; add a preference, a status hint and a unit test

Drop 1:2.5: on a grid of 10 it steps by 4, which misses 10, so texts on
two elements 10 apart could never line up. Every remaining divisor is a
whole number, which tst_textgrid checks.

The divisor list and the snapping arithmetic move to the header-only
textgrid.h so the toolbar menu, the preferences page and the test share
them. The preferences page gets the same choice under Grille + Clavier;
QETApp::textGridChanged keeps every editor's toolbar button in step.
While element texts are dragged, the status bar names the text grid and
says to release Shift and hold Ctrl for free placement -- Ctrl+Shift
together is the pan shortcut.

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 10:11:18 +12:00
parent 0e02190eb2
commit 95f3ea2f6d
12 changed files with 252 additions and 37 deletions
+13 -19
View File
@@ -42,6 +42,7 @@
#include "qetinformation.h"
#include "qetproject.h"
#include "diagramsortkeys.h"
#include "textgrid.h"
#include <QTextStream>
#include <algorithm>
#include <climits>
@@ -2686,32 +2687,25 @@ QPointF Diagram::snapToGrid(const QPointF &p)
/**
@brief Diagram::snapToTextGrid
Return the nearest point of p on the text grid.
The text grid is the folio grid divided by the
"diagrameditor/text_grid_divisor" setting (1 = same as the folio grid,
0 = no grid). Because it divides the folio grid, texts snapped to it
still line up with every element and with each other.
Ctrl held, or a divisor of 0, rounds to the nearest pixel instead.
Return the nearest point of p on the text grid, see TextGrid.
Ctrl held rounds to the nearest pixel instead, as snapToGrid() does.
@param p point to find the nearest snapped point
@return
*/
QPointF Diagram::snapToTextGrid(const QPointF &p)
{
QSettings settings;
const qreal divisor = settings.value(
QStringLiteral("diagrameditor/text_grid_divisor"),
1).toReal();
const qreal divisor =
QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)
? 0
: settings.value(TextGrid::settings_key, 1).toReal();
if (divisor <= 0
|| QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
return QPointF(qRound(p.x()), qRound(p.y()));
const qreal x_step = settings.value(QStringLiteral("diagrameditor/Xgrid"),
Diagram::xGrid).toInt() / divisor;
const qreal y_step = settings.value(QStringLiteral("diagrameditor/Ygrid"),
Diagram::yGrid).toInt() / divisor;
return QPointF(qRound(p.x() / x_step) * x_step,
qRound(p.y() / y_step) * y_step);
return TextGrid::snap(p,
settings.value(QStringLiteral("diagrameditor/Xgrid"),
Diagram::xGrid).toInt(),
settings.value(QStringLiteral("diagrameditor/Ygrid"),
Diagram::yGrid).toInt(),
divisor);
}