diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-16 23:41:43 +0200 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-05-16 23:41:43 +0200 |
| commit | 1faecafbc6cc74daa8d0a781c0b54f2c778b04b0 (patch) | |
| tree | 75e3915d245ead47b0e03ef6b544c714b4145cef /line.cpp | |
| parent | 1f1550f77e33bf32eb715eb62dd68751c07f9c0e (diff) | |
| download | GUI_SS2015-1faecafbc6cc74daa8d0a781c0b54f2c778b04b0.tar.gz GUI_SS2015-1faecafbc6cc74daa8d0a781c0b54f2c778b04b0.zip | |
Add 2d drawing for lines.
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()); + +} |
