summaryrefslogtreecommitdiffstats
path: root/rectangle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rectangle.cpp')
-rw-r--r--rectangle.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/rectangle.cpp b/rectangle.cpp
new file mode 100644
index 0000000..f07651c
--- /dev/null
+++ b/rectangle.cpp
@@ -0,0 +1,42 @@
+#include "rectangle.h"
+
+Rectangle::Rectangle()
+ : Line()
+{
+
+}
+
+bool Rectangle::isHit(const QPoint &clickPoint)
+{
+ QVector3D a(p2() - p1());
+ QVector3D r1(p1());
+
+ QVector3D rq(clickPoint);
+
+ float dist = rq.distanceToLine(r1, a.normalized());
+
+ return dist < 5;
+}
+
+void Rectangle::draw(QPainter *painter)
+{
+ if (m_selected)
+ {
+ QPen penTemp(Qt::DotLine);
+ penTemp.setColor(Qt::red);
+ painter->setPen(penTemp);
+
+ painter->drawEllipse(p1(), 5, 5);
+ painter->drawEllipse(QPoint(p1().rx() + (p2().rx() - p1().rx()), p1().ry()), 5, 5);
+ painter->drawEllipse(QPoint(p1().rx(), p1().ry() + (p2().ry() - p1().ry())), 5, 5);
+ painter->drawEllipse(p2(), 5, 5);
+ }
+ else
+ {
+ QPen penNormal(Qt::SolidLine);
+ penNormal.setColor(Qt::black);
+ painter->setPen(penNormal);
+ }
+
+ painter->drawRect(QRect(p1(), p2()));
+}