#include "FractoriumPch.h"
#include "LibraryTreeWidget.h"
#include "Fractorium.h"
///
/// Set a pointer to the main window.
///
/// Pointer to the main Fractorium object
void LibraryTreeWidget::SetMainWindow(Fractorium* f)
{
m_Fractorium = f;
}
///
/// Process the drop event to allow for moving items around inside of the tree.
///
/// Pointer to the QDropEvent object
void LibraryTreeWidget::dropEvent(QDropEvent* de)
{
QModelIndex droppedIndex = indexAt(de->pos());
auto items = selectionModel()->selectedRows();
if (!droppedIndex.isValid())//Don't process drop because it's outside of the droppable area.
{
de->ignore();
return;
}
else if (!items.empty())//Actually do the drop and move the item to a new location.
{
int row = droppedIndex.row();
DropIndicatorPosition dp = dropIndicatorPosition();
if (dp == QAbstractItemView::BelowItem)
row++;
QTimer::singleShot(500, [ = ]() { m_Fractorium->m_Controller->MoveLibraryItems(items, row); });//Need to fire this after this event has internally reshuffled the items.
}
QTreeWidget::dropEvent(de);
}