diff --git a/src/Gui/ViewProviderAnnotation.cpp b/src/Gui/ViewProviderAnnotation.cpp index 457036dae5..4b554ec600 100644 --- a/src/Gui/ViewProviderAnnotation.cpp +++ b/src/Gui/ViewProviderAnnotation.cpp @@ -54,7 +54,6 @@ #include "BitmapFactory.h" #include "Document.h" #include "SoFCSelection.h" -#include "SoTextLabel.h" #include "Tools.h" #include "Window.h" @@ -292,7 +291,7 @@ ViewProviderAnnotationLabel::ViewProviderAnnotationLabel() pColor->ref(); pBaseTranslation = new SoTranslation(); pBaseTranslation->ref(); - pTextTranslation = new SoTransform(); + pTextTranslation = new TranslateManip(); pTextTranslation->ref(); pCoords = new SoCoordinate3(); pCoords->ref(); @@ -376,6 +375,27 @@ void ViewProviderAnnotationLabel::attach(App::DocumentObject* f) addDisplayMaskMode(linesep, "Line"); addDisplayMaskMode(textsep, "Object"); + + // Use the image node as the transform handle + SoSearchAction sa; + sa.setInterest(SoSearchAction::FIRST); + sa.setSearchingAll(true); + sa.setNode(this->pImage); + sa.apply(pcRoot); + SoPath * imagePath = sa.getPath(); + if (imagePath) { + SoDragger* dragger = pTextTranslation->getDragger(); + dragger->addStartCallback(dragStartCallback, this); + dragger->addFinishCallback(dragFinishCallback, this); + dragger->addMotionCallback(dragMotionCallback, this); + + dragger->setPartAsPath("translator", imagePath); + + // Hide the dragger feedback during translation + dragger->setPart("translatorActive", NULL); + dragger->setPart("xAxisFeedback", NULL); + dragger->setPart("yAxisFeedback", NULL); + } } void ViewProviderAnnotationLabel::updateData(const App::Property* prop) @@ -399,16 +419,6 @@ void ViewProviderAnnotationLabel::updateData(const App::Property* prop) ViewProviderDocumentObject::updateData(prop); } -bool ViewProviderAnnotationLabel::doubleClicked() -{ - Gui::Application::Instance->activeDocument()->setEdit(this); - return true; -} - -void ViewProviderAnnotationLabel::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) -{ - menu->addAction(QObject::tr("Move annotation"), receiver, member); -} void ViewProviderAnnotationLabel::dragStartCallback(void *, SoDragger *) { @@ -432,45 +442,6 @@ void ViewProviderAnnotationLabel::dragMotionCallback(void *data, SoDragger *drag } } -bool ViewProviderAnnotationLabel::setEdit(int ModNum) -{ - Q_UNUSED(ModNum); - SoSearchAction sa; - sa.setInterest(SoSearchAction::FIRST); - sa.setSearchingAll(false); - sa.setNode(this->pTextTranslation); - sa.apply(pcRoot); - SoPath * path = sa.getPath(); - if (path) { - auto manip = new TranslateManip; - SoDragger* dragger = manip->getDragger(); - dragger->addStartCallback(dragStartCallback, this); - dragger->addFinishCallback(dragFinishCallback, this); - dragger->addMotionCallback(dragMotionCallback, this); - return manip->replaceNode(path); - } - - return false; -} - -void ViewProviderAnnotationLabel::unsetEdit(int ModNum) -{ - Q_UNUSED(ModNum); - SoSearchAction sa; - sa.setType(TranslateManip::getClassTypeId()); - sa.setInterest(SoSearchAction::FIRST); - sa.apply(pcRoot); - SoPath * path = sa.getPath(); - - // No transform manipulator found. - if (!path) - return; - - auto manip = static_cast(path->getTail()); - SoTransform* transform = this->pTextTranslation; - manip->replaceManip(path, transform); -} - void ViewProviderAnnotationLabel::drawImage(const std::vector& s) { if (s.empty()) { diff --git a/src/Gui/ViewProviderAnnotation.h b/src/Gui/ViewProviderAnnotation.h index 1d2d5e7923..ee4f0adea4 100644 --- a/src/Gui/ViewProviderAnnotation.h +++ b/src/Gui/ViewProviderAnnotation.h @@ -26,6 +26,7 @@ #include "ViewProviderDocumentObject.h" #include +#include "SoTextLabel.h" class SoFont; class SoText2; @@ -106,15 +107,6 @@ public: std::vector getDisplayModes() const override; void setDisplayMode(const char* ModeName) override; - /** @name Edit methods */ - //@{ - bool doubleClicked() override; - void setupContextMenu(QMenu*, QObject*, const char*) override; -protected: - bool setEdit(int ModNum) override; - void unsetEdit(int ModNum) override; - //@} - protected: void onChanged(const App::Property* prop) override; void drawImage(const std::vector&); @@ -129,7 +121,7 @@ private: SoImage * pImage; SoBaseColor * pColor; SoTranslation * pBaseTranslation; - SoTransform * pTextTranslation; + TranslateManip * pTextTranslation; static const char* JustificationEnums[]; };