src/editmodes/drawMode.cc

changeset 861
83426c5fa732
parent 844
11587d419d2f
child 866
4951b737f8cb
equal deleted inserted replaced
860:a496e72af069 861:83426c5fa732
33 void DrawMode::render (QPainter& painter) const 33 void DrawMode::render (QPainter& painter) const
34 { 34 {
35 QVector<Vertex> poly; 35 QVector<Vertex> poly;
36 QFontMetrics metrics = QFontMetrics (QFont()); 36 QFontMetrics metrics = QFontMetrics (QFont());
37 37
38 for (Vertex const& vert : _drawedVerts) 38 for (Vertex const& vert : m_drawedVerts)
39 poly << vert; 39 poly << vert;
40 40
41 // Draw the cursor vertex as the last one in the list. 41 // Draw the cursor vertex as the last one in the list.
42 if (poly.size() < 4) 42 if (poly.size() < 4)
43 poly << renderer()->position3D(); 43 poly << renderer()->position3D();
46 } 46 }
47 47
48 bool DrawMode::preAddVertex (Vertex const& pos) 48 bool DrawMode::preAddVertex (Vertex const& pos)
49 { 49 {
50 // If we picked an already-existing vertex, stop drawing 50 // If we picked an already-existing vertex, stop drawing
51 for (Vertex& vert : _drawedVerts) 51 for (Vertex& vert : m_drawedVerts)
52 { 52 {
53 if (vert == pos) 53 if (vert == pos)
54 { 54 {
55 endDraw(); 55 endDraw();
56 return true; 56 return true;
66 return true; 66 return true;
67 67
68 if (data.releasedButtons & Qt::LeftButton) 68 if (data.releasedButtons & Qt::LeftButton)
69 { 69 {
70 // If we have 4 verts, stop drawing. 70 // If we have 4 verts, stop drawing.
71 if (_drawedVerts.size() >= 4) 71 if (m_drawedVerts.size() >= 4)
72 { 72 {
73 endDraw(); 73 endDraw();
74 return true; 74 return true;
75 } 75 }
76 76
82 } 82 }
83 83
84 void DrawMode::endDraw() 84 void DrawMode::endDraw()
85 { 85 {
86 // Clean the selection and create the object 86 // Clean the selection and create the object
87 QList<Vertex>& verts = _drawedVerts; 87 QList<Vertex>& verts = m_drawedVerts;
88 LDObjectList objs; 88 LDObjectList objs;
89 89
90 switch (verts.size()) 90 switch (verts.size())
91 { 91 {
92 case 1: 92 case 1:
93 { 93 {
94 // 1 vertex - add a vertex object 94 // 1 vertex - add a vertex object
95 LDVertexPtr obj = spawn<LDVertex>(); 95 LDVertexPtr obj = LDSpawn<LDVertex>();
96 obj->pos = verts[0]; 96 obj->pos = verts[0];
97 obj->setColor (maincolor()); 97 obj->setColor (MainColor());
98 objs << obj; 98 objs << obj;
99 break; 99 break;
100 } 100 }
101 101
102 case 2: 102 case 2:
103 { 103 {
104 // 2 verts - make a line 104 // 2 verts - make a line
105 LDLinePtr obj = spawn<LDLine> (verts[0], verts[1]); 105 LDLinePtr obj = LDSpawn<LDLine> (verts[0], verts[1]);
106 obj->setColor (edgecolor()); 106 obj->setColor (EdgeColor());
107 objs << obj; 107 objs << obj;
108 break; 108 break;
109 } 109 }
110 110
111 case 3: 111 case 3:
112 case 4: 112 case 4:
113 { 113 {
114 LDObjectPtr obj = (verts.size() == 3) ? 114 LDObjectPtr obj = (verts.size() == 3) ?
115 static_cast<LDObjectPtr> (spawn<LDTriangle>()) : 115 static_cast<LDObjectPtr> (LDSpawn<LDTriangle>()) :
116 static_cast<LDObjectPtr> (spawn<LDQuad>()); 116 static_cast<LDObjectPtr> (LDSpawn<LDQuad>());
117 117
118 obj->setColor (maincolor()); 118 obj->setColor (MainColor());
119 119
120 for (int i = 0; i < verts.size(); ++i) 120 for (int i = 0; i < verts.size(); ++i)
121 obj->setVertex (i, verts[i]); 121 obj->setVertex (i, verts[i]);
122 122
123 objs << obj; 123 objs << obj;

mercurial