2013-07-28 20:11:37 +00:00
|
|
|
#include "droparea.h"
|
|
|
|
|
|
|
|
#include <QGraphicsSceneDragDropEvent>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QDebug>
|
|
|
|
|
2014-01-15 16:18:02 +00:00
|
|
|
DropArea::DropArea(QDeclarativeItem *parent) : QDeclarativeItem(parent),
|
2013-07-28 20:11:37 +00:00
|
|
|
m_accepting(true)
|
|
|
|
{
|
|
|
|
setAcceptDrops(m_accepting);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropArea::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
event->acceptProposedAction();
|
|
|
|
setCursor(Qt::DragMoveCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropArea::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
|
|
|
unsetCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropArea::dropEvent(QGraphicsSceneDragDropEvent *event)
|
|
|
|
{
|
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
|
|
|
{
|
|
|
|
QString path = list.at(i).path();
|
2013-07-28 20:11:37 +00:00
|
|
|
emit fileDroped(path.right(path.size()-1));
|
2014-01-15 16:18:02 +00:00
|
|
|
}
|
2013-07-28 20:11:37 +00:00
|
|
|
unsetCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DropArea::setAcceptingDrops(bool accepting)
|
|
|
|
{
|
|
|
|
if (accepting == m_accepting)
|
2014-01-15 16:18:02 +00:00
|
|
|
return;
|
2013-07-28 20:11:37 +00:00
|
|
|
|
|
|
|
m_accepting = accepting;
|
2014-01-15 16:18:02 +00:00
|
|
|
|
2013-07-28 20:11:37 +00:00
|
|
|
setAcceptDrops(m_accepting);
|
|
|
|
emit acceptingDropsChanged();
|
|
|
|
}
|