element editor: add mirror and flip for “text”

Maybe not (yet) perfect, but it looks pretty good to me!

Why am I doing this to myself?
All this crap with fonts and stuff!
It's been crap for as long as I can remember.
This commit is contained in:
plc-user
2025-02-17 19:39:53 +01:00
parent 0f647a5c38
commit dc836248f0
3 changed files with 37 additions and 2 deletions

View File

@@ -72,6 +72,39 @@ void PartText::setRotation(qreal angle) {
setPos(QTransform().rotate(angle).map(pos()));
}
void PartText::mirror() {
// at first: rotate the text:
QGraphicsObject::setRotation(QET::correctAngle((360-rotation()), true));
// then see, where we need to re-position depending on text, font ...
QFontMetrics qfm(font());
qreal textwidth = qfm.horizontalAdvance(toPlainText());
// ... and angle!!!
qreal rot = qRound(QET::correctAngle(rotation(), true));
qreal c = qCos(qDegreesToRadians(rot));
qreal s = qSin(qDegreesToRadians(rot));
// Now: Move!
qreal x = (-1) * pos().x() - c * (textwidth);
qreal y = pos().y() - s * (textwidth);
setPos(x, y);
}
void PartText::flip() {
// at first: rotate the text:
QGraphicsObject::setRotation(QET::correctAngle((360-rotation()), true));
// then see, where we need to re-position depending on text, font ...
QFontMetrics qfm(font());
qreal textheight = realSize() - qfm.descent();
// ... and angle!!!
qreal rot = qRound(QET::correctAngle(rotation(), true));
qreal c = qCos(qDegreesToRadians(rot));
qreal s = qSin(qDegreesToRadians(rot));
// Now: Move!
qreal x = pos().x() - s * (textheight);
qreal y = (-1) * pos().y() + c * (textheight);
setPos(x, y);
}
/**
Importe les proprietes d'un texte statique depuis un element XML
@param xml_element Element XML a lire