mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
element-editor: add mirror and flip for "dynamic_text"
This commit is contained in:
parent
6fdc243552
commit
3fc5469aee
@ -619,9 +619,12 @@ ElementEditionCommand(QObject::tr("Miroir de sélection", "undo caption"), scene
|
|||||||
void MirrorElementsCommand::redo()
|
void MirrorElementsCommand::redo()
|
||||||
{
|
{
|
||||||
foreach (auto *item, m_items) {
|
foreach (auto *item, m_items) {
|
||||||
if ((item->type() == PartText::Type) ||
|
if (item->type() == PartText::Type) {
|
||||||
(item->type() == PartDynamicTextField::Type)) {
|
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
|
||||||
continue;
|
//staticText->mirror();
|
||||||
|
} else if (item->type() == PartDynamicTextField::Type) {
|
||||||
|
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
|
||||||
|
dyntext->mirror();
|
||||||
} else if (item->type() == PartArc::Type) {
|
} else if (item->type() == PartArc::Type) {
|
||||||
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
|
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
|
||||||
arc->mirror();
|
arc->mirror();
|
||||||
@ -664,9 +667,12 @@ ElementEditionCommand(QObject::tr("Retourner la sélection", "undo caption"), sc
|
|||||||
void FlipElementsCommand::redo()
|
void FlipElementsCommand::redo()
|
||||||
{
|
{
|
||||||
foreach (auto *item, m_items) {
|
foreach (auto *item, m_items) {
|
||||||
if ((item->type() == PartText::Type) ||
|
if (item->type() == PartText::Type) {
|
||||||
(item->type() == PartDynamicTextField::Type)) {
|
PartText* staticText = qgraphicsitem_cast<PartText*>(item);
|
||||||
continue;
|
//staticText->flip();
|
||||||
|
} else if (item->type() == PartDynamicTextField::Type) {
|
||||||
|
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
|
||||||
|
dyntext->flip();
|
||||||
} else if (item->type() == PartArc::Type) {
|
} else if (item->type() == PartArc::Type) {
|
||||||
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
|
PartArc* arc = qgraphicsitem_cast<PartArc*>(item);
|
||||||
arc->flip();
|
arc->flip();
|
||||||
|
@ -69,7 +69,30 @@ QString PartDynamicTextField::xmlName() const
|
|||||||
void PartDynamicTextField::setRotation(qreal angle) {
|
void PartDynamicTextField::setRotation(qreal angle) {
|
||||||
QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true));
|
QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true));
|
||||||
setPos(QTransform().rotate(angle).map(pos()));
|
setPos(QTransform().rotate(angle).map(pos()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartDynamicTextField::mirror() {
|
||||||
|
// at first: rotate the text:
|
||||||
|
QGraphicsObject::setRotation(QET::correctAngle(360-rotation(), true));
|
||||||
|
// then see, where we need to re-position depending on the angle!
|
||||||
|
qreal rot = qRound(QET::correctAngle(rotation(), true));
|
||||||
|
qreal c = qCos(qDegreesToRadians(rot));
|
||||||
|
qreal s = qSin(qDegreesToRadians(rot));
|
||||||
|
qreal x = (-1) * pos().x() - c * boundingRect().width();
|
||||||
|
qreal y = pos().y() - s * boundingRect().width();
|
||||||
|
setPos(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PartDynamicTextField::flip() {
|
||||||
|
// at first: rotate the text:
|
||||||
|
QGraphicsObject::setRotation(QET::correctAngle(360-rotation(), true));
|
||||||
|
// then see, where we need to re-position depending on the angle!
|
||||||
|
qreal rot = qRound(QET::correctAngle(rotation(), true));
|
||||||
|
qreal c = qCos(qDegreesToRadians(rot));
|
||||||
|
qreal s = qSin(qDegreesToRadians(rot));
|
||||||
|
qreal x = pos().x() + s * boundingRect().height();
|
||||||
|
qreal y = (-1) * pos().y() - c * boundingRect().height();
|
||||||
|
setPos(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,6 +102,8 @@ class PartDynamicTextField : public QGraphicsTextItem, public CustomElementPart
|
|||||||
bool keepVisualRotation() const;
|
bool keepVisualRotation() const;
|
||||||
|
|
||||||
void setRotation(qreal angle);
|
void setRotation(qreal angle);
|
||||||
|
void mirror();
|
||||||
|
void flip();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user