93 bool AbstractDrawMode::mouseReleased(MouseEventData const& data) |
93 bool AbstractDrawMode::mouseReleased(MouseEventData const& data) |
94 { |
94 { |
95 if (Super::mouseReleased(data)) |
95 if (Super::mouseReleased(data)) |
96 return true; |
96 return true; |
97 |
97 |
98 if ((data.releasedButtons & Qt::MidButton) and (m_drawedVerts.size() < 4) and (not data.mouseMoved)) |
98 if ((data.releasedButtons & Qt::MidButton) and (length(m_drawedVerts) < 4) and (not data.mouseMoved)) |
99 { |
99 { |
100 // Find the closest vertex to our cursor |
100 // Find the closest vertex to our cursor |
101 double minimumDistance = 1024.0; |
101 double minimumDistance = 1024.0; |
102 const Vertex* closest = nullptr; |
102 const Vertex* closest = nullptr; |
103 Vertex cursorPosition = renderer()->convert2dTo3d (data.ev->pos(), false); |
103 Vertex cursorPosition = renderer()->convert2dTo3d (data.ev->pos(), false); |
167 |
167 |
168 void AbstractDrawMode::finishDraw(LDObjectList const& objs) |
168 void AbstractDrawMode::finishDraw(LDObjectList const& objs) |
169 { |
169 { |
170 int pos = m_window->suggestInsertPoint(); |
170 int pos = m_window->suggestInsertPoint(); |
171 |
171 |
172 if (objs.size() > 0) |
172 if (length(objs) > 0) |
173 { |
173 { |
174 for (LDObject* obj : objs) |
174 for (LDObject* obj : objs) |
175 { |
175 { |
176 renderer()->document()->insertObject (pos++, obj); |
176 renderer()->document()->insertObject (pos++, obj); |
177 renderer()->compileObject (obj); |
177 renderer()->compileObject (obj); |
196 } |
196 } |
197 |
197 |
198 void AbstractDrawMode::renderPolygon(QPainter& painter, const QVector<Vertex>& polygon3d, |
198 void AbstractDrawMode::renderPolygon(QPainter& painter, const QVector<Vertex>& polygon3d, |
199 bool drawLineLengths, bool drawAngles ) const |
199 bool drawLineLengths, bool drawAngles ) const |
200 { |
200 { |
201 QVector<QPoint> polygon2d (polygon3d.size()); |
201 QVector<QPoint> polygon2d (length(polygon3d)); |
202 QFontMetrics metrics = QFontMetrics(QFont()); |
202 QFontMetrics metrics = QFontMetrics(QFont()); |
203 |
203 |
204 // Convert to 2D |
204 // Convert to 2D |
205 for (int i = 0; i < polygon3d.size(); ++i) |
205 for (int i = 0; i < length(polygon3d); ++i) |
206 polygon2d[i] = renderer()->convert3dTo2d(polygon3d[i]); |
206 polygon2d[i] = renderer()->convert3dTo2d(polygon3d[i]); |
207 |
207 |
208 // Draw the polygon-to-be |
208 // Draw the polygon-to-be |
209 painter.setBrush(m_polybrush); |
209 painter.setBrush(m_polybrush); |
210 painter.drawPolygon(QPolygonF{polygon2d}); |
210 painter.drawPolygon(QPolygonF{polygon2d}); |
211 |
211 |
212 // Draw vertex blips |
212 // Draw vertex blips |
213 for (int i = 0; i < polygon3d.size(); ++i) |
213 for (int i = 0; i < length(polygon3d); ++i) |
214 { |
214 { |
215 renderer()->drawPoint(painter, polygon2d[i]); |
215 renderer()->drawPoint(painter, polygon2d[i]); |
216 renderer()->drawBlipCoordinates(painter, polygon3d[i], polygon2d[i]); |
216 renderer()->drawBlipCoordinates(painter, polygon3d[i], polygon2d[i]); |
217 } |
217 } |
218 |
218 |
219 // Draw line lenghts and angle info if appropriate |
219 // Draw line lenghts and angle info if appropriate |
220 if (polygon3d.size() >= 2 and (drawLineLengths or drawAngles)) |
220 if (length(polygon3d) >= 2 and (drawLineLengths or drawAngles)) |
221 { |
221 { |
222 painter.setPen (renderer()->textPen()); |
222 painter.setPen (renderer()->textPen()); |
223 |
223 |
224 for (int i = 0; i < polygon3d.size(); ++i) |
224 for (int i = 0; i < length(polygon3d); ++i) |
225 { |
225 { |
226 int j = (i + 1) % polygon3d.size(); |
226 int j = (i + 1) % length(polygon3d); |
227 int prior = (i - 1 >= 0) ? (i - 1) : (polygon3d.size() - 1); |
227 int prior = (i - 1 >= 0) ? (i - 1) : (length(polygon3d) - 1); |
228 |
228 |
229 if (drawLineLengths) |
229 if (drawLineLengths) |
230 drawLineLength(painter, polygon3d[i], polygon3d[j], polygon2d[i], polygon2d[j]); |
230 drawLineLength(painter, polygon3d[i], polygon3d[j], polygon2d[i], polygon2d[j]); |
231 |
231 |
232 if (drawAngles and m_config->drawAngles()) |
232 if (drawAngles and m_config->drawAngles()) |