2013-07-28 20:11:37 +00:00
|
|
|
#include "droparea.h"
|
|
|
|
|
|
|
|
#include <QGraphicsSceneDragDropEvent>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2016-01-08 19:49:49 +00:00
|
|
|
DropArea::DropArea(QQuickItem *parent) : QQuickItem(parent),
|
2013-07-28 20:11:37 +00:00
|
|
|
m_accepting(true)
|
|
|
|
{
|
2016-01-08 19:49:49 +00:00
|
|
|
setAcceptingDrops(m_accepting);
|
2013-07-28 20:11:37 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 19:49:49 +00:00
|
|
|
//void DropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
//{
|
|
|
|
// event->acceptProposedAction();
|
|
|
|
// setCursor(Qt::DragMoveCursor);
|
|
|
|
//}
|
|
|
|
|
|
|
|
//void DropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
//{
|
|
|
|
// unsetCursor();
|
|
|
|
//}
|
|
|
|
|
|
|
|
//void DropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
//{
|
|
|
|
// qDebug("File!");
|
|
|
|
// QList<QUrl> list = event->mimeData()->urls();
|
|
|
|
// for(int i=0; i<list.size(); i++)
|
|
|
|
// {
|
|
|
|
// QString path = list.at(i).path();
|
|
|
|
// emit fileDroped(path.right(path.size()-1));
|
|
|
|
// }
|
|
|
|
// unsetCursor();
|
|
|
|
//}
|
2013-07-28 20:11:37 +00:00
|
|
|
|
2016-01-08 19:49:49 +00:00
|
|
|
void DropArea::setAcceptingDrops(bool accepting)
|
2013-07-28 20:11:37 +00:00
|
|
|
{
|
2016-01-08 19:49:49 +00:00
|
|
|
if (accepting == m_accepting)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_accepting = accepting;
|
|
|
|
|
|
|
|
setFlag(QQuickItem::ItemAcceptsDrops);
|
|
|
|
//setAcceptDrops(m_accepting);
|
|
|
|
emit acceptingDropsChanged();
|
2013-07-28 20:11:37 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 19:49:49 +00:00
|
|
|
void DropArea::dropEvent(QDropEvent *event)
|
2013-07-28 20:11:37 +00:00
|
|
|
{
|
2014-01-15 16:18:02 +00:00
|
|
|
qDebug("File!");
|
2013-07-28 20:11:37 +00:00
|
|
|
QList<QUrl> list = event->mimeData()->urls();
|
|
|
|
for(int i=0; i<list.size(); i++)
|
2014-01-15 16:18:02 +00:00
|
|
|
{
|
2016-01-08 19:49:49 +00:00
|
|
|
QString path = list.at(i).path();
|
|
|
|
emit fileDroped(path.right(path.size()-1));
|
2014-01-15 16:18:02 +00:00
|
|
|
}
|
2013-07-28 20:11:37 +00:00
|
|
|
unsetCursor();
|
|
|
|
}
|