Browse Source

support drag and drop into edit area to open external files

Le Tan 8 years ago
parent
commit
8a6ce16db5
5 changed files with 44 additions and 5 deletions
  1. 1 2
      src/main.cpp
  2. 0 3
      src/veditarea.cpp
  3. 36 0
      src/veditwindow.cpp
  4. 6 0
      src/veditwindow.h
  5. 1 0
      src/vwebview.cpp

+ 1 - 2
src/main.cpp

@@ -125,9 +125,8 @@ int main(int argc, char *argv[])
                 // Need to use absolute path here since VNote may be launched
                 // in different working directory.
                 filePath = QDir::cleanPath(fi.absoluteFilePath());
+                filePaths.append(filePath);
             }
-
-            filePaths.append(filePath);
         }
     }
 

+ 0 - 3
src/veditarea.cpp

@@ -597,9 +597,6 @@ int VEditArea::focusNextWindow(int p_biaIdx)
 
 void VEditArea::moveCurrentTabOneSplit(bool p_right)
 {
-    if (splitter->count() < 2) {
-        return;
-    }
     getWindow(curWindowIndex)->moveCurrentTabOneSplit(p_right);
 }
 

+ 36 - 0
src/veditwindow.cpp

@@ -20,6 +20,7 @@ VEditWindow::VEditWindow(VNote *vnote, VEditArea *editArea, QWidget *parent)
     : QTabWidget(parent), vnote(vnote), m_editArea(editArea),
       m_curTabWidget(NULL), m_lastTabWidget(NULL)
 {
+    setAcceptDrops(true);
     initTabActions();
     setupCornerWidget();
 
@@ -808,6 +809,7 @@ void VEditWindow::moveCurrentTabOneSplit(bool p_right)
     if (idx == -1) {
         return;
     }
+
     moveTabOneSplit(idx, p_right);
 }
 
@@ -918,3 +920,37 @@ VEditTab* VEditWindow::getTab(int tabIndex) const
     return dynamic_cast<VEditTab *>(widget(tabIndex));
 }
 
+void VEditWindow::dragEnterEvent(QDragEnterEvent *p_event)
+{
+    if (p_event->mimeData()->hasFormat("text/uri-list")) {
+        p_event->acceptProposedAction();
+    }
+}
+
+void VEditWindow::dropEvent(QDropEvent *p_event)
+{
+    const QMimeData *mime = p_event->mimeData();
+    if (mime->hasFormat("text/uri-list") && mime->hasUrls()) {
+        // Open external files in this edit window.
+        QStringList files;
+        QList<QUrl> urls = mime->urls();
+        for (int i = 0; i < urls.size(); ++i) {
+            QString file;
+            if (urls[i].isLocalFile()) {
+                file = urls[i].toLocalFile();
+                QFileInfo fi(file);
+                if (fi.exists() && fi.isFile()) {
+                    file = QDir::cleanPath(fi.absoluteFilePath());
+                    files.append(file);
+                }
+            }
+        }
+
+        if (!files.isEmpty()) {
+            focusWindow();
+            g_vnote->getMainWindow()->openExternalFiles(files);
+        }
+
+        p_event->acceptProposedAction();
+    }
+}

+ 6 - 0
src/veditwindow.h

@@ -63,6 +63,12 @@ public:
 protected:
     void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
 
+    // To accept specific drop.
+    void dragEnterEvent(QDragEnterEvent *p_event) Q_DECL_OVERRIDE;
+
+    // Drop the data.
+    void dropEvent(QDropEvent *p_event) Q_DECL_OVERRIDE;
+
 signals:
     // Status of current VEditTab has update.
     void tabStatusUpdated(const VEditTabInfo &p_info);

+ 1 - 0
src/vwebview.cpp

@@ -19,6 +19,7 @@ static const QString c_ClipboardPropertyMark = "CopiedImageURLAltered";
 VWebView::VWebView(VFile *p_file, QWidget *p_parent)
     : QWebEngineView(p_parent), m_file(p_file), m_actionHooked(false)
 {
+    setAcceptDrops(false);
 }
 
 void VWebView::contextMenuEvent(QContextMenuEvent *p_event)