diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index e13907407..de93e055c 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -92,6 +92,7 @@ MainWindow::MainWindow(QWidget *parent) sceneDraw = new VMainGraphicsScene(); currentScene = sceneDraw; qApp->setCurrentScene(currentScene); + connect(this, &MainWindow::EnableItemMove, sceneDraw, &VMainGraphicsScene::EnableItemMove); connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); sceneDetails = new VMainGraphicsScene(); connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); @@ -244,7 +245,9 @@ void MainWindow::ActionNewPP() sceneDraw->addItem(spoint); ui->view->itemClicked(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); + connect(sceneDraw, &VMainGraphicsScene::DisableItem, spoint, &VToolSinglePoint::Disable); connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); + connect(sceneDraw, &VMainGraphicsScene::EnableToolMove, spoint, &VToolSinglePoint::EnableToolMove); QHash* tools = doc->getTools(); SCASSERT(tools != nullptr); tools->insert(id, spoint); @@ -1046,114 +1049,75 @@ void MainWindow::CancelTool() ui->actionArrowTool->setChecked(false); helpLabel->setText(""); ui->actionStopTool->setEnabled(true); - break; + emit EnableItemMove(false); + return; case Tool::SinglePoint: Q_UNREACHABLE(); //Nothing to do here because we can't create this tool from main window. break; case Tool::EndLine: ui->toolButtonEndLine->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::Line: ui->toolButtonLine->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearFocus(); break; case Tool::AlongLine: ui->toolButtonAlongLine->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::ShoulderPoint: ui->toolButtonShoulderPoint->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::Normal: ui->toolButtonNormal->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::Bisector: ui->toolButtonBisector->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::LineIntersect: ui->toolButtonLineIntersect->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::Spline: ui->toolButtonSpline->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::Arc: ui->toolButtonArc->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::SplinePath: ui->toolButtonSplinePath->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::PointOfContact: ui->toolButtonPointOfContact->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::Detail: ui->toolButtonNewDetail->setChecked(false); break; case Tool::Height: ui->toolButtonHeight->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::Triangle: ui->toolButtonTriangle->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::PointOfIntersection: ui->toolButtonPointOfIntersection->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::CutSpline: ui->toolButtonSplineCutPoint->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::CutSplinePath: ui->toolButtonSplinePathCutPoint->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::UnionDetails: ui->toolButtonUnionDetails->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::CutArc: ui->toolButtonArcCutPoint->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::LineIntersectAxis: ui->toolButtonLineIntersectAxis->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::CurveIntersectAxis: ui->toolButtonCurveIntersectAxis->setChecked(false); ui->toolButtonArcIntersectAxis->setChecked(false); - currentScene->setFocus(Qt::OtherFocusReason); - currentScene->clearSelection(); break; case Tool::NodePoint: case Tool::NodeArc: @@ -1163,6 +1127,9 @@ void MainWindow::CancelTool() qDebug()<<"Got wrong tool type. Ignored."; break; } + currentScene->setFocus(Qt::OtherFocusReason); + currentScene->clearSelection(); + emit EnableItemMove(true); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 20f1dc927..3e1a2c210 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -139,6 +139,7 @@ signals: void ModelChosen(QVector listDetails, const QString &curFile, const QString &description); void RefreshHistory(); + void EnableItemMove(bool move); protected: virtual void keyPressEvent(QKeyEvent *event); virtual void showEvent(QShowEvent *event); diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 597399843..608599c1d 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -206,6 +206,13 @@ void VDrawTool::SetFactor(qreal factor) VApplication::CheckFactor(this->factor, factor); } +//--------------------------------------------------------------------------------------------------------------------- +void VDrawTool::EnableToolMove(bool move) +{ + Q_UNUSED(move) + // Do nothing. +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief CheckFormula check formula. diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index 021387e20..d76e5c99f 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -69,6 +69,7 @@ public slots: virtual void FullUpdateFromGuiOk(int result); virtual void FullUpdateFromGuiApply(); virtual void SetFactor(qreal factor); + virtual void EnableToolMove(bool move); protected: /** @brief ignoreFullUpdate ignore or not full updates. */ diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index d082ddd20..28753d1a2 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -216,6 +216,7 @@ void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { Q_UNUSED(event); this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor)); + QGraphicsEllipseItem::hoverLeaveEvent(event); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 003d7b3a5..0948cecc1 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -205,7 +205,10 @@ void VToolSinglePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { VToolPoint::hoverEnterEvent(event); - VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1); + if (flags() & QGraphicsItem::ItemIsMovable) + { + VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -213,16 +216,22 @@ void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { VToolPoint::hoverLeaveEvent(event); - //Disable cursor-arrow-openhand - VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png")); + if (flags() & QGraphicsItem::ItemIsMovable) + { + //Disable cursor-arrow-openhand + VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png")); + } } //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + if (flags() & QGraphicsItem::ItemIsMovable) { - VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1); + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + { + VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1); + } } VToolPoint::mousePressEvent(event); } @@ -230,10 +239,13 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + if (flags() & QGraphicsItem::ItemIsMovable) { - //Disable cursor-arrow-closehand - VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png")); + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) + { + //Disable cursor-arrow-closehand + VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png")); + } } VToolPoint::mouseReleaseEvent(event); } @@ -332,3 +344,9 @@ void VToolSinglePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event, false); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::EnableToolMove(bool move) +{ + this->setFlag(QGraphicsItem::ItemIsMovable, move); +} diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index 833365a9b..9ecdf2c28 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -50,6 +50,7 @@ public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); + virtual void EnableToolMove(bool move); signals: /** * @brief FullUpdateTree handle if need update pattern file. diff --git a/src/app/widgets/vmaingraphicsscene.cpp b/src/app/widgets/vmaingraphicsscene.cpp index 7ecad701f..0d4b77150 100644 --- a/src/app/widgets/vmaingraphicsscene.cpp +++ b/src/app/widgets/vmaingraphicsscene.cpp @@ -126,3 +126,9 @@ void VMainGraphicsScene::SetFactor(qreal factor) scaleFactor=scaleFactor*factor; emit NewFactor(scaleFactor); } + +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsScene::EnableItemMove(bool move) +{ + emit EnableToolMove(move); +} diff --git a/src/app/widgets/vmaingraphicsscene.h b/src/app/widgets/vmaingraphicsscene.h index 96288c0ca..06f2cd5b6 100644 --- a/src/app/widgets/vmaingraphicsscene.h +++ b/src/app/widgets/vmaingraphicsscene.h @@ -52,6 +52,7 @@ public: public slots: void ChoosedItem(quint32 id, const SceneObject &type); void SetFactor(qreal factor); + void EnableItemMove(bool move); protected: virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); @@ -78,6 +79,7 @@ signals: */ void NewFactor(qreal factor); void DisableItem(bool disable); + void EnableToolMove(bool move); private: /** @brief horScrollBar value horizontal scroll bar. */ qint32 horScrollBar; diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 5b5d3b4f9..df52079ec 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -1163,6 +1163,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); connect(scene, &VMainGraphicsScene::DisableItem, spoint, &VToolSinglePoint::Disable); + connect(scene, &VMainGraphicsScene::EnableToolMove, spoint, &VToolSinglePoint::EnableToolMove); tools[id] = spoint; } }