mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-08 04:44:13 +02:00
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:
+11
-8
@@ -197,11 +197,15 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
fontSize = text->font().pixelSize();
|
||||
|
||||
QPointF text_pos = text->pos();
|
||||
if (elmt -> isMirrored())
|
||||
//A text the element mirrors, or turns in a project that keeps
|
||||
//symbol texts horizontal, keeps reading as in the symbol:
|
||||
//only its box moves, as ElementPictureFactory draws it on the
|
||||
//folio. It is then drawn as in a symbol neither mirrored nor
|
||||
//turned, moved to where the element puts the box's centre.
|
||||
const QTransform texts_transform = elmt -> symbolTextsTransform();
|
||||
const qreal text_turn = elmt -> hasUprightSymbolTexts() ? 0 : rotation_angle;
|
||||
if (!texts_transform.isIdentity())
|
||||
{
|
||||
//The text keeps reading normally: only its box is
|
||||
//mirrored, about its own centre, as ElementPictureFactory
|
||||
//draws it on the folio
|
||||
QTransform box_transform;
|
||||
box_transform.translate(text->pos().x(), text->pos().y());
|
||||
box_transform.rotate(text->rotation());
|
||||
@@ -210,19 +214,18 @@ void DxfExport::write(Diagram *diagram, int width, int height,
|
||||
text->boundingRect().width(),
|
||||
text->boundingRect().height());
|
||||
const QPointF centre = box_transform.mapRect(box).center();
|
||||
text_pos += QPointF(centre.x() * (mirror_x - 1),
|
||||
centre.y() * (mirror_y - 1));
|
||||
text_pos += texts_transform.map(centre) - centre;
|
||||
}
|
||||
|
||||
qreal x = elem_pos_x + text_pos.x();
|
||||
qreal y = elem_pos_y + text_pos.y();
|
||||
|
||||
qreal angle = text -> rotation() + rotation_angle;
|
||||
qreal angle = text -> rotation() + text_turn;
|
||||
qreal angler = angle * M_PI/180;
|
||||
int xdir = -sin(angler);
|
||||
int ydir = -cos(angler);
|
||||
|
||||
QPointF transformed_point = rotation_transformed(x, y, elem_pos_x, elem_pos_y, -rotation_angle);
|
||||
QPointF transformed_point = rotation_transformed(x, y, elem_pos_x, elem_pos_y, -text_turn);
|
||||
x = transformed_point.x() - ydir * fontSize * 0.5;
|
||||
y = transformed_point.y() - xdir * fontSize * 0.5;
|
||||
QStringList lines = text->text().split('\n');
|
||||
|
||||
Reference in New Issue
Block a user