element-editor: fix jumping positions when rotate, mirror or flip

This commit is contained in:
plc-user
2025-03-07 07:43:20 +01:00
parent 20b7e1763d
commit 45afd9af0e
6 changed files with 112 additions and 81 deletions

View File

@@ -168,25 +168,25 @@ 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:
auto p1 = mapToScene(m_rect.x(),m_rect.y());
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x; qreal y;
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); }
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = (m_rect.y() + m_rect.height()) * (-1);
qreal y = m_rect.x();
m_rect = QRectF(x, y, width, height);
} else {
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); }
qreal width = m_rect.height();
qreal height = m_rect.width();
qreal x = m_rect.y();
qreal y = (m_rect.x() + m_rect.width()) * (-1);
m_rect = QRectF(x, y, width, height);
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); }
x = (p1.y() + m_rect.height()) * (-1);
y = p1.x();
} else {
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); }
x = p1.y();
y = (p1.x() + m_rect.width()) * (-1);
}
p1 = mapFromScene(x, y);
m_rect = QRectF(p1.x(), p1.y(), width, height);
prepareGeometryChange();
adjustHandlerPos();
@@ -202,8 +202,10 @@ void PartArc::flip() {
m_span_angle = (-1) * m_span_angle;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
qreal y = ((-1.0) * m_rect.y()) - m_rect.height();
m_rect = QRectF(m_rect.x(), y, m_rect.width(), m_rect.height());
auto p1 = mapToScene(m_rect.x(),m_rect.y());
p1.setY(((-1.0) * p1.y()) - m_rect.height());
p1 = mapFromScene(p1.x(),p1.y());
m_rect = QRectF(m_rect.x(), p1.y(), m_rect.width(), m_rect.height());
prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();
@@ -214,8 +216,10 @@ void PartArc::mirror() {
m_span_angle = (-1) * m_span_angle;
while (m_start_angle < 0) { m_start_angle += (360*16); }
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
qreal x = ((-1.0) * m_rect.x()) - m_rect.width();
m_rect = QRectF(x, m_rect.y(), m_rect.width(), m_rect.height());
auto p1 = mapToScene(m_rect.x(),m_rect.y());
p1.setX(((-1.0) * p1.x()) - m_rect.width());
p1 = mapFromScene(p1.x(), p1.y());
m_rect = QRectF(p1.x(), m_rect.y(), m_rect.width(), m_rect.height());
prepareGeometryChange();
adjustHandlerPos();
emit rectChanged();