Commit 55630280 authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Get control points working

parent 81df344c
...@@ -48,8 +48,15 @@ void Shape2D::draw(QPainter &painter) const { ...@@ -48,8 +48,15 @@ void Shape2D::draw(QPainter &painter) const {
painter.setPen(QPen(m_color, 0)); painter.setPen(QPen(m_color, 0));
this->drawShape(painter); this->drawShape(painter);
if (m_editing || m_selected) { if (m_editing || m_selected) {
auto center = m_boundingRect.center();
QRectF drawRect = m_boundingRect.translated(-center).toQRectF();
painter.save();
double rotation = 20;
painter.rotate(rotation);
painter.translate(QTransform().rotate(-rotation).map(center));
painter.setPen(QPen(QColor(255, 255, 255, 100), 0)); painter.setPen(QPen(QColor(255, 255, 255, 100), 0));
painter.drawRect(m_boundingRect.toQRectF()); painter.drawRect(drawRect);
painter.restore();
size_t np = NCommonCP; size_t np = NCommonCP;
double rsize = 2; double rsize = 2;
int alpha = 100; int alpha = 100;
...@@ -90,8 +97,13 @@ QPointF Shape2D::getControlPoint(size_t i) const { ...@@ -90,8 +97,13 @@ QPointF Shape2D::getControlPoint(size_t i) const {
throw std::range_error("Control point index is out of range"); throw std::range_error("Control point index is out of range");
} }
if (i < 4) if (i < 4) {
return m_boundingRect.vertex(i); auto center = m_boundingRect.center();
QPointF vertex = m_boundingRect.vertex(i);
double rotation = 20;
vertex = QTransform().rotate(rotation).map(vertex-center)+center;
return vertex;
}
return getShapeControlPoint(i - NCommonCP); return getShapeControlPoint(i - NCommonCP);
} }
...@@ -102,7 +114,9 @@ void Shape2D::setControlPoint(size_t i, const QPointF &pos) { ...@@ -102,7 +114,9 @@ void Shape2D::setControlPoint(size_t i, const QPointF &pos) {
} }
if (i < 4) { if (i < 4) {
m_boundingRect.setVertex(i, pos); auto center = m_boundingRect.center();
double rotation = 20;
m_boundingRect.setVertex(i, QTransform().rotate(-rotation).map(pos-center)+center);
refit(); refit();
} }
...@@ -395,7 +409,9 @@ Shape2DRectangle::Shape2DRectangle(const QPointF &p0, const QSizeF &size) { ...@@ -395,7 +409,9 @@ Shape2DRectangle::Shape2DRectangle(const QPointF &p0, const QSizeF &size) {
bool Shape2DRectangle::selectAt(const QPointF &p) const { bool Shape2DRectangle::selectAt(const QPointF &p) const {
if (m_fill_color != QColor()) { // filled rectangle if (m_fill_color != QColor()) { // filled rectangle
return contains(p); auto center = m_boundingRect.center();
double rotation = 20;
return contains(QTransform().rotate(-rotation).map(p-center)+center);
} }
RectF outer(m_boundingRect); RectF outer(m_boundingRect);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment