notepad--/draglineedit.cpp

53 lines
817 B
C++
Raw Normal View History

#include "draglineedit.h"
DragLineEdit::DragLineEdit(QWidget *parent)
: QLineEdit(parent)
{
setAcceptDrops(true);
}
DragLineEdit::~DragLineEdit()
{
}
void DragLineEdit::dragEnterEvent(QDragEnterEvent* event)
{
if (event->mimeData()->hasFormat("text/uri-list")) //ֻ<>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD>ı<EFBFBD><C4B1>ļ<EFBFBD>
{
event->accept(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϷŶ<CFB7><C5B6><EFBFBD>
}
else
{
event->ignore();
}
}
void DragLineEdit::dragMoveEvent(QDragMoveEvent* )
{
}
void DragLineEdit::dropEvent(QDropEvent* e)
{
QList<QUrl> urls = e->mimeData()->urls();
if (urls.isEmpty())
return;
QString fileName = urls.first().toLocalFile();
if (fileName.isEmpty())
{
return;
}
if (!QFile::exists(fileName))
{
return;
}
this->setText(fileName);
e->accept();
emit this->returnPressed();
}