Fixed issue #217. Bug with mouse cursor.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-02-09 11:54:19 +02:00
parent 2885abb5a1
commit c2191dd8d0
10 changed files with 54 additions and 49 deletions

View File

@ -92,6 +92,7 @@ MainWindow::MainWindow(QWidget *parent)
sceneDraw = new VMainGraphicsScene(); sceneDraw = new VMainGraphicsScene();
currentScene = sceneDraw; currentScene = sceneDraw;
qApp->setCurrentScene(currentScene); qApp->setCurrentScene(currentScene);
connect(this, &MainWindow::EnableItemMove, sceneDraw, &VMainGraphicsScene::EnableItemMove);
connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); connect(sceneDraw, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
sceneDetails = new VMainGraphicsScene(); sceneDetails = new VMainGraphicsScene();
connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove); connect(sceneDetails, &VMainGraphicsScene::mouseMove, this, &MainWindow::mouseMove);
@ -244,7 +245,9 @@ void MainWindow::ActionNewPP()
sceneDraw->addItem(spoint); sceneDraw->addItem(spoint);
ui->view->itemClicked(spoint); ui->view->itemClicked(spoint);
connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem);
connect(sceneDraw, &VMainGraphicsScene::DisableItem, spoint, &VToolSinglePoint::Disable);
connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
connect(sceneDraw, &VMainGraphicsScene::EnableToolMove, spoint, &VToolSinglePoint::EnableToolMove);
QHash<quint32, VDataTool*>* tools = doc->getTools(); QHash<quint32, VDataTool*>* tools = doc->getTools();
SCASSERT(tools != nullptr); SCASSERT(tools != nullptr);
tools->insert(id, spoint); tools->insert(id, spoint);
@ -1046,114 +1049,75 @@ void MainWindow::CancelTool()
ui->actionArrowTool->setChecked(false); ui->actionArrowTool->setChecked(false);
helpLabel->setText(""); helpLabel->setText("");
ui->actionStopTool->setEnabled(true); ui->actionStopTool->setEnabled(true);
break; emit EnableItemMove(false);
return;
case Tool::SinglePoint: case Tool::SinglePoint:
Q_UNREACHABLE(); Q_UNREACHABLE();
//Nothing to do here because we can't create this tool from main window. //Nothing to do here because we can't create this tool from main window.
break; break;
case Tool::EndLine: case Tool::EndLine:
ui->toolButtonEndLine->setChecked(false); ui->toolButtonEndLine->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::Line: case Tool::Line:
ui->toolButtonLine->setChecked(false); ui->toolButtonLine->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearFocus();
break; break;
case Tool::AlongLine: case Tool::AlongLine:
ui->toolButtonAlongLine->setChecked(false); ui->toolButtonAlongLine->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::ShoulderPoint: case Tool::ShoulderPoint:
ui->toolButtonShoulderPoint->setChecked(false); ui->toolButtonShoulderPoint->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::Normal: case Tool::Normal:
ui->toolButtonNormal->setChecked(false); ui->toolButtonNormal->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::Bisector: case Tool::Bisector:
ui->toolButtonBisector->setChecked(false); ui->toolButtonBisector->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::LineIntersect: case Tool::LineIntersect:
ui->toolButtonLineIntersect->setChecked(false); ui->toolButtonLineIntersect->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::Spline: case Tool::Spline:
ui->toolButtonSpline->setChecked(false); ui->toolButtonSpline->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::Arc: case Tool::Arc:
ui->toolButtonArc->setChecked(false); ui->toolButtonArc->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::SplinePath: case Tool::SplinePath:
ui->toolButtonSplinePath->setChecked(false); ui->toolButtonSplinePath->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::PointOfContact: case Tool::PointOfContact:
ui->toolButtonPointOfContact->setChecked(false); ui->toolButtonPointOfContact->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::Detail: case Tool::Detail:
ui->toolButtonNewDetail->setChecked(false); ui->toolButtonNewDetail->setChecked(false);
break; break;
case Tool::Height: case Tool::Height:
ui->toolButtonHeight->setChecked(false); ui->toolButtonHeight->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::Triangle: case Tool::Triangle:
ui->toolButtonTriangle->setChecked(false); ui->toolButtonTriangle->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::PointOfIntersection: case Tool::PointOfIntersection:
ui->toolButtonPointOfIntersection->setChecked(false); ui->toolButtonPointOfIntersection->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::CutSpline: case Tool::CutSpline:
ui->toolButtonSplineCutPoint->setChecked(false); ui->toolButtonSplineCutPoint->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::CutSplinePath: case Tool::CutSplinePath:
ui->toolButtonSplinePathCutPoint->setChecked(false); ui->toolButtonSplinePathCutPoint->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::UnionDetails: case Tool::UnionDetails:
ui->toolButtonUnionDetails->setChecked(false); ui->toolButtonUnionDetails->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::CutArc: case Tool::CutArc:
ui->toolButtonArcCutPoint->setChecked(false); ui->toolButtonArcCutPoint->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::LineIntersectAxis: case Tool::LineIntersectAxis:
ui->toolButtonLineIntersectAxis->setChecked(false); ui->toolButtonLineIntersectAxis->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::CurveIntersectAxis: case Tool::CurveIntersectAxis:
ui->toolButtonCurveIntersectAxis->setChecked(false); ui->toolButtonCurveIntersectAxis->setChecked(false);
ui->toolButtonArcIntersectAxis->setChecked(false); ui->toolButtonArcIntersectAxis->setChecked(false);
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
break; break;
case Tool::NodePoint: case Tool::NodePoint:
case Tool::NodeArc: case Tool::NodeArc:
@ -1163,6 +1127,9 @@ void MainWindow::CancelTool()
qDebug()<<"Got wrong tool type. Ignored."; qDebug()<<"Got wrong tool type. Ignored.";
break; break;
} }
currentScene->setFocus(Qt::OtherFocusReason);
currentScene->clearSelection();
emit EnableItemMove(true);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -139,6 +139,7 @@ signals:
void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &curFile, void ModelChosen(QVector<VLayoutDetail> listDetails, const QString &curFile,
const QString &description); const QString &description);
void RefreshHistory(); void RefreshHistory();
void EnableItemMove(bool move);
protected: protected:
virtual void keyPressEvent(QKeyEvent *event); virtual void keyPressEvent(QKeyEvent *event);
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);

View File

@ -206,6 +206,13 @@ void VDrawTool::SetFactor(qreal factor)
VApplication::CheckFactor(this->factor, factor); VApplication::CheckFactor(this->factor, factor);
} }
//---------------------------------------------------------------------------------------------------------------------
void VDrawTool::EnableToolMove(bool move)
{
Q_UNUSED(move)
// Do nothing.
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief CheckFormula check formula. * @brief CheckFormula check formula.

View File

@ -69,6 +69,7 @@ public slots:
virtual void FullUpdateFromGuiOk(int result); virtual void FullUpdateFromGuiOk(int result);
virtual void FullUpdateFromGuiApply(); virtual void FullUpdateFromGuiApply();
virtual void SetFactor(qreal factor); virtual void SetFactor(qreal factor);
virtual void EnableToolMove(bool move);
protected: protected:
/** @brief ignoreFullUpdate ignore or not full updates. */ /** @brief ignoreFullUpdate ignore or not full updates. */

View File

@ -216,6 +216,7 @@ void VToolPoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor)); this->setPen(QPen(CorrectColor(baseColor), qApp->toPixel(qApp->widthHairLine())/factor));
QGraphicsEllipseItem::hoverLeaveEvent(event);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -205,36 +205,48 @@ void VToolSinglePoint::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
{ {
VToolPoint::hoverEnterEvent(event); VToolPoint::hoverEnterEvent(event);
if (flags() & QGraphicsItem::ItemIsMovable)
{
VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1); VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"), 1, 1);
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
{ {
VToolPoint::hoverLeaveEvent(event); VToolPoint::hoverLeaveEvent(event);
if (flags() & QGraphicsItem::ItemIsMovable)
{
//Disable cursor-arrow-openhand //Disable cursor-arrow-openhand
VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png")); VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-openhand.png"));
} }
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1); VApplication::setOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"), 1, 1);
} }
}
VToolPoint::mousePressEvent(event); VToolPoint::mousePressEvent(event);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
if (flags() & QGraphicsItem::ItemIsMovable)
{ {
if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick)
{ {
//Disable cursor-arrow-closehand //Disable cursor-arrow-closehand
VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png")); VApplication::restoreOverrideCursor(QStringLiteral("://cursor/cursor-arrow-closehand.png"));
} }
}
VToolPoint::mouseReleaseEvent(event); VToolPoint::mouseReleaseEvent(event);
} }
@ -332,3 +344,9 @@ void VToolSinglePoint::ShowContextMenu(QGraphicsSceneContextMenuEvent *event)
ContextMenu<DialogSinglePoint>(this, event, false); ContextMenu<DialogSinglePoint>(this, event, false);
} }
} }
//---------------------------------------------------------------------------------------------------------------------
void VToolSinglePoint::EnableToolMove(bool move)
{
this->setFlag(QGraphicsItem::ItemIsMovable, move);
}

View File

@ -50,6 +50,7 @@ public slots:
virtual void FullUpdateFromFile(); virtual void FullUpdateFromFile();
virtual void SetFactor(qreal factor); virtual void SetFactor(qreal factor);
virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event);
virtual void EnableToolMove(bool move);
signals: signals:
/** /**
* @brief FullUpdateTree handle if need update pattern file. * @brief FullUpdateTree handle if need update pattern file.

View File

@ -126,3 +126,9 @@ void VMainGraphicsScene::SetFactor(qreal factor)
scaleFactor=scaleFactor*factor; scaleFactor=scaleFactor*factor;
emit NewFactor(scaleFactor); emit NewFactor(scaleFactor);
} }
//---------------------------------------------------------------------------------------------------------------------
void VMainGraphicsScene::EnableItemMove(bool move)
{
emit EnableToolMove(move);
}

View File

@ -52,6 +52,7 @@ public:
public slots: public slots:
void ChoosedItem(quint32 id, const SceneObject &type); void ChoosedItem(quint32 id, const SceneObject &type);
void SetFactor(qreal factor); void SetFactor(qreal factor);
void EnableItemMove(bool move);
protected: protected:
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
@ -78,6 +79,7 @@ signals:
*/ */
void NewFactor(qreal factor); void NewFactor(qreal factor);
void DisableItem(bool disable); void DisableItem(bool disable);
void EnableToolMove(bool move);
private: private:
/** @brief horScrollBar value horizontal scroll bar. */ /** @brief horScrollBar value horizontal scroll bar. */
qint32 horScrollBar; qint32 horScrollBar;

View File

@ -1163,6 +1163,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem
connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem); connect(spoint, &VToolSinglePoint::ChoosedTool, scene, &VMainGraphicsScene::ChoosedItem);
connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); connect(scene, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor);
connect(scene, &VMainGraphicsScene::DisableItem, spoint, &VToolSinglePoint::Disable); connect(scene, &VMainGraphicsScene::DisableItem, spoint, &VToolSinglePoint::Disable);
connect(scene, &VMainGraphicsScene::EnableToolMove, spoint, &VToolSinglePoint::EnableToolMove);
tools[id] = spoint; tools[id] = spoint;
} }
} }