mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-10 22:24: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:
@@ -167,6 +167,8 @@ Element::Element(
|
||||
//The mirror is about the element's own axis, so it follows the
|
||||
//rotation, see applyMirrorTransform()
|
||||
connect(this, &Element::rotationChanged, this, &Element::applyMirrorTransform);
|
||||
//Texts kept horizontal in a turned symbol depend on the turn
|
||||
connect(this, &Element::rotationChanged, this, [this]() {updateSymbolPictures();});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -299,16 +301,7 @@ void Element::setMirror(bool horizontal, bool vertical)
|
||||
m_horizontal_mirror = horizontal;
|
||||
m_vertical_mirror = vertical;
|
||||
|
||||
m_mirrored_picture = QPicture();
|
||||
m_mirrored_low_zoom_picture = QPicture();
|
||||
if (isMirrored())
|
||||
ElementPictureFactory::instance()->getMirroredPictures(
|
||||
m_location,
|
||||
horizontal,
|
||||
vertical,
|
||||
m_mirrored_picture,
|
||||
m_mirrored_low_zoom_picture);
|
||||
|
||||
updateSymbolPictures();
|
||||
applyMirrorTransform();
|
||||
keepChildrenReadable();
|
||||
update();
|
||||
@@ -325,6 +318,69 @@ QTransform Element::mirrorTransform() const
|
||||
m_vertical_mirror ? -1 : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::hasUprightSymbolTexts
|
||||
@return true if the project of this element keeps the texts of its
|
||||
turned symbols horizontal (QETProject::uprightSymbolTexts())
|
||||
*/
|
||||
bool Element::hasUprightSymbolTexts() const
|
||||
{
|
||||
const Diagram *d = diagram();
|
||||
return d && d->project() && d->project()->uprightSymbolTexts();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::symbolTextsTransform
|
||||
@return what this element does to the texts drawn in its symbol, which
|
||||
the drawing undoes to keep them readable (updateSymbolPictures()):
|
||||
its mirrors, and its turn when the project keeps them horizontal.
|
||||
The identity when the symbol is drawn as it is.
|
||||
*/
|
||||
QTransform Element::symbolTextsTransform() const
|
||||
{
|
||||
//QTransform's product applies its left operand first
|
||||
QTransform transform = mirrorTransform();
|
||||
if (hasUprightSymbolTexts())
|
||||
transform *= QTransform().rotate(orientation() * 90);
|
||||
return transform;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::updateSymbolPictures
|
||||
Take the drawing of the symbol whose texts read normally once this
|
||||
element has mirrored and turned it (symbolTextsTransform()), or drop it
|
||||
when the plain drawing does.
|
||||
@param force : take it again even if the transform did not change, as
|
||||
when the symbol's definition was reloaded
|
||||
*/
|
||||
void Element::updateSymbolPictures(bool force)
|
||||
{
|
||||
const QTransform transform = symbolTextsTransform();
|
||||
if (transform.isIdentity())
|
||||
{
|
||||
if (!m_readable_transform.isIdentity())
|
||||
{
|
||||
m_readable_transform = QTransform();
|
||||
m_readable_picture = QPicture();
|
||||
m_readable_low_zoom_picture = QPicture();
|
||||
update();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (transform == m_readable_transform && !force)
|
||||
return;
|
||||
|
||||
m_readable_transform = transform;
|
||||
m_readable_picture = QPicture();
|
||||
m_readable_low_zoom_picture = QPicture();
|
||||
ElementPictureFactory::instance()->getReadablePictures(
|
||||
m_location,
|
||||
transform,
|
||||
m_readable_picture,
|
||||
m_readable_low_zoom_picture);
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Element::applyMirrorTransform
|
||||
QGraphicsItem applies transform() after the rotation, so the mirrors of
|
||||
@@ -427,9 +483,10 @@ void Element::paint(
|
||||
QBrush brush;
|
||||
painter->setPen(pen);
|
||||
painter->setBrush(brush);
|
||||
const QPicture &picture = isMirrored() ? m_mirrored_picture : m_picture;
|
||||
const QPicture &low_zoom_picture = isMirrored() ? m_mirrored_low_zoom_picture
|
||||
: m_low_zoom_picture;
|
||||
const bool readable = !m_readable_transform.isIdentity();
|
||||
const QPicture &picture = readable ? m_readable_picture : m_picture;
|
||||
const QPicture &low_zoom_picture = readable ? m_readable_low_zoom_picture
|
||||
: m_low_zoom_picture;
|
||||
if (options && options->levelOfDetailFromTransform(painter->worldTransform()) < 0.5)
|
||||
{
|
||||
if (!low_zoom_picture.isNull())
|
||||
@@ -1965,6 +2022,10 @@ QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value)
|
||||
deti->refreshResizeHandlesVisibility();
|
||||
}
|
||||
}
|
||||
//Whether the texts of a turned symbol stay horizontal is the
|
||||
//project's setting, known once the element is on one of its folios
|
||||
else if (change == QGraphicsItem::ItemSceneHasChanged)
|
||||
updateSymbolPictures();
|
||||
return QetGraphicsItem::itemChange(change, value);
|
||||
}
|
||||
|
||||
@@ -2186,13 +2247,7 @@ Element::ReloadPictureResult Element::reloadPicture()
|
||||
|
||||
m_picture = picture;
|
||||
m_low_zoom_picture = low_zoom_picture;
|
||||
if (isMirrored())
|
||||
ElementPictureFactory::instance()->getMirroredPictures(
|
||||
m_location,
|
||||
m_horizontal_mirror,
|
||||
m_vertical_mirror,
|
||||
m_mirrored_picture,
|
||||
m_mirrored_low_zoom_picture);
|
||||
updateSymbolPictures(true);
|
||||
update();
|
||||
return ReloadPictureResult::Reloaded;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user