OSDN Git Service

Implement Drag&Drop support
authorlordmulder <mulder2@gmx.de>
Fri, 12 Nov 2010 22:31:04 +0000 (23:31 +0100)
committerlordmulder <mulder2@gmx.de>
Fri, 12 Nov 2010 22:31:04 +0000 (23:31 +0100)
src/Config.h
src/Dialog_MainWindow.cpp
src/Dialog_MainWindow.h

index f91ba95..ddb10c5 100644 (file)
@@ -25,7 +25,7 @@
 #define VER_LAMEXP_MAJOR                               4
 #define VER_LAMEXP_MINOR_HI                            0
 #define VER_LAMEXP_MINOR_LO                            0
-#define VER_LAMEXP_BUILD                               11
+#define VER_LAMEXP_BUILD                               12
 #define VER_LAMEXP_SUFFIX                              TechPreview
 
 /*
index d76f71f..8e981e3 100644 (file)
@@ -47,6 +47,8 @@
 #include <QWindowsVistaStyle>
 #include <QWindowsStyle>
 #include <QSysInfo>
+#include <QDragEnterEvent>
+#include <QWindowsMime>
 
 //Win32 includes
 #include <Windows.h>
@@ -205,6 +207,9 @@ MainWindow::MainWindow(QWidget *parent)
        connect(m_messageHandler, SIGNAL(killSignalReceived()), this, SLOT(close()), Qt::QueuedConnection);
        connect(m_delayedFileTimer, SIGNAL(timeout()), this, SLOT(handleDelayedFiles()));
        m_messageHandler->start();
+
+       //Enable Drag & Drop
+       this->setAcceptDrops(true);
 }
 
 ////////////////////////////////////////////////////////////
@@ -284,6 +289,34 @@ void MainWindow::showEvent(QShowEvent *event)
        QTimer::singleShot(0, this, SLOT(windowShown()));
 }
 
+void MainWindow::dragEnterEvent(QDragEnterEvent *event)
+{
+       QStringList formats = event->mimeData()->formats();
+       
+       for(int i = 0; i < formats.count(); i++)
+       {
+               if(formats[i].indexOf("FileNameW") >= 0)
+               {
+                       event->acceptProposedAction();
+               }
+       }
+}
+
+void MainWindow::dropEvent(QDropEvent *event)
+{
+       ABORT_IF_BUSY;
+
+       QStringList droppedFiles;
+       const QList<QUrl> urls = event->mimeData()->urls();
+
+       for(int i = 0; i < urls.count(); i++)
+       {
+               droppedFiles << QFileInfo(urls.at(i).toLocalFile()).absoluteFilePath();
+       }
+       
+       addFiles(droppedFiles);
+}
+
 ////////////////////////////////////////////////////////////
 // Slots
 ////////////////////////////////////////////////////////////
index 7a0c08d..0837c08 100644 (file)
@@ -71,6 +71,8 @@ private slots:
 
 protected:
        void showEvent(QShowEvent *event);
+       void dragEnterEvent(QDragEnterEvent *event);
+       void dropEvent(QDropEvent *event);
 
 private:
        void addFiles(const QStringList &files);