diff options
Diffstat (limited to 'line.cpp')
| -rw-r--r-- | line.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/line.cpp b/line.cpp new file mode 100644 index 0000000..aa29d43 --- /dev/null +++ b/line.cpp @@ -0,0 +1,52 @@ +#include "line.h" + +Line::Line() + :QLine() +{ + m_selected = true; +} + +Line::Line(const Line &other) + :QLine(other) +{ + m_selected = other.m_selected; +} + +bool Line::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 Line::setSelected(bool selected) +{ + m_selected = selected; +} + +void Line::draw(QPainter *painter) +{ + if(m_selected) + { + QPen penTemp(Qt::DotLine); + penTemp.setColor(Qt::red); + painter->setPen(penTemp); + + painter->drawEllipse(p1(), 5, 5); + painter->drawEllipse(p2(), 5, 5); + } + else + { + QPen penNormal(Qt::SolidLine); + penNormal.setColor(Qt::black); + painter->setPen(penNormal); + } + + painter->drawLine(p1(), p2()); + +} |
