2016-04-03 21:55:12 -04:00
|
|
|
#include "FractoriumPch.h"
|
|
|
|
#include "LibraryTreeWidget.h"
|
|
|
|
#include "Fractorium.h"
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a pointer to the main window.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="f">Pointer to the main Fractorium object</param>
|
|
|
|
void LibraryTreeWidget::SetMainWindow(Fractorium* f)
|
|
|
|
{
|
|
|
|
m_Fractorium = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Process the drop event to allow for moving items around inside of the tree.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="de">Pointer to the QDropEvent object</param>
|
|
|
|
void LibraryTreeWidget::dropEvent(QDropEvent* de)
|
|
|
|
{
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto droppedIndex = indexAt(de->pos());
|
|
|
|
const auto items = selectionModel()->selectedRows();
|
2016-04-03 21:55:12 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
{
|
2017-03-02 23:04:47 -05:00
|
|
|
// get the list of the items that are about to be dragged
|
|
|
|
int i, row = droppedIndex.row();
|
2016-04-03 21:55:12 -04:00
|
|
|
DropIndicatorPosition dp = dropIndicatorPosition();
|
2017-03-02 23:04:47 -05:00
|
|
|
QList<QTreeWidgetItem*> dragItems = selectedItems();
|
2016-04-03 21:55:12 -04:00
|
|
|
|
|
|
|
if (dp == QAbstractItemView::BelowItem)
|
|
|
|
row++;
|
|
|
|
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto itemat = this->itemFromIndex(droppedIndex);
|
2017-03-02 23:04:47 -05:00
|
|
|
QTreeWidget::dropEvent(de);//This internally changes the order of the items.
|
|
|
|
|
|
|
|
//Qt has a long standing major bug that rearranges the order of disjoint selections when
|
|
|
|
//The drop location is in between the disjoint regions.
|
|
|
|
//This is an attempt to correct for that bug by removing the dropped items, then re-inserting them
|
|
|
|
//in the order they were selected.
|
|
|
|
//This bug remains present as of Qt 5.8: https://bugreports.qt.io/browse/QTBUG-45320
|
2021-04-19 23:07:24 -04:00
|
|
|
if (const auto top = topLevelItem(0))
|
2017-03-02 23:04:47 -05:00
|
|
|
{
|
|
|
|
if (itemat)
|
|
|
|
{
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto offsetitem = this->indexFromItem(itemat);
|
2017-03-02 23:04:47 -05:00
|
|
|
|
|
|
|
if (dp == QAbstractItemView::BelowItem)
|
|
|
|
{
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto itemrow = offsetitem.row() + 1;
|
2017-03-02 23:04:47 -05:00
|
|
|
|
|
|
|
for (i = 0; i < dragItems.size(); i++)
|
|
|
|
{
|
|
|
|
if (itemrow < top->childCount())
|
|
|
|
top->takeChild(itemrow);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dragItems.size(); i++)
|
|
|
|
{
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto offset = i + itemrow;
|
2017-03-02 23:04:47 -05:00
|
|
|
|
|
|
|
if (offset <= top->childCount())
|
|
|
|
top->insertChild(offset, dragItems[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-04-19 23:07:24 -04:00
|
|
|
const auto itemrow = offsetitem.row();//Will be at least 1 if dropped above it.
|
2017-03-02 23:04:47 -05:00
|
|
|
auto offset = itemrow;
|
|
|
|
|
2017-03-04 10:46:28 -05:00
|
|
|
for (i = 0; i < dragItems.size() && offset > 0; i++)
|
2017-03-02 23:04:47 -05:00
|
|
|
{
|
|
|
|
offset--;
|
|
|
|
|
|
|
|
if (offset < top->childCount())
|
|
|
|
top->takeChild(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dragItems.size(); i++)
|
|
|
|
{
|
|
|
|
if (offset <= top->childCount())
|
|
|
|
top->insertChild(offset, dragItems[i]);
|
|
|
|
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-04 10:46:28 -05:00
|
|
|
m_Fractorium->m_Controller->MoveLibraryItems(items, row);
|
2016-04-03 21:55:12 -04:00
|
|
|
}
|
--User changes
-Add backward compatibility option for the following variations: cos, cosh, cot, coth, csc, csch, sec, sech, sin, sinh, tan, tanh.
-Add the ability to re-order variations by dragging them in the Info tab.
2020-03-05 01:30:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Set a pointer to the main window.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="f">Pointer to the main Fractorium object</param>
|
|
|
|
void InfoTreeWidget::SetMainWindow(Fractorium* f)
|
|
|
|
{
|
|
|
|
m_Fractorium = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Called on each mouse movement while dragging, validate whether the area
|
|
|
|
/// being dragged over can be dropped on.
|
|
|
|
/// Can only drop on like (pre/reg/post) variation section of the same xform
|
|
|
|
/// of the variation being dragged.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dme">Pointer to the drag move event</param>
|
|
|
|
void InfoTreeWidget::dragMoveEvent(QDragMoveEvent* dme)
|
|
|
|
{
|
|
|
|
QModelIndex index = indexAt(dme->pos());
|
|
|
|
|
|
|
|
if (!index.isValid())//Don't process drop because it's outside of the droppable area.
|
|
|
|
{
|
|
|
|
dme->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> dragItems = selectedItems();
|
|
|
|
|
|
|
|
if (dragItems.size())
|
|
|
|
{
|
|
|
|
auto drag0 = dragItems[0];
|
|
|
|
|
|
|
|
if (auto itemat = itemFromIndex(index))
|
|
|
|
{
|
|
|
|
auto dragpre = drag0->text(0).startsWith("pre_", Qt::CaseInsensitive);
|
|
|
|
auto droppre = itemat->text(0).startsWith("pre_", Qt::CaseInsensitive);
|
|
|
|
auto dragpost = drag0->text(0).startsWith("post_", Qt::CaseInsensitive);
|
|
|
|
auto droppost = itemat->text(0).startsWith("post_", Qt::CaseInsensitive);
|
|
|
|
|
|
|
|
if (auto par = itemat->parent())
|
|
|
|
{
|
|
|
|
if (drag0->parent() == par &&
|
|
|
|
(par->text(0).startsWith("xform ", Qt::CaseInsensitive) ||
|
|
|
|
par->text(0).startsWith("final", Qt::CaseInsensitive)))
|
|
|
|
{
|
|
|
|
if (auto vitemat = dynamic_cast<VariationTreeWidgetItem*>(itemat))
|
|
|
|
{
|
|
|
|
bool dopre = dragpre && droppre;
|
|
|
|
bool dopost = dragpost && droppost;
|
|
|
|
bool doreg = !dragpre && !droppre && !dragpost && !droppost;
|
|
|
|
|
2020-03-05 09:35:09 -05:00
|
|
|
if (dopre || doreg || dopost)
|
--User changes
-Add backward compatibility option for the following variations: cos, cosh, cot, coth, csc, csch, sec, sech, sin, sinh, tan, tanh.
-Add the ability to re-order variations by dragging them in the Info tab.
2020-03-05 01:30:08 -05:00
|
|
|
{
|
|
|
|
QTreeWidget::dragMoveEvent(dme);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dme->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Process the drop event to allow for moving items around inside of the tree.
|
|
|
|
/// This will only allow variations to be moved around within the variation section of the tree
|
|
|
|
/// and nowhere else.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="de">Pointer to the QDropEvent object</param>
|
|
|
|
void InfoTreeWidget::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.
|
|
|
|
{
|
|
|
|
QList<QTreeWidgetItem*> dragItems = selectedItems();
|
|
|
|
|
|
|
|
if (dragItems.size())
|
|
|
|
{
|
|
|
|
auto drag0 = dragItems[0];
|
|
|
|
auto itemat = itemFromIndex(droppedIndex);
|
|
|
|
|
|
|
|
if (auto par = itemat->parent())
|
|
|
|
{
|
|
|
|
if (auto vdropitem = dynamic_cast<VariationTreeWidgetItem*>(itemat))
|
|
|
|
{
|
|
|
|
if (auto vdragitem = dynamic_cast<VariationTreeWidgetItem*>(drag0))
|
|
|
|
{
|
|
|
|
QTreeWidget::dropEvent(de);//This internally changes the order of the items.
|
|
|
|
m_Fractorium->ReorderVariations(par);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
de->ignore();
|
|
|
|
}
|
|
|
|
}
|