I've a parent Component with small components inside, (like a stack of components)
These small component can be dragged to change the order, and can be deleted by dragging outside the parent.
class ParentComponent : public Component,
public DragAndDropTarget,
public DragAndDropContainer
class ChildComponent : public Component
void mouseDrag (const MouseEvent& e)
{
DragAndDropContainer* dragContainer = DragAndDropContainer::findParentDragContainerFor (this);
if (!dragContainer->isDragAndDropActive())
{
dragContainer->startDragging("childComponent", this, Image::null, true);
}
}
To delete a child component
void ParentComponent::itemDragExit (const SourceDetails& dragSourceDetails)
{
// Component* toDelete member
toDelete = dragSourceDetails.sourceComponent.get();
toMove = nullptr;
repaint();
}
void ParentComponent::dragOperationEnded()
{
if (toDelete != nullptr)
{
removeChildComponent (toDelete);
items.removeObject (dynamic_cast <ModuleGui*> (toDelete));
}
I'm going in the right direction?
I was thinking to do it this way may be unsafe, What if two elements move at the same time? the above code will not work
