mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 14:50:53 +01:00
element-editor: fix jumping positions when rotate, mirror or flip
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -234,19 +234,19 @@ 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:
|
||||
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) {
|
||||
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);
|
||||
x = (p1.y() + m_rect.height()) * (-1);
|
||||
y = p1.x();
|
||||
} else {
|
||||
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);
|
||||
x = m_rect.y();
|
||||
y = (m_rect.x() + m_rect.width()) * (-1);
|
||||
}
|
||||
p1 = mapFromScene(x, y);
|
||||
m_rect = QRectF(p1.x(), p1.y(), width, height);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
emit rectChanged();
|
||||
@@ -257,16 +257,20 @@ qreal PartEllipse::rotation() const {
|
||||
}
|
||||
|
||||
void PartEllipse::flip() {
|
||||
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(p1.x(), p1.y(), m_rect.width(), m_rect.height());
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
emit rectChanged();
|
||||
}
|
||||
|
||||
void PartEllipse::mirror() {
|
||||
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(), p1.y(), m_rect.width(), m_rect.height());
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
emit rectChanged();
|
||||
|
||||
@@ -574,8 +574,12 @@ void PartLine::setSecondEndLength(const qreal &l)
|
||||
void PartLine::setRotation(qreal angle) {
|
||||
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()));
|
||||
auto p1 = mapToScene(m_line.p1());
|
||||
auto p2 = mapToScene(m_line.p2());
|
||||
p1 = QTransform().rotate(diffAngle).map(p1);
|
||||
p2 = QTransform().rotate(diffAngle).map(p2);
|
||||
m_line.setP1(mapFromScene(p1));
|
||||
m_line.setP2(mapFromScene(p2));
|
||||
prepareGeometryChange();
|
||||
setLine(m_line);
|
||||
adjustHandlerPos();
|
||||
@@ -587,8 +591,12 @@ qreal PartLine::rotation() const {
|
||||
}
|
||||
|
||||
void PartLine::flip() {
|
||||
m_line.setP1(QPointF(m_line.p1().x(), (-1) * m_line.p1().y()));
|
||||
m_line.setP2(QPointF(m_line.p2().x(), (-1) * m_line.p2().y()));
|
||||
auto p1 = mapToScene(m_line.p1());
|
||||
auto p2 = mapToScene(m_line.p2());
|
||||
p1 = QPointF(p1.x(), (-1) * p1.y());
|
||||
p2 = QPointF(p2.x(), (-1) * p2.y());
|
||||
m_line.setP1(mapFromScene(p1));
|
||||
m_line.setP2(mapFromScene(p2));
|
||||
setLine(m_line);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
@@ -596,8 +604,12 @@ void PartLine::flip() {
|
||||
}
|
||||
|
||||
void PartLine::mirror() {
|
||||
m_line.setP1(QPointF((-1) * m_line.p1().x(), m_line.p1().y()));
|
||||
m_line.setP2(QPointF((-1) * m_line.p2().x(), m_line.p2().y()));
|
||||
auto p1 = mapToScene(m_line.p1());
|
||||
auto p2 = mapToScene(m_line.p2());
|
||||
p1 = QPointF((-1) * p1.x(), p1.y());
|
||||
p2 = QPointF((-1) * p2.x(), p2.y());
|
||||
m_line.setP1(mapFromScene(p1));
|
||||
m_line.setP2(mapFromScene(p2));
|
||||
setLine(m_line);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
|
||||
@@ -292,8 +292,12 @@ void PartPolygon::resetAllHandlerColor()
|
||||
void PartPolygon::setRotation(qreal 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));
|
||||
for (auto &pt : m_polygon) {
|
||||
pt = mapToScene(pt.x(), pt.y());
|
||||
pt = QTransform().rotate(diffAngle).map(pt);
|
||||
pt = mapFromScene(pt.x(), pt.y());
|
||||
}
|
||||
setPolygon(m_polygon);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
emit polygonChanged();
|
||||
@@ -305,7 +309,9 @@ qreal PartPolygon::rotation() const {
|
||||
|
||||
void PartPolygon::flip() {
|
||||
for (auto &pt : m_polygon) {
|
||||
pt = mapToScene(pt.x(), pt.y());
|
||||
pt = QPointF(pt.x(), (-1) * pt.y());
|
||||
pt = mapFromScene(pt.x(), pt.y());
|
||||
}
|
||||
setPolygon(m_polygon);
|
||||
prepareGeometryChange();
|
||||
@@ -315,7 +321,9 @@ void PartPolygon::flip() {
|
||||
|
||||
void PartPolygon::mirror() {
|
||||
for (auto &pt : m_polygon) {
|
||||
pt = mapToScene(pt.x(), pt.y());
|
||||
pt = QPointF((-1) * pt.x(), pt.y());
|
||||
pt = mapFromScene(pt.x(), pt.y());
|
||||
}
|
||||
setPolygon(m_polygon);
|
||||
prepareGeometryChange();
|
||||
|
||||
@@ -163,22 +163,19 @@ 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());
|
||||
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) {
|
||||
x = (pos.y() + m_rect.height()) * (-1);
|
||||
y = pos.x();
|
||||
x = (p1.y() + m_rect.height()) * (-1);
|
||||
y = p1.x();
|
||||
} else {
|
||||
x = pos.y();
|
||||
y = (pos.x() + m_rect.width()) * (-1);
|
||||
x = p1.y();
|
||||
y = (p1.x() + m_rect.width()) * (-1);
|
||||
}
|
||||
|
||||
pos = mapFromScene(x, y);
|
||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
||||
m_rect.setWidth(width); m_rect.setHeight(height);
|
||||
p1 = mapFromScene(x, y);
|
||||
m_rect = QRectF(p1.x(), p1.y(), width, height);
|
||||
std::swap (m_xRadius, m_yRadius);
|
||||
|
||||
prepareGeometryChange();
|
||||
@@ -191,13 +188,13 @@ qreal PartRectangle::rotation() const {
|
||||
}
|
||||
|
||||
void PartRectangle::flip() {
|
||||
// for whatever reason: with "rect" we need to use scene-positions...
|
||||
qreal height = m_rect.height();
|
||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
||||
qreal x = pos.x();
|
||||
qreal y = ((-1.0) * pos.y()) - height;
|
||||
pos = mapFromScene(x, y);
|
||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
||||
auto height = m_rect.height();
|
||||
auto p1 = mapToScene(m_rect.x(),m_rect.y());
|
||||
qreal x = p1.x();
|
||||
qreal y = ((-1.0) * p1.y()) - height;
|
||||
p1 = mapFromScene(x, y);
|
||||
m_rect.setX(p1.x());
|
||||
m_rect.setY(p1.y());
|
||||
m_rect.setHeight(height);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
@@ -205,13 +202,13 @@ void PartRectangle::flip() {
|
||||
}
|
||||
|
||||
void PartRectangle::mirror() {
|
||||
// for whatever reason: with "rect" we need to use scene-positions...
|
||||
qreal width = m_rect.width();
|
||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
||||
qreal x = ((-1.0) * pos.x()) - width;
|
||||
qreal y = pos.y();
|
||||
pos = mapFromScene(x, y);
|
||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
||||
auto width = m_rect.width();
|
||||
auto p1 = mapToScene(m_rect.x(),m_rect.y());
|
||||
qreal x = ((-1.0) * p1.x()) - width;
|
||||
qreal y = p1.y();
|
||||
p1 = mapFromScene(x, y);
|
||||
m_rect.setX(p1.x());
|
||||
m_rect.setY(p1.y());
|
||||
m_rect.setWidth(width);
|
||||
prepareGeometryChange();
|
||||
adjustHandlerPos();
|
||||
|
||||
@@ -158,23 +158,20 @@ void PartTerminal::setRotation(qreal angle) {
|
||||
else new_ori = Qet::West;
|
||||
|
||||
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
||||
double tmp, y, x;
|
||||
if (diffAngle > 0) {
|
||||
tmp = d->m_pos.y();
|
||||
y = d->m_pos.x();
|
||||
x = (-1) * tmp;
|
||||
} else {
|
||||
tmp = d->m_pos.x();
|
||||
x = d->m_pos.y();
|
||||
y = (-1) * tmp;
|
||||
}
|
||||
d->m_pos.setX(x); d->m_pos.setY(y);
|
||||
|
||||
auto p1 = QTransform().rotate(diffAngle).map(pos());
|
||||
d->m_pos.setX(p1.x()); d->m_pos.setY(p1.y());
|
||||
setPos(d->m_pos);
|
||||
setOrientation(new_ori);
|
||||
updateSecondPoint();
|
||||
prepareGeometryChange();
|
||||
emit orientationChanged(); // all terminal-signals call "updateForm"
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartTerminal::rotation
|
||||
@return current rotation-angle in degrees
|
||||
*/
|
||||
qreal PartTerminal::rotation() const {
|
||||
switch (d->m_orientation) {
|
||||
case Qet::North : return 0;
|
||||
@@ -185,9 +182,13 @@ qreal PartTerminal::rotation() const {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartTerminal::flip
|
||||
turn part upside down
|
||||
*/
|
||||
void PartTerminal::flip() {
|
||||
d->m_pos.setY((-1.0) * d->m_pos.y());
|
||||
|
||||
d->m_pos.setX( pos().x());
|
||||
d->m_pos.setY((-1.0) * pos().y());
|
||||
switch (d->m_orientation) {
|
||||
case Qet::North : setOrientation(Qet::South);
|
||||
break;
|
||||
@@ -202,8 +203,13 @@ void PartTerminal::flip() {
|
||||
emit yChanged(); // all terminal-signals call "updateForm"
|
||||
}
|
||||
|
||||
/**
|
||||
@brief PartTerminal::mirror
|
||||
turn part from left to right
|
||||
*/
|
||||
void PartTerminal::mirror() {
|
||||
d->m_pos.setX((-1.0) * d->m_pos.x());
|
||||
d->m_pos.setX((-1.0) * pos().x());
|
||||
d->m_pos.setY( pos().y());
|
||||
switch (d->m_orientation) {
|
||||
case Qet::North : break;
|
||||
case Qet::East : setOrientation(Qet::West);
|
||||
|
||||
Reference in New Issue
Block a user