DragAndDrop components from and to same class


#1

Hello,

I have a list of MyItemComponent(s). I want to be able to:

  • move them around:
    At the moment I manage to do that having a ComponentDragger dragger; in the MyItemComponent class and using the methods
    void resized() override;
    void mouseDown (const MouseEvent& e) override;
    void mouseDrag (const MouseEvent& e) override;

  • dragAndDrop into each other so I can connect them. I’m not sure if it’s a properly DragAndDrop as I don’t really need to move the source, just to create a link with the target (and maybe draw a line?)
    For that I was trying to derive from DragAndDropContainer in MyItemsViewerComponent, who has a list of MyItemComponent(s) and derive MyItemComponent from DragAndDropTarget and implementing the methods:
    bool isInterestedInDragSource (const SourceDetails& /dragSourceDetails/) override;
    void itemDragEnter (const SourceDetails& /dragSourceDetails/) override;
    void itemDragMove (const SourceDetails& /dragSourceDetails/) override;
    void itemDragExit (const SourceDetails& /dragSourceDetails/) override;
    void itemDropped (const SourceDetails& dragSourceDetails) override;

I can move MyItemComponent around but nothing happens when I move it on top of another MyItemComponent

Any light? Or am I mixing things and messing it too much?
Thx


#2

I’ll reply to myself:

I made MyItemComponent to derive from
public DragAndDropContainer,
public DragAndDropTarget

then in mouseDown I either call

  • startDragging(…) //to do the drag and drop
    or
  • dragger.startDraggingComponent (this, e); //to move the object
    depending on the MouseEvent Mods