Skip to content

Commit

Permalink
Simplify dragging of App::AnnotationLabel (FreeCAD#11602)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
hlorus and WandererFan authored Dec 11, 2023
1 parent 1066bb5 commit e3b1fe5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 61 deletions.
73 changes: 22 additions & 51 deletions src/Gui/ViewProviderAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#include "BitmapFactory.h"
#include "Document.h"
#include "SoFCSelection.h"
#include "SoTextLabel.h"
#include "Tools.h"
#include "Window.h"

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand All @@ -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 *)
{
Expand All @@ -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()) {
Expand Down
12 changes: 2 additions & 10 deletions src/Gui/ViewProviderAnnotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "ViewProviderDocumentObject.h"
#include <App/PropertyUnits.h>
#include "SoTextLabel.h"

class SoFont;
class SoText2;
Expand Down Expand Up @@ -106,15 +107,6 @@ class GuiExport ViewProviderAnnotationLabel : public ViewProviderDocumentObject
std::vector<std::string> 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<std::string>&);
Expand All @@ -129,7 +121,7 @@ class GuiExport ViewProviderAnnotationLabel : public ViewProviderDocumentObject
SoImage * pImage;
SoBaseColor * pColor;
SoTranslation * pBaseTranslation;
SoTransform * pTextTranslation;
TranslateManip * pTextTranslation;

static const char* JustificationEnums[];
};
Expand Down

0 comments on commit e3b1fe5

Please sign in to comment.