summaryrefslogtreecommitdiffstats
path: root/polygon.cpp
diff options
context:
space:
mode:
authorStefan Suhren <suhren.stefan@fh-swf.de>2015-05-31 22:55:45 +0200
committerStefan Suhren <suhren.stefan@fh-swf.de>2015-05-31 22:55:45 +0200
commit45813562e266cf8e58ea9cb04f655bbb542a555e (patch)
treec8864c50a1bd84ec8f2e8e527e71c9825fabf92a /polygon.cpp
parent16cdefa1a8546d23efc357010e62c7c031319e56 (diff)
downloadGUI_SS2015-45813562e266cf8e58ea9cb04f655bbb542a555e.tar.gz
GUI_SS2015-45813562e266cf8e58ea9cb04f655bbb542a555e.zip
Make every line subclass editable
Diffstat (limited to 'polygon.cpp')
-rw-r--r--polygon.cpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/polygon.cpp b/polygon.cpp
index a292653..d8b71b7 100644
--- a/polygon.cpp
+++ b/polygon.cpp
@@ -3,21 +3,14 @@
Polygon::Polygon()
: Line()
{
- m_polygon.append(QPoint(0,0));
- m_polygon.append(QPoint(0,0));
- m_polygon.append(QPoint(0,0));
+ m_polygon.append(QPoint(10, 50));
+ m_polygon.append(QPoint(30, 70));
+ m_polygon.append(QPoint(50, 50));
}
bool Polygon::isHit(const QPoint &clickPoint)
{
- QVector3D a(p2() - p1());
- QVector3D r1(p1());
-
- QVector3D rq(clickPoint);
-
- float dist = rq.distanceToLine(r1, a.normalized());
-
- return dist < 5;
+ return m_polygon.containsPoint(clickPoint, Qt::OddEvenFill);
}
void Polygon::draw(QPainter *painter)
@@ -28,9 +21,9 @@ void Polygon::draw(QPainter *painter)
penTemp.setColor(Qt::red);
painter->setPen(penTemp);
- painter->drawEllipse(p1(), 5, 5);
- painter->drawEllipse(p2(), 5, 5);
- painter->drawEllipse(QPoint(p1().rx() + 20, p1().ry() - 20), 5, 5);
+ painter->drawEllipse(m_polygon.point(0), 5, 5);
+ painter->drawEllipse(m_polygon.point(1), 5, 5);
+ painter->drawEllipse(m_polygon.point(2), 5, 5);
}
else
{
@@ -39,9 +32,33 @@ void Polygon::draw(QPainter *painter)
painter->setPen(penNormal);
}
- m_polygon.replace(0, p1());
- m_polygon.replace(1, p2());
- m_polygon.replace(2, QPoint(p1().rx() + 20, p1().ry() - 20));
-
painter->drawPolygon(m_polygon);
}
+
+
+void Polygon::move(const QPoint &oldPoint, const QPoint &newPoint)
+{
+ if(m_selected)
+ {
+ QPoint offset = newPoint - oldPoint;
+ QVector3D vecOld(oldPoint);
+ if(vecOld.distanceToPoint(QVector3D(m_polygon.point(0))) < 5)
+ {
+ m_polygon.replace(0, m_polygon.point(0) + offset);
+ }
+ else if(vecOld.distanceToPoint(QVector3D(m_polygon.point(1))) < 5)
+ {
+ m_polygon.replace(1, m_polygon.point(1) + offset);
+ }
+ else if(vecOld.distanceToPoint(QVector3D(m_polygon.point(2))) < 5)
+ {
+ m_polygon.replace(2, m_polygon.point(2) + offset);
+ }
+ else
+ {
+ m_polygon.replace(0, m_polygon.point(0) + offset);
+ m_polygon.replace(1, m_polygon.point(1) + offset);
+ m_polygon.replace(2, m_polygon.point(2) + offset);
+ }
+ }
+}