Add drop file support

This commit is contained in:
2022-04-14 11:20:16 +02:00
parent 56d6db8bc3
commit 26be690c70
4 changed files with 32 additions and 2 deletions
+25
View File
@@ -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);