src/layers/edittools.cpp

changeset 311
fab454611f9b
parent 310
5d6639a9607f
child 312
2637134bc37c
equal deleted inserted replaced
310:5d6639a9607f 311:fab454611f9b
48 } 48 }
49 49
50 void EditTools::setEditMode(EditingMode newMode) 50 void EditTools::setEditMode(EditingMode newMode)
51 { 51 {
52 this->mode = newMode; 52 this->mode = newMode;
53 switch (this->mode) {
54 case SelectMode:
55 Q_EMIT this->suggestCursor(Qt::ArrowCursor);
56 break;
57 case DrawMode:
58 case CircleMode:
59 Q_EMIT this->suggestCursor(Qt::CrossCursor);
60 break;
61 }
53 } 62 }
54 63
55 void EditTools::setGridMatrix(const glm::mat4& newGridMatrix) 64 void EditTools::setGridMatrix(const glm::mat4& newGridMatrix)
56 { 65 {
57 this->gridMatrix = newGridMatrix; 66 this->gridMatrix = newGridMatrix;
212 }; 221 };
213 222
214 void EditTools::overpaint(QPainter* painter) 223 void EditTools::overpaint(QPainter* painter)
215 { 224 {
216 painter->save(); 225 painter->save();
217 const Pens& pens = (this->renderer->isDark() ? darkPens : brightPens); 226 if (this->usePolygon()) {
218 this->renderPreview(painter, &pens); 227 const Pens& pens = (this->renderer->isDark() ? darkPens : brightPens);
219 QFont font; 228 this->renderPreview(painter, &pens);
220 font.setBold(true); 229 QFont font;
221 if (this->worldPosition.has_value()) 230 font.setBold(true);
222 { 231 if (this->usePolygon() and this->worldPosition.has_value())
223 painter->setRenderHint(QPainter::Antialiasing); 232 {
224 painter->setPen(pens.pointPen); 233 painter->setRenderHint(QPainter::Antialiasing);
225 painter->setBrush(pens.greenPolygonBrush); 234 painter->setPen(pens.pointPen);
226 const QPointF pos = this->renderer->modelToScreenCoordinates(*this->worldPosition); 235 painter->setBrush(pens.greenPolygonBrush);
227 painter->drawEllipse(pos, 5, 5); 236 const QPointF pos = this->renderer->modelToScreenCoordinates(*this->worldPosition);
228 drawBorderedText(painter, pos + QPointF{5, 5}, font, vectorToString(*this->worldPosition)); 237 painter->drawEllipse(pos, 5, 5);
238 drawBorderedText(painter, pos + QPointF{5, 5}, font, vectorToString(*this->worldPosition));
239 }
229 } 240 }
230 painter->restore(); 241 painter->restore();
231 } 242 }
232 243
233 const std::vector<ModelAction> EditTools::modelActions() const 244 const std::vector<ModelAction> EditTools::modelActions() const
460 } 471 }
461 } 472 }
462 return result; 473 return result;
463 } 474 }
464 475
476 bool EditTools::usePolygon() const
477 {
478 switch (this->mode) {
479 case SelectMode:
480 return false;
481 case DrawMode:
482 case CircleMode:
483 return true;
484 }
485 return {};
486 }
487
465 void EditTools::closeShape() 488 void EditTools::closeShape()
466 { 489 {
467 for (const ModelAction& action : this->modelActions()) { 490 for (const ModelAction& action : this->modelActions()) {
468 Q_EMIT this->modelAction(action); 491 Q_EMIT this->modelAction(action);
469 } 492 }

mercurial