Simplify dragging of App::AnnotationLabel (#11602)

* ViewProviderAnnotationn: Always allow dragging

Removes the editmode

* ViewProviderAnnotation: Use the label as transformation handle

* ViewProviderAnnotationn: Always allow dragging

Removes the editmode

* ViewProviderAnnotation: Use the label as transformation handle

* ViewProviderAnnotation: Hide dragger feedback during translation

---------

Co-authored-by: WandererFan <WandererFan@gmail.com>
This commit is contained in:
hlorus
2023-12-11 20:18:27 +01:00
committed by GitHub
parent 6d0db27bd9
commit f0f9e81f88
2 changed files with 24 additions and 61 deletions

View File

@@ -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<TranslateManip*>(path->getTail());
SoTransform* transform = this->pTextTranslation;
manip->replaceManip(path, transform);
}
void ViewProviderAnnotationLabel::drawImage(const std::vector<std::string>& s)
{
if (s.empty()) {