#ifndef TREEWIDGET_H
#define TREEWIDGET_H

#include <QTreeWidget>
#include <QDropEvent>
#include <QDebug>
#include <QTimer>

class InternalMoveTreeWidget: public QTreeWidget
{
	Q_OBJECT
public:
	InternalMoveTreeWidget(QWidget * parent = 0): QTreeWidget(parent) {}
	
protected:
	virtual void dropEvent(QDropEvent * e) {
		QList<QTreeWidgetItem*> sil = selectedItems();
		if (sil.isEmpty()) return;
		QTreeWidget::dropEvent(e);
		foreach (QTreeWidgetItem * ti, sil) {
			QTreeWidgetItem * ti_p = ti->parent();
			if (!ti_p) ti_p = invisibleRootItem();
			int ti_ppos = ti_p->indexOfChild(ti);
			emit itemMoved(ti, ti_p, ti_ppos);
		}
	}
	
signals:
	void itemMoved(QTreeWidgetItem * item, QTreeWidgetItem * new_parent, int new_index);
	
};

#endif // TREEWIDGET_H
