From 22278b78266c6884847e77d8d1145a4c8b9125fe Mon Sep 17 00:00:00 2001 From: Ian Rees Date: Thu, 10 Jul 2014 14:02:30 +1200 Subject: [PATCH] This branch adds a mouse cursor to the 'Measure Distance' tool. --- src/Gui/CommandView.cpp | 45 ++++++++++++++++++++++++- src/Gui/View3DInventor.cpp | 4 +-- src/Gui/ViewProviderMeasureDistance.cpp | 15 +++++---- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/src/Gui/CommandView.cpp b/src/Gui/CommandView.cpp index ae715d5b6..89fd30a0f 100644 --- a/src/Gui/CommandView.cpp +++ b/src/Gui/CommandView.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2002 Jürgen Riegel * + * Copyright (c) 2002 J�rgen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * @@ -2221,6 +2221,45 @@ StdCmdMeasureDistance::StdCmdMeasureDistance() eType = Alter3DView; } +// Yay for cheezy drawings! +/* XPM */ +static const char * cursor_ruler[] = { +"32 32 3 1", +" c None", +". c #FFFFFF", +"+ c #FF0000", +" . ", +" . ", +" . ", +" . ", +" . ", +" ", +"..... ..... ", +" ", +" . ", +" . ", +" . ++ ", +" . + + ", +" . + ++ ", +" + + + ", +" + + + ", +" + + ++ ", +" + + + ", +" + + ", +" + + + ", +" + + + ", +" + + ", +" + + + ", +" + + + ", +" + + ", +" + + + ", +" + + ++", +" + + + ", +" + + ", +" + + ", +" + + ", +" + + ", +" + "}; void StdCmdMeasureDistance::activated(int iMsg) { Gui::Document* doc = Gui::Application::Instance->activeDocument(); @@ -2228,6 +2267,10 @@ void StdCmdMeasureDistance::activated(int iMsg) if (view) { Gui::View3DInventorViewer* viewer = view->getViewer(); viewer->setEditing(true); + viewer->setEditingCursor(QCursor(QPixmap(cursor_ruler), 7, 7)); + + // Derives from QObject and we have a parent object, so we don't + // require a delete. PointMarker* marker = new PointMarker(viewer); viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), ViewProviderMeasureDistance::measureDistanceCallback, marker); diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 90a27f7ec..ceb1e51aa 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (c) 2004 Jürgen Riegel * + * Copyright (c) 2004 J�rgen Riegel * * * * This file is part of the FreeCAD CAx development system. * * * @@ -171,7 +171,7 @@ View3DInventor::~View3DInventor() hGrp->Detach(this); //If we destroy this viewer by calling 'delete' directly the focus proxy widget which is defined - //by a widget in SoQtViewer isn't resetted. This widget becomes to a dangling pointer and makes + //by a widget in SoQtViewer isn't reset. This widget becomes a dangling pointer and makes //the application crash. (Probably it's better to destroy this viewer by calling close().) //See also Gui::Document::~Document(). QWidget* foc = qApp->focusWidget(); diff --git a/src/Gui/ViewProviderMeasureDistance.cpp b/src/Gui/ViewProviderMeasureDistance.cpp index f1217989a..c1dc1ab01 100644 --- a/src/Gui/ViewProviderMeasureDistance.cpp +++ b/src/Gui/ViewProviderMeasureDistance.cpp @@ -320,14 +320,10 @@ void ViewProviderMeasureDistance::measureDistanceCallback(void * ud, SoEventCall // Mark all incoming mouse button events as handled, especially, to deactivate the selection node n->getAction()->setHandled(); - if (mbe->getButton() == SoMouseButtonEvent::BUTTON2 && mbe->getState() == SoButtonEvent::UP) { - n->setHandled(); - view->setEditing(false); - view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), measureDistanceCallback, ud); - pm->deleteLater(); - } - else if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { + + if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { const SoPickedPoint * point = n->getPickedPoint(); + // I think this is where we need to snap. IR 20140630 if (point == NULL) { Base::Console().Message("No point picked.\n"); return; @@ -343,5 +339,10 @@ void ViewProviderMeasureDistance::measureDistanceCallback(void * ud, SoEventCall view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), measureDistanceCallback, ud); pm->deleteLater(); } + } else if (mbe->getButton() != SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::UP) { + n->setHandled(); + view->setEditing(false); + view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), measureDistanceCallback, ud); + pm->deleteLater(); } }