src/editmodes/lineLoopMode.cpp

changeset 875
ce8e9b37d44f
parent 874
ba75c789667e
equal deleted inserted replaced
874:ba75c789667e 875:ce8e9b37d44f
1 #include "lineLoopMode.h" 1 #include "lineLoopMode.h"
2 #include "../glRenderer.h" 2 #include "../glRenderer.h"
3 #include "../mainWindow.h"
4 #include <QKeyEvent>
3 5
4 LineLoopMode::LineLoopMode (GLRenderer *renderer) : 6 LineLoopMode::LineLoopMode (GLRenderer *renderer) :
5 Super (renderer) {} 7 Super (renderer) {}
6 8
7 void LineLoopMode::render (QPainter& painter) const 9 void LineLoopMode::render (QPainter& painter) const
8 { 10 {
9 renderer()->drawBlip (painter, renderer()->coordconv3_2 (renderer()->position3D()));
10 QVector<QPointF> points; 11 QVector<QPointF> points;
12 QList<Vertex> points3d (m_drawedVerts);
13 points3d << renderer()->position3D();
11 14
12 for (Vertex const& vrt : m_drawedVerts) 15 for (Vertex const& vrt : points3d)
13 points << renderer()->coordconv3_2 (vrt); 16 points << renderer()->coordconv3_2 (vrt);
14 17
15 painter.setPen (renderer()->textPen()); 18 painter.setPen (renderer()->textPen());
19 assert (points.size() == points3d.size());
16 20
17 for (int i = 0; i < points.size() - 1; ++i) 21 for (int i = 0; i < points.size() - 1; ++i)
22 {
18 painter.drawLine (QLineF (points[i], points[i + 1])); 23 painter.drawLine (QLineF (points[i], points[i + 1]));
24 drawLength (painter, points3d[i], points3d[i + 1], points[i], points[i + 1]);
25 }
19 26
20 for (QPointF const& point : points) 27 for (QPointF const& point : points)
21 renderer()->drawBlip (painter, point); 28 renderer()->drawBlip (painter, point);
22 } 29 }
23 30
32 return true; 39 return true;
33 } 40 }
34 41
35 return false; 42 return false;
36 } 43 }
44
45 bool LineLoopMode::preAddVertex (Vertex const& pos)
46 {
47 // If we picked an the last vertex, stop drawing
48 if (not m_drawedVerts.isEmpty() and pos == m_drawedVerts.last())
49 {
50 endDraw();
51 return true;
52 }
53
54 return false;
55 }
56
57 void LineLoopMode::endDraw()
58 {
59 LDObjectList objs;
60
61 for (int i = 0; i < m_drawedVerts.size() - 1; ++i)
62 {
63 LDLinePtr line = LDSpawn<LDLine>();
64 line->setVertex (0, m_drawedVerts[i]);
65 line->setVertex (1, m_drawedVerts[i + 1]);
66 objs << line;
67 }
68
69 finishDraw (objs);
70 }
71
72 bool LineLoopMode::keyReleased (QKeyEvent* ev)
73 {
74 if (Super::keyReleased (ev))
75 return true;
76
77 if (ev->key() == Qt::Key_Enter or ev->key() == Qt::Key_Return)
78 {
79 endDraw();
80 return true;
81 }
82
83 return false;
84 }

mercurial