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;
|
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
||||||
m_rot = QET::correctAngle(angle, true);
|
m_rot = QET::correctAngle(angle, true);
|
||||||
// idea taken from QET_ElementScaler:
|
// 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) {
|
if (diffAngle > 0) {
|
||||||
m_start_angle += 270.0 * 16;
|
m_start_angle += 270.0 * 16;
|
||||||
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
||||||
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
|
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
|
||||||
qreal width = m_rect.height();
|
x = (p1.y() + m_rect.height()) * (-1);
|
||||||
qreal height = m_rect.width();
|
y = p1.x();
|
||||||
qreal x = (m_rect.y() + m_rect.height()) * (-1);
|
} else {
|
||||||
qreal y = m_rect.x();
|
m_start_angle -= 270.0 * 16;
|
||||||
m_rect = QRectF(x, y, width, height);
|
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
||||||
} else {
|
while (m_start_angle >= (360*16)) { m_start_angle -= (360*16); }
|
||||||
m_start_angle -= 270.0 * 16;
|
x = p1.y();
|
||||||
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
y = (p1.x() + m_rect.width()) * (-1);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
p1 = mapFromScene(x, y);
|
||||||
|
m_rect = QRectF(p1.x(), p1.y(), width, height);
|
||||||
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
@@ -202,8 +202,10 @@ void PartArc::flip() {
|
|||||||
m_span_angle = (-1) * m_span_angle;
|
m_span_angle = (-1) * m_span_angle;
|
||||||
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
||||||
while (m_start_angle >= (360*16)) { 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();
|
auto p1 = mapToScene(m_rect.x(),m_rect.y());
|
||||||
m_rect = QRectF(m_rect.x(), y, m_rect.width(), m_rect.height());
|
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();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
emit rectChanged();
|
emit rectChanged();
|
||||||
@@ -214,8 +216,10 @@ void PartArc::mirror() {
|
|||||||
m_span_angle = (-1) * m_span_angle;
|
m_span_angle = (-1) * m_span_angle;
|
||||||
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
while (m_start_angle < 0) { m_start_angle += (360*16); }
|
||||||
while (m_start_angle >= (360*16)) { 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();
|
auto p1 = mapToScene(m_rect.x(),m_rect.y());
|
||||||
m_rect = QRectF(x, m_rect.y(), m_rect.width(), m_rect.height());
|
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();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
emit rectChanged();
|
emit rectChanged();
|
||||||
|
|||||||
@@ -234,19 +234,19 @@ void PartEllipse::setRotation(qreal angle) {
|
|||||||
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
||||||
m_rot = QET::correctAngle(angle, true);
|
m_rot = QET::correctAngle(angle, true);
|
||||||
// idea taken from QET_ElementScaler:
|
// 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) {
|
if (diffAngle > 0) {
|
||||||
qreal width = m_rect.height();
|
x = (p1.y() + m_rect.height()) * (-1);
|
||||||
qreal height = m_rect.width();
|
y = p1.x();
|
||||||
qreal x = (m_rect.y() + m_rect.height()) * (-1);
|
|
||||||
qreal y = m_rect.x();
|
|
||||||
m_rect = QRectF(x, y, width, height);
|
|
||||||
} else {
|
} else {
|
||||||
qreal width = m_rect.height();
|
x = m_rect.y();
|
||||||
qreal height = m_rect.width();
|
y = (m_rect.x() + m_rect.width()) * (-1);
|
||||||
qreal x = m_rect.y();
|
|
||||||
qreal y = (m_rect.x() + m_rect.width()) * (-1);
|
|
||||||
m_rect = QRectF(x, y, width, height);
|
|
||||||
}
|
}
|
||||||
|
p1 = mapFromScene(x, y);
|
||||||
|
m_rect = QRectF(p1.x(), p1.y(), width, height);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
emit rectChanged();
|
emit rectChanged();
|
||||||
@@ -257,16 +257,20 @@ qreal PartEllipse::rotation() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PartEllipse::flip() {
|
void PartEllipse::flip() {
|
||||||
qreal y = ((-1.0) * m_rect.y()) - m_rect.height();
|
auto p1 = mapToScene(m_rect.x(), m_rect.y());
|
||||||
m_rect = QRectF(m_rect.x(), y, m_rect.width(), m_rect.height());
|
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();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
emit rectChanged();
|
emit rectChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PartEllipse::mirror() {
|
void PartEllipse::mirror() {
|
||||||
qreal x = ((-1.0) * m_rect.x()) - m_rect.width();
|
auto p1 = mapToScene(m_rect.x(), m_rect.y());
|
||||||
m_rect = QRectF(x, m_rect.y(), m_rect.width(), m_rect.height());
|
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();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
emit rectChanged();
|
emit rectChanged();
|
||||||
|
|||||||
@@ -574,8 +574,12 @@ void PartLine::setSecondEndLength(const qreal &l)
|
|||||||
void PartLine::setRotation(qreal angle) {
|
void PartLine::setRotation(qreal angle) {
|
||||||
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
||||||
m_rot = QET::correctAngle(angle, true);
|
m_rot = QET::correctAngle(angle, true);
|
||||||
m_line.setP1(QTransform().rotate(diffAngle).map(m_line.p1()));
|
auto p1 = mapToScene(m_line.p1());
|
||||||
m_line.setP2(QTransform().rotate(diffAngle).map(m_line.p2()));
|
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();
|
prepareGeometryChange();
|
||||||
setLine(m_line);
|
setLine(m_line);
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
@@ -587,8 +591,12 @@ qreal PartLine::rotation() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PartLine::flip() {
|
void PartLine::flip() {
|
||||||
m_line.setP1(QPointF(m_line.p1().x(), (-1) * m_line.p1().y()));
|
auto p1 = mapToScene(m_line.p1());
|
||||||
m_line.setP2(QPointF(m_line.p2().x(), (-1) * m_line.p2().y()));
|
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);
|
setLine(m_line);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
@@ -596,8 +604,12 @@ void PartLine::flip() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PartLine::mirror() {
|
void PartLine::mirror() {
|
||||||
m_line.setP1(QPointF((-1) * m_line.p1().x(), m_line.p1().y()));
|
auto p1 = mapToScene(m_line.p1());
|
||||||
m_line.setP2(QPointF((-1) * m_line.p2().x(), m_line.p2().y()));
|
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);
|
setLine(m_line);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
|
|||||||
@@ -292,8 +292,12 @@ void PartPolygon::resetAllHandlerColor()
|
|||||||
void PartPolygon::setRotation(qreal angle) {
|
void PartPolygon::setRotation(qreal angle) {
|
||||||
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
||||||
m_rot = QET::correctAngle(angle, true);
|
m_rot = QET::correctAngle(angle, true);
|
||||||
QTransform rotation = QTransform().rotate(diffAngle);
|
for (auto &pt : m_polygon) {
|
||||||
setPolygon(rotation.map(m_polygon));
|
pt = mapToScene(pt.x(), pt.y());
|
||||||
|
pt = QTransform().rotate(diffAngle).map(pt);
|
||||||
|
pt = mapFromScene(pt.x(), pt.y());
|
||||||
|
}
|
||||||
|
setPolygon(m_polygon);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
emit polygonChanged();
|
emit polygonChanged();
|
||||||
@@ -305,7 +309,9 @@ qreal PartPolygon::rotation() const {
|
|||||||
|
|
||||||
void PartPolygon::flip() {
|
void PartPolygon::flip() {
|
||||||
for (auto &pt : m_polygon) {
|
for (auto &pt : m_polygon) {
|
||||||
|
pt = mapToScene(pt.x(), pt.y());
|
||||||
pt = QPointF(pt.x(), (-1) * pt.y());
|
pt = QPointF(pt.x(), (-1) * pt.y());
|
||||||
|
pt = mapFromScene(pt.x(), pt.y());
|
||||||
}
|
}
|
||||||
setPolygon(m_polygon);
|
setPolygon(m_polygon);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
@@ -315,7 +321,9 @@ void PartPolygon::flip() {
|
|||||||
|
|
||||||
void PartPolygon::mirror() {
|
void PartPolygon::mirror() {
|
||||||
for (auto &pt : m_polygon) {
|
for (auto &pt : m_polygon) {
|
||||||
|
pt = mapToScene(pt.x(), pt.y());
|
||||||
pt = QPointF((-1) * pt.x(), pt.y());
|
pt = QPointF((-1) * pt.x(), pt.y());
|
||||||
|
pt = mapFromScene(pt.x(), pt.y());
|
||||||
}
|
}
|
||||||
setPolygon(m_polygon);
|
setPolygon(m_polygon);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
|
|||||||
@@ -163,22 +163,19 @@ void PartRectangle::setYRadius(qreal Y)
|
|||||||
void PartRectangle::setRotation(qreal angle) {
|
void PartRectangle::setRotation(qreal angle) {
|
||||||
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
||||||
m_rot = QET::correctAngle(angle, true);
|
m_rot = QET::correctAngle(angle, true);
|
||||||
// for whatever reason: with "rect" we need to use scene-positions...
|
auto p1 = mapToScene(m_rect.x(),m_rect.y());
|
||||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
|
||||||
qreal width = m_rect.height();
|
qreal width = m_rect.height();
|
||||||
qreal height = m_rect.width();
|
qreal height = m_rect.width();
|
||||||
qreal x; qreal y;
|
qreal x; qreal y;
|
||||||
if (diffAngle > 0) {
|
if (diffAngle > 0) {
|
||||||
x = (pos.y() + m_rect.height()) * (-1);
|
x = (p1.y() + m_rect.height()) * (-1);
|
||||||
y = pos.x();
|
y = p1.x();
|
||||||
} else {
|
} else {
|
||||||
x = pos.y();
|
x = p1.y();
|
||||||
y = (pos.x() + m_rect.width()) * (-1);
|
y = (p1.x() + m_rect.width()) * (-1);
|
||||||
}
|
}
|
||||||
|
p1 = mapFromScene(x, y);
|
||||||
pos = mapFromScene(x, y);
|
m_rect = QRectF(p1.x(), p1.y(), width, height);
|
||||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
|
||||||
m_rect.setWidth(width); m_rect.setHeight(height);
|
|
||||||
std::swap (m_xRadius, m_yRadius);
|
std::swap (m_xRadius, m_yRadius);
|
||||||
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
@@ -191,13 +188,13 @@ qreal PartRectangle::rotation() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PartRectangle::flip() {
|
void PartRectangle::flip() {
|
||||||
// for whatever reason: with "rect" we need to use scene-positions...
|
auto height = m_rect.height();
|
||||||
qreal height = m_rect.height();
|
auto p1 = mapToScene(m_rect.x(),m_rect.y());
|
||||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
qreal x = p1.x();
|
||||||
qreal x = pos.x();
|
qreal y = ((-1.0) * p1.y()) - height;
|
||||||
qreal y = ((-1.0) * pos.y()) - height;
|
p1 = mapFromScene(x, y);
|
||||||
pos = mapFromScene(x, y);
|
m_rect.setX(p1.x());
|
||||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
m_rect.setY(p1.y());
|
||||||
m_rect.setHeight(height);
|
m_rect.setHeight(height);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
@@ -205,13 +202,13 @@ void PartRectangle::flip() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PartRectangle::mirror() {
|
void PartRectangle::mirror() {
|
||||||
// for whatever reason: with "rect" we need to use scene-positions...
|
auto width = m_rect.width();
|
||||||
qreal width = m_rect.width();
|
auto p1 = mapToScene(m_rect.x(),m_rect.y());
|
||||||
auto pos = mapToScene(m_rect.x(),m_rect.y());
|
qreal x = ((-1.0) * p1.x()) - width;
|
||||||
qreal x = ((-1.0) * pos.x()) - width;
|
qreal y = p1.y();
|
||||||
qreal y = pos.y();
|
p1 = mapFromScene(x, y);
|
||||||
pos = mapFromScene(x, y);
|
m_rect.setX(p1.x());
|
||||||
m_rect.setX(pos.x()); m_rect.setY(pos.y());
|
m_rect.setY(p1.y());
|
||||||
m_rect.setWidth(width);
|
m_rect.setWidth(width);
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
adjustHandlerPos();
|
adjustHandlerPos();
|
||||||
|
|||||||
@@ -158,23 +158,20 @@ void PartTerminal::setRotation(qreal angle) {
|
|||||||
else new_ori = Qet::West;
|
else new_ori = Qet::West;
|
||||||
|
|
||||||
qreal diffAngle = qRound((angle - rotation()) * 100.0) / 100.0;
|
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);
|
setPos(d->m_pos);
|
||||||
setOrientation(new_ori);
|
setOrientation(new_ori);
|
||||||
|
updateSecondPoint();
|
||||||
|
prepareGeometryChange();
|
||||||
emit orientationChanged(); // all terminal-signals call "updateForm"
|
emit orientationChanged(); // all terminal-signals call "updateForm"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief PartTerminal::rotation
|
||||||
|
@return current rotation-angle in degrees
|
||||||
|
*/
|
||||||
qreal PartTerminal::rotation() const {
|
qreal PartTerminal::rotation() const {
|
||||||
switch (d->m_orientation) {
|
switch (d->m_orientation) {
|
||||||
case Qet::North : return 0;
|
case Qet::North : return 0;
|
||||||
@@ -185,9 +182,13 @@ qreal PartTerminal::rotation() const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief PartTerminal::flip
|
||||||
|
turn part upside down
|
||||||
|
*/
|
||||||
void PartTerminal::flip() {
|
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) {
|
switch (d->m_orientation) {
|
||||||
case Qet::North : setOrientation(Qet::South);
|
case Qet::North : setOrientation(Qet::South);
|
||||||
break;
|
break;
|
||||||
@@ -202,8 +203,13 @@ void PartTerminal::flip() {
|
|||||||
emit yChanged(); // all terminal-signals call "updateForm"
|
emit yChanged(); // all terminal-signals call "updateForm"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
@brief PartTerminal::mirror
|
||||||
|
turn part from left to right
|
||||||
|
*/
|
||||||
void PartTerminal::mirror() {
|
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) {
|
switch (d->m_orientation) {
|
||||||
case Qet::North : break;
|
case Qet::North : break;
|
||||||
case Qet::East : setOrientation(Qet::West);
|
case Qet::East : setOrientation(Qet::West);
|
||||||
|
|||||||
Reference in New Issue
Block a user