unify calls to "setRotation" for element-primitives

This commit is contained in:
plc-user
2025-02-22 09:30:15 +01:00
parent 181680e6f1
commit 43386aa14f
9 changed files with 44 additions and 32 deletions

View File

@@ -541,19 +541,19 @@ void RotateElementsCommand::undo()
}
else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(-90);
line->setRotation(line->rotation()-90);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(-90);
poly->setRotation(poly->rotation()-90);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(-90);
text->setRotation(text->rotation()-90);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(-90);
dyntext->setRotation(dyntext->rotation()-90);
}
else {
item->setRotation(item->rotation()-90);
@@ -586,19 +586,19 @@ void RotateElementsCommand::redo()
}
else if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(+90);
line->setRotation(line->rotation()+90);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(+90);
poly->setRotation(poly->rotation()+90);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(+90);
text->setRotation(text->rotation()+90);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(+90);
dyntext->setRotation(dyntext->rotation()+90);
}
else {
item->setRotation(item->rotation()+90);
@@ -622,22 +622,22 @@ void RotateFineElementsCommand::undo()
{
if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(-5);
line->setRotation(line->rotation()-5);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(-5);
poly->setRotation(poly->rotation()-5);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(-5);
text->setRotation(text->rotation()-5);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(-5);
dyntext->setRotation(dyntext->rotation()-5);
}
else {
//item->setRotation(-5);
//item->setRotation(item->rotation()-5);
}
}
}
@@ -651,22 +651,22 @@ void RotateFineElementsCommand::redo()
{
if (item->type() == PartLine::Type) {
PartLine* line = qgraphicsitem_cast<PartLine*>(item);
line->setRotation(+5);
line->setRotation(line->rotation()+5);
}
else if (item->type() == PartPolygon::Type) {
PartPolygon* poly = qgraphicsitem_cast<PartPolygon*>(item);
poly->setRotation(+5);
poly->setRotation(poly->rotation()+5);
}
else if (item->type() == PartText::Type) {
PartText* text = qgraphicsitem_cast<PartText*>(item);
text->setRotation(+5);
text->setRotation(text->rotation()+5);
}
else if (item->type() == PartDynamicTextField::Type) {
PartDynamicTextField* dyntext = qgraphicsitem_cast<PartDynamicTextField*>(item);
dyntext->setRotation(+5);
dyntext->setRotation(dyntext->rotation()+5);
}
else {
//item->setRotation(+5);
//item->setRotation(item->rotation()+5);
}
}
}

View File

@@ -172,8 +172,10 @@ QPainterPath PartArc::shadowShape() const
void PartArc::setRotation(qreal angle) {
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
// idea taken from QET_ElementScaler:
if (angle > 0) {
if (diffAngle > 0) {
m_start_angle += 270.0 * 16;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }

View File

@@ -67,8 +67,9 @@ QString PartDynamicTextField::xmlName() const
@param angle
*/
void PartDynamicTextField::setRotation(qreal angle) {
QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true));
setPos(QTransform().rotate(angle).map(pos()));
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
QGraphicsObject::setRotation(QET::correctAngle(angle, true));
setPos(QTransform().rotate(diffAngle).map(pos()));
}
void PartDynamicTextField::mirror() {

View File

@@ -238,8 +238,10 @@ bool PartEllipse::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
void PartEllipse::setRotation(qreal angle) {
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
// idea taken from QET_ElementScaler:
if (angle > 0) {
if (diffAngle > 0) {
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = (m_rect.y() + m_rect.height()) * (-1);

View File

@@ -579,9 +579,10 @@ void PartLine::setSecondEndLength(const qreal &l)
}
void PartLine::setRotation(qreal angle) {
m_rot += angle;
m_line.setP1(QTransform().rotate(angle).map(m_line.p1()));
m_line.setP2(QTransform().rotate(angle).map(m_line.p2()));
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
m_line.setP1(QTransform().rotate(diffAngle).map(m_line.p1()));
m_line.setP2(QTransform().rotate(diffAngle).map(m_line.p2()));
prepareGeometryChange();
setLine(m_line);
adjustHandlerPos();

View File

@@ -297,8 +297,9 @@ void PartPolygon::resetAllHandlerColor()
void PartPolygon::setRotation(qreal angle) {
QTransform rotation = QTransform().rotate(angle);
m_rot += angle;
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
QTransform rotation = QTransform().rotate(diffAngle);
setPolygon(rotation.map(m_polygon));
prepareGeometryChange();
adjustHandlerPos();

View File

@@ -168,12 +168,14 @@ void PartRectangle::setYRadius(qreal Y)
}
void PartRectangle::setRotation(qreal angle) {
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
m_rot = QET::correctAngle(angle, true);
// for whatever reason: with "rect" we need to use scene-positions...
auto pos = mapToScene(m_rect.x(),m_rect.y());
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x; qreal y;
if (angle > 0) {
if (diffAngle > 0) {
x = (pos.y() + m_rect.height()) * (-1);
y = pos.x();
} else {

View File

@@ -42,8 +42,9 @@ PartTerminal::~PartTerminal()
}
/**
Import terminal properties from an XML element
Importe les proprietes d'une borne depuis un element XML
@param xml_elmt Element XML a lire
@param xml_elmt Element XML a lire / XML element to read
*/
void PartTerminal::fromXml(const QDomElement &xml_elmt) {
d -> fromXml(xml_elmt);
@@ -166,8 +167,9 @@ void PartTerminal::setRotation(qreal angle) {
else if (180 <= angle_mod && angle_mod < 270) new_ori = Qet::South;
else new_ori = Qet::West;
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
double tmp, y, x;
if (angle > 0) {
if (diffAngle > 0) {
tmp = d->m_pos.y();
y = d->m_pos.x();
x = (-1) * tmp;

View File

@@ -68,8 +68,9 @@ PartText::~PartText()
@param angle
*/
void PartText::setRotation(qreal angle) {
QGraphicsObject::setRotation(QET::correctAngle(rotation()+angle, true));
setPos(QTransform().rotate(angle).map(pos()));
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
QGraphicsObject::setRotation(QET::correctAngle(angle, true));
setPos(QTransform().rotate(diffAngle).map(pos()));
}
void PartText::mirror() {