]> Some of my projects - localmylist.git/commitdiff
Add drag&drop support to enable adding files by dragging them onto managment-gui
authorAPTX <marek321@gmail.com>
Sun, 15 Jul 2012 22:56:34 +0000 (00:56 +0200)
committerAPTX <marek321@gmail.com>
Sun, 15 Jul 2012 22:56:34 +0000 (00:56 +0200)
management-gui/mainwindow.cpp
management-gui/mainwindow.h

index 0670bbcd431aec5523fcb6a9a2b788895db9fdd2..c1604204c8701ff544e0296953569272c125e44c 100644 (file)
@@ -7,6 +7,8 @@
 #include <QDesktopServices>
 #include <QUrl>
 #include <QSortFilterProxyModel>
+#include <QDragEnterEvent>
+#include <QDropEvent>
 
 #include "mylist.h"
 #include "database.h"
@@ -50,6 +52,8 @@ MainWindow::MainWindow(QWidget *parent) :
        ui->myListView->header()->resizeSection(4, 200);
 
        connect(ui->myListView, SIGNAL(renameTest(int)), this, SLOT(openRenameScriptEditor(int)));
+
+       setAcceptDrops(true);
 }
 
 MainWindow::~MainWindow()
@@ -346,3 +350,24 @@ void MainWindow::on_actionAddRelatedEpisodeInfo_triggered()
 {
        MyList::instance()->executeTask(new AddRelatedEpisodesTask());
 }
+
+void MainWindow::dragEnterEvent(QDragEnterEvent *event)
+{
+       if (event->mimeData()->hasFormat("text/uri-list"))
+               event->acceptProposedAction();
+}
+
+void MainWindow::dropEvent(QDropEvent *event)
+{
+       QList<QUrl> urls = event->mimeData()->urls();
+       QFileInfoList files;
+
+       for (int i = 0; i < urls.count(); ++i)
+       {
+               if (!urls[i].isLocalFile())
+                       continue;
+
+               LocalMyList::instance()->addFile(QFileInfo(urls[i].toLocalFile()));
+       }
+       event->acceptProposedAction();
+}
index 488f77f3b2fdb9e812e15a24f1621de65d653cb5..83dbd2b378c30e12efdf4a83bfc9a4e9421b6ced 100644 (file)
@@ -62,6 +62,10 @@ private slots:
        void on_actionStartDirectoryWatcher_triggered();
        void on_actionAddRelatedEpisodeInfo_triggered();
 
+protected:
+       void dragEnterEvent(QDragEnterEvent *event);
+       void dropEvent(QDropEvent *event);
+
 private:
        Ui::MainWindow *ui;
        RenameSettingsDialog *renameSettingsDialog;