src/editmodes/circlemode.cc

changeset 827
82469b40567e
parent 825
f7649c9bfd9a
child 829
bb903e89e23c
equal deleted inserted replaced
826:d7a21e4a4ec3 827:82469b40567e
3 #include "../miscallenous.h" 3 #include "../miscallenous.h"
4 #include "../ldObject.h" 4 #include "../ldObject.h"
5 #include "../ldDocument.h" 5 #include "../ldDocument.h"
6 #include "../misc/ringFinder.h" 6 #include "../misc/ringFinder.h"
7 #include "../primitives.h" 7 #include "../primitives.h"
8 #include "../glRenderer.h"
8 9
9 CircleMode::CircleMode (GLRenderer* renderer) : 10 CircleMode::CircleMode (GLRenderer* renderer) :
10 Super (renderer) {} 11 Super (renderer) {}
12
13 EditModeType CircleMode::type() const
14 {
15 return EditModeType::Circle;
16 }
11 17
12 double CircleMode::getCircleDrawDist (int pos) const 18 double CircleMode::getCircleDrawDist (int pos) const
13 { 19 {
14 assert (_drawedVerts.size() >= pos + 1); 20 assert (_drawedVerts.size() >= pos + 1);
15 Vertex v1 = (_drawedVerts.size() >= pos + 2) ? _drawedVerts[pos + 1] : 21 Vertex v1 = (_drawedVerts.size() >= pos + 2) ? _drawedVerts[pos + 1] :
148 finishDraw (objs); 154 finishDraw (objs);
149 } 155 }
150 156
151 void CircleMode::render (QPainter& painter) const 157 void CircleMode::render (QPainter& painter) const
152 { 158 {
153 QFontMetrics const metrics (QFont()); 159 QFontMetrics metrics = QFontMetrics (QFont());
154 160
155 // If we have not specified the center point of the circle yet, preview it on the screen. 161 // If we have not specified the center point of the circle yet, preview it on the screen.
156 if (_drawedVerts.isEmpty()) 162 if (_drawedVerts.isEmpty())
157 { 163 {
158 renderer()->drawBlip (painter, renderer()->coordconv3_2 (renderer()->position3D())); 164 renderer()->drawBlip (painter, renderer()->coordconv3_2 (renderer()->position3D()));
221 painter.setPen (Qt::NoPen); 227 painter.setPen (Qt::NoPen);
222 painter.drawPolygon (QPolygon (ringpoints)); 228 painter.drawPolygon (QPolygon (ringpoints));
223 229
224 // Draw the circles 230 // Draw the circles
225 painter.setBrush (Qt::NoBrush); 231 painter.setBrush (Qt::NoBrush);
226 painter.setPen (renderer()->getLinePen()); 232 painter.setPen (renderer()->linePen());
227 painter.drawPolygon (QPolygon (circlepoints)); 233 painter.drawPolygon (QPolygon (circlepoints));
228 painter.drawPolygon (QPolygon (circle2points)); 234 painter.drawPolygon (QPolygon (circle2points));
229 235
230 // Draw the current radius in the middle of the circle. 236 // Draw the current radius in the middle of the circle.
231 QPoint origin = renderer()->coordconv3_2 (_drawedVerts[0]); 237 QPoint origin = renderer()->coordconv3_2 (_drawedVerts[0]);
232 QString label = QString::number (dist0); 238 QString label = QString::number (dist0);
233 painter.setPen (renderer()->getTextPen()); 239 painter.setPen (renderer()->textPen());
234 painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label); 240 painter.drawText (origin.x() - (metrics.width (label) / 2), origin.y(), label);
235 241
236 if (_drawedVerts.size() >= 2) 242 if (_drawedVerts.size() >= 2)
237 { 243 {
238 painter.drawText (origin.x() - (metrics.width (label) / 2), 244 painter.drawText (origin.x() - (metrics.width (label) / 2),
244 bool CircleMode::mouseReleased (MouseEventData const& data) 250 bool CircleMode::mouseReleased (MouseEventData const& data)
245 { 251 {
246 if (Super::mouseReleased (data)) 252 if (Super::mouseReleased (data))
247 return true; 253 return true;
248 254
249 if (_drawedVerts.size() < 3) 255 if (data.releasedButtons & Qt::LeftButton)
250 { 256 {
251 addDrawnVertex (renderer()->position3D()); 257 if (_drawedVerts.size() < 3)
252 return; 258 addDrawnVertex (renderer()->position3D());
253 } 259 else
254 260 buildCircle();
255 buildCircle(); 261
256 } 262 return true;
263 }
264
265 return false;
266 }

mercurial