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 <QOpenGLPixelTransferOptions>
#include <QOpenGLFramebufferObject> #include <QOpenGLFramebufferObject>
#include <QGridLayout> #include <QGridLayout>
#include <QMimeData>
struct RawImageType struct RawImageType
{ {
@@ -54,6 +55,7 @@ ImageWidget::ImageWidget(QWidget *parent) : QOpenGLWidget(parent)
m_range = UINT16_MAX; m_range = UINT16_MAX;
m_imgWidth = m_imgHeight = -1; m_imgWidth = m_imgHeight = -1;
m_superpixel = m_invert = false; m_superpixel = m_invert = false;
setAcceptDrops(true);
} }
ImageWidget::~ImageWidget() ImageWidget::~ImageWidget()
@@ -256,6 +258,29 @@ void ImageWidget::initializeGL()
m_transferOptions->setAlignment(1); 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) ImageScrollAreaGL::ImageScrollAreaGL(QWidget *parent) : QWidget(parent)
{ {
QGridLayout *layout = new QGridLayout(this); QGridLayout *layout = new QGridLayout(this);
+4
View File
@@ -59,6 +59,10 @@ protected:
void paintGL(); void paintGL();
void resizeGL(int w, int h); void resizeGL(int w, int h);
void initializeGL(); void initializeGL();
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);
signals:
void fileDropped(const QString &path);
}; };
class ImageScrollAreaGL : public QWidget class ImageScrollAreaGL : public QWidget
+2 -1
View File
@@ -80,6 +80,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
connect(m_ringList, SIGNAL(currentImageChanged(int)), this, SLOT(updateWindowTitle())); connect(m_ringList, SIGNAL(currentImageChanged(int)), this, SLOT(updateWindowTitle()));
connect(m_ringList, SIGNAL(infoLoaded(ImageInfoData)), m_info, SLOT(setInfo(const ImageInfoData&))); connect(m_ringList, SIGNAL(infoLoaded(ImageInfoData)), m_info, SLOT(setInfo(const ImageInfoData&)));
connect(m_ringList, SIGNAL(currentImageChanged(int)), m_filesystem, SLOT(selectFile(int))); connect(m_ringList, SIGNAL(currentImageChanged(int)), m_filesystem, SLOT(selectFile(int)));
connect(m_imageGL->imageWidget(), &ImageWidget::fileDropped, this, static_cast<void (MainWindow::*)(const QString &)>(&MainWindow::loadFile));
QMenu *fileMenu = new QMenu(tr("File"), this); QMenu *fileMenu = new QMenu(tr("File"), this);
fileMenu->addAction(tr("Open"), this, SLOT(loadFile()), QKeySequence("Ctrl+O")); fileMenu->addAction(tr("Open"), this, SLOT(loadFile()), QKeySequence("Ctrl+O"));
@@ -256,7 +257,7 @@ void MainWindow::loadFile()
loadFile(file); loadFile(file);
} }
void MainWindow::loadFile(const QString path) void MainWindow::loadFile(const QString &path)
{ {
if(!path.isEmpty()) if(!path.isEmpty())
{ {
+1 -1
View File
@@ -41,7 +41,7 @@ protected slots:
void updateWindowTitle(); void updateWindowTitle();
void pixmapLoaded(Image *image); void pixmapLoaded(Image *image);
void loadFile(); void loadFile();
void loadFile(const QString path); void loadFile(const QString &path);
void loadFile(int row); void loadFile(int row);
void indexDir(); void indexDir();
void saveAs(); void saveAs();