Fri, 01 Jul 2022 16:45:40 +0300
Use different cursors depending on edit mode
--- a/src/gl/partrenderer.cpp Fri Jul 01 13:41:46 2022 +0300 +++ b/src/gl/partrenderer.cpp Fri Jul 01 16:45:40 2022 +0300 @@ -46,7 +46,6 @@ { this->setMouseTracking(true); this->setFocusPolicy(Qt::WheelFocus); - this->setCursor(Qt::CrossCursor); QSurfaceFormat surfaceFormat; surfaceFormat.setSamples(8); this->setFormat(surfaceFormat);
--- a/src/layers/edittools.cpp Fri Jul 01 13:41:46 2022 +0300 +++ b/src/layers/edittools.cpp Fri Jul 01 16:45:40 2022 +0300 @@ -50,6 +50,15 @@ void EditTools::setEditMode(EditingMode newMode) { this->mode = newMode; + switch (this->mode) { + case SelectMode: + Q_EMIT this->suggestCursor(Qt::ArrowCursor); + break; + case DrawMode: + case CircleMode: + Q_EMIT this->suggestCursor(Qt::CrossCursor); + break; + } } void EditTools::setGridMatrix(const glm::mat4& newGridMatrix) @@ -214,18 +223,20 @@ void EditTools::overpaint(QPainter* painter) { painter->save(); - const Pens& pens = (this->renderer->isDark() ? darkPens : brightPens); - this->renderPreview(painter, &pens); - QFont font; - font.setBold(true); - if (this->worldPosition.has_value()) - { - painter->setRenderHint(QPainter::Antialiasing); - painter->setPen(pens.pointPen); - painter->setBrush(pens.greenPolygonBrush); - const QPointF pos = this->renderer->modelToScreenCoordinates(*this->worldPosition); - painter->drawEllipse(pos, 5, 5); - drawBorderedText(painter, pos + QPointF{5, 5}, font, vectorToString(*this->worldPosition)); + if (this->usePolygon()) { + const Pens& pens = (this->renderer->isDark() ? darkPens : brightPens); + this->renderPreview(painter, &pens); + QFont font; + font.setBold(true); + if (this->usePolygon() and this->worldPosition.has_value()) + { + painter->setRenderHint(QPainter::Antialiasing); + painter->setPen(pens.pointPen); + painter->setBrush(pens.greenPolygonBrush); + const QPointF pos = this->renderer->modelToScreenCoordinates(*this->worldPosition); + painter->drawEllipse(pos, 5, 5); + drawBorderedText(painter, pos + QPointF{5, 5}, font, vectorToString(*this->worldPosition)); + } } painter->restore(); } @@ -462,6 +473,18 @@ return result; } +bool EditTools::usePolygon() const +{ + switch (this->mode) { + case SelectMode: + return false; + case DrawMode: + case CircleMode: + return true; + } + return {}; +} + void EditTools::closeShape() { for (const ModelAction& action : this->modelActions()) {
--- a/src/layers/edittools.h Fri Jul 01 13:41:46 2022 +0300 +++ b/src/layers/edittools.h Fri Jul 01 16:45:40 2022 +0300 @@ -62,6 +62,7 @@ void newStatusText(const QString& newStatusText); void modelAction(const ModelAction& action); void select(const QSet<ElementId>& ids, bool retain); + void suggestCursor(const QCursor& cursor); protected: void mvpMatrixChanged(const glm::mat4& matrix) override; void mouseMoved(const QMouseEvent* event) override; @@ -71,6 +72,7 @@ const std::vector<ModelAction> modelActions() const; const std::vector<ModelAction> circleModeActions() const; const std::vector<ModelAction> drawModeActions() const; + bool usePolygon() const; void closeShape(); void renderPreview(QPainter* painter, const void* pensptr); void removeLastPoint();
--- a/src/main.cpp Fri Jul 01 13:41:46 2022 +0300 +++ b/src/main.cpp Fri Jul 01 16:45:40 2022 +0300 @@ -570,6 +570,12 @@ } }); QObject::connect(data->canvas.get(), &PartRenderer::message, &messageLog, &MessageLog::addMessage); + QObject::connect( + data->tools.get(), + &EditTools::suggestCursor, + data->canvas.get(), + &QWidget::setCursor); + data->tools->setEditMode(SelectMode); const QFileInfo fileInfo{*documents.modelPath(modelId)}; auto* const subWindow = createSubWindow<ModelSubWindow>(ui.mdiArea, modelId); subWindow->setMinimumSize({96, 96});