Add drop file support
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <QOpenGLPixelTransferOptions>
|
||||
#include <QOpenGLFramebufferObject>
|
||||
#include <QGridLayout>
|
||||
#include <QMimeData>
|
||||
|
||||
struct RawImageType
|
||||
{
|
||||
@@ -54,6 +55,7 @@ ImageWidget::ImageWidget(QWidget *parent) : QOpenGLWidget(parent)
|
||||
m_range = UINT16_MAX;
|
||||
m_imgWidth = m_imgHeight = -1;
|
||||
m_superpixel = m_invert = false;
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
ImageWidget::~ImageWidget()
|
||||
@@ -256,6 +258,29 @@ void ImageWidget::initializeGL()
|
||||
m_transferOptions->setAlignment(1);
|
||||
}
|
||||
|
||||
void ImageWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if(event->mimeData()->hasUrls() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction))
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void ImageWidget::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if(event->mimeData()->hasUrls() && event->proposedAction() & (Qt::CopyAction | Qt::MoveAction))
|
||||
{
|
||||
for(const QUrl &url : event->mimeData()->urls())
|
||||
{
|
||||
if(url.isLocalFile())
|
||||
{
|
||||
emit fileDropped(url.path());
|
||||
event->accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
event->ignore();
|
||||
}
|
||||
|
||||
ImageScrollAreaGL::ImageScrollAreaGL(QWidget *parent) : QWidget(parent)
|
||||
{
|
||||
QGridLayout *layout = new QGridLayout(this);
|
||||
|
||||
Reference in New Issue
Block a user