diff --git a/sources/factory/elementpicturefactory.cpp b/sources/factory/elementpicturefactory.cpp index 6de56ad79..ba2892aa2 100644 --- a/sources/factory/elementpicturefactory.cpp +++ b/sources/factory/elementpicturefactory.cpp @@ -379,6 +379,9 @@ bool ElementPictureFactory::build(const ElementsLocation &location, const auto uuid_ = cacheKey(location); if (!mirror.isIdentity()) { + //The primitives are those of the drawing without mirror, + //already kept by the build of that one + qDeleteAll(primitives_.m_texts); const QPair key(uuid_, (mirror.m11() < 0 ? 1 : 0) | (mirror.m22() < 0 ? 2 : 0)); if (!picture) { diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 67dbabca5..755898ee3 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -2186,6 +2186,13 @@ 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); update(); return ReloadPictureResult::Reloaded; } diff --git a/sources/qetgraphicsitem/elementtextitemgroup.cpp b/sources/qetgraphicsitem/elementtextitemgroup.cpp index b9dc47a91..a14a5ef0c 100644 --- a/sources/qetgraphicsitem/elementtextitemgroup.cpp +++ b/sources/qetgraphicsitem/elementtextitemgroup.cpp @@ -648,6 +648,10 @@ QRectF ElementTextItemGroup::boundingRect() const void ElementTextItemGroup::setRotation(qreal angle) { QGraphicsItemGroup::setRotation(angle); + //On a mirrored element, the mirror that keeps this group readable + //is about the centre of its turned box + if (m_parent_element) + m_parent_element->keepReadable(this); emit rotationChanged(angle); } diff --git a/sources/qetgraphicsitem/terminal.cpp b/sources/qetgraphicsitem/terminal.cpp index 70f7df795..3a8564ab3 100644 --- a/sources/qetgraphicsitem/terminal.cpp +++ b/sources/qetgraphicsitem/terminal.cpp @@ -306,6 +306,23 @@ 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(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); + const QPointF c = rect.center(); + painter->setTransform(QTransform::fromTranslate(-c.x(), -c.y()) + * mirror + * QTransform::fromTranslate(c.x(), c.y()), true); + }; + if (!qFuzzyIsNull(d->m_label_rotation)) { painter->save(); painter->translate(label_pos); @@ -321,6 +338,7 @@ void Terminal::paint( else if (d->m_label_valignment & Qt::AlignBottom) ry = -text_size.height(); QRectF text_rect(QPointF(rx, ry), text_size); + keep_readable(text_rect, d->m_label_rotation); painter->drawText(text_rect, static_cast(d->m_label_halignment | d->m_label_valignment), display_name); painter->restore(); } else { @@ -334,6 +352,7 @@ void Terminal::paint( else if (d->m_label_valignment & Qt::AlignBottom) dy = -text_size.height(); QRectF text_rect(label_pos + QPointF(dx, dy), text_size); + keep_readable(text_rect, 0); if (d->m_label_frame) { painter->drawRect(text_rect.adjusted(-1, -1, 1, 1)); }