mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 23:20:52 +01:00
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:
@@ -686,7 +686,7 @@ void MirrorElementsCommand::redo()
|
|||||||
foreach (auto *item, m_items) {
|
foreach (auto *item, m_items) {
|
||||||
if (item->type() == PartText::Type) {
|
if (item->type() == PartText::Type) {
|
||||||
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
|
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
|
||||||
//staticText->mirror();
|
staticText->mirror();
|
||||||
} else if (item->type() == PartDynamicTextField::Type) {
|
} else if (item->type() == PartDynamicTextField::Type) {
|
||||||
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
|
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
|
||||||
dyntext->mirror();
|
dyntext->mirror();
|
||||||
@@ -734,7 +734,7 @@ void FlipElementsCommand::redo()
|
|||||||
foreach (auto *item, m_items) {
|
foreach (auto *item, m_items) {
|
||||||
if (item->type() == PartText::Type) {
|
if (item->type() == PartText::Type) {
|
||||||
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
|
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
|
||||||
//staticText->flip();
|
staticText->flip();
|
||||||
} else if (item->type() == PartDynamicTextField::Type) {
|
} else if (item->type() == PartDynamicTextField::Type) {
|
||||||
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
|
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
|
||||||
dyntext->flip();
|
dyntext->flip();
|
||||||
|
|||||||
@@ -72,6 +72,39 @@ void PartText::setRotation(qreal angle) {
|
|||||||
setPos(QTransform().rotate(angle).map(pos()));
|
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
|
Importe les proprietes d'un texte statique depuis un element XML
|
||||||
@param xml_element Element XML a lire
|
@param xml_element Element XML a lire
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ class PartText : public QGraphicsTextItem, public CustomElementPart {
|
|||||||
void fromXml(const QDomElement &) override;
|
void fromXml(const QDomElement &) override;
|
||||||
const QDomElement toXml(QDomDocument &) const override;
|
const QDomElement toXml(QDomDocument &) const override;
|
||||||
void setRotation(qreal angle);
|
void setRotation(qreal angle);
|
||||||
|
void mirror();
|
||||||
|
void flip();
|
||||||
bool isUseless() const override;
|
bool isUseless() const override;
|
||||||
QRectF sceneGeometricRect() const override;
|
QRectF sceneGeometricRect() const override;
|
||||||
void startUserTransformation(const QRectF &) override;
|
void startUserTransformation(const QRectF &) override;
|
||||||
|
|||||||
Reference in New Issue
Block a user