I want to drag a component onto a workspace but leave the original component where it was. This action creates a new component on the workspace while leaving the original component. Like Visio or some other drawing tool where you drag a component onto a workspace or canvas.
Once I got my component drawn and draggable, I tried to create a new component in mouseDown() and have the new component as the one being dragged. I could not get this to work.
I then discovered Toolbar and its associated classes. But I can’t drag my component off of the tool bar. Here’s what I tried with toolbar:
class MyToolbar : public Toolbar
{
MyToolbar() = default;
void mouseDown(MouseEvent& e)
{
startDragging(e.eventComponent.getName(), e.eventComponent);
}
};
‘mouseDown()’ never get called.
Now I’m thinking I should use ToolbarItemPalette and just pass it a dummy (unused) toolbar. Is there a better/standard way to do this with Juce?
You toolbar’s mouseDown won’t get called because the toolbar is full of child components, and they’re catching the mouse-down events, not the parent toolbar. You’d need to create your own toolbar button if you want to make it do custom stuff.
Thanks Jules. Yes, I can see the component’s mouseDown(…) getting called. From with in the component’s mouseDown(…) I can get a pointer to the toolbar and call startDragging on the toolbar. But this only let’s me drag the component on the toolbar. I need to also be able to drag it from the toolbar and into the component that contains the toolbar.
Thanks for your help Jules. Got it working. Just made the parent of the toolbar a DragAndDropContainer and then called parent.startDragging(…) in the component’s mouseDrag(…) when the component is dragged outside the toolbar: