Keep the texts of turned symbols horizontal, per project (#1335)

A project can now keep the texts drawn in its symbols, and the names of
their terminals, horizontal when a symbol is turned: Project properties >
General, "Garder horizontaux les textes des symboles pivotés". The box of
each text turns with the symbol; the text does not, and reads as it does
in the symbol itself.

It is a project setting, saved as <symbol_texts upright="true"/> and
only when on. A new project starts with it on; a project saved without
it (every existing one) reads with it off, so it looks and saves exactly
as before, and looks the same on every computer. The MCP server's new
projects start with it on too.

It builds on the mirror of #1354, which already redraws the texts of a
mirrored symbol readable: what the symbol does to its texts is now its
mirrors and, with the setting on, its turn (Element::symbolTextsTransform()).
ElementPictureFactory caches one drawing per such transform, terminal
names undo it the same way, and the DXF export places the texts alike.

The fields of a symbol (label, comment...) already keep their angle with
"Garder la rotation visuelle" and are left as they are.

Known limit: two texts stacked in a symbol end up side by side when it is
turned, and can overlap when kept horizontal; the setting can be turned
off for such a project.

Test: tst_uprightsymboltexts turns the symbols of a folio and checks the
angle of each motor's "M" in the DXF, with the setting off and on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-07 12:43:04 +13:00
parent a3b1468b0f
commit 592cbdbf0b
14 changed files with 428 additions and 93 deletions
+14 -12
View File
@@ -306,20 +306,22 @@ void Terminal::paint(
QFontMetrics fm(d->m_label_font);
QSizeF text_size = fm.size(Qt::TextSingleLine, display_name);
// On a mirrored element, mirror the name a second time about
// the centre of its box, in the frame it is drawn in (turned
// by label_rotation): its box stays where the element's mirror
// puts it, but it reads normally (Element::keepReadable())
const Element *mirrored = qgraphicsitem_cast<Element *>(parentItem());
if (mirrored && !mirrored->isMirrored()) mirrored = nullptr;
auto keep_readable = [painter, mirrored](const QRectF &rect, qreal label_rotation) {
if (!mirrored) return;
const QTransform mirror = QTransform().rotate(label_rotation)
* mirrored->mirrorTransform()
* QTransform().rotate(-label_rotation);
// When the element mirrors its symbol, or turns it in a project
// that keeps symbol texts horizontal, undo that on the name
// about the centre of its box, in the frame it is drawn in
// (turned by label_rotation): its box stays where the element
// puts it, but it reads as in the symbol (Element::keepReadable())
const Element *element = qgraphicsitem_cast<Element *>(parentItem());
const QTransform texts_transform = element ? element->symbolTextsTransform()
: QTransform();
auto keep_readable = [painter, &texts_transform](const QRectF &rect, qreal label_rotation) {
if (texts_transform.isIdentity()) return;
const QTransform undo = QTransform().rotate(label_rotation)
* texts_transform.inverted()
* QTransform().rotate(-label_rotation);
const QPointF c = rect.center();
painter->setTransform(QTransform::fromTranslate(-c.x(), -c.y())
* mirror
* undo
* QTransform::fromTranslate(c.x(), c.y()), true);
};