#include <QDebug>
#include <QMimeData>
#include "droppable_line_edit.h"
DroppableLineEdit::DroppableLineEdit(QWidget *parent) : QLineEdit(parent)
{
    setAcceptDrops(true);
}

DroppableLineEdit::~DroppableLineEdit()
{

}

void DroppableLineEdit::dragEnterEvent(QDragEnterEvent *event)
{
    if (event->mimeData()->hasUrls())
        event->acceptProposedAction(); //事件数据中存在路径，方向事件
    else
        event->ignore();
}

void DroppableLineEdit::dragMoveEvent(QDragMoveEvent *event)
{
    //暂时没用上
    Q_UNUSED(event);
}

void DroppableLineEdit::dropEvent(QDropEvent *event)
{
    const QMimeData *mimeData = event->mimeData();
    if (mimeData->hasUrls())
    {
        QList<QUrl> urls = mimeData->urls();
        QString fileName = urls.at(0).toLocalFile();
        if(fileName.endsWith(".deb",Qt::CaseInsensitive)){
            setText(fileName);
            event->accept();
        }else{
            event->ignore();
        }
    }
    else
    {
        event->ignore();
    }
}
