]> cloud.milkyroute.net Git - dolphin.git/commitdiff
support drag & drop for the treeview sidebar page
authorPeter Penz <peter.penz19@gmail.com>
Sun, 11 Mar 2007 09:15:08 +0000 (09:15 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 11 Mar 2007 09:15:08 +0000 (09:15 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=641405

src/sidebartreeview.cpp
src/sidebartreeview.h
src/treeviewsidebarpage.cpp
src/treeviewsidebarpage.h

index ccd90846398835d6b6d9ea1ce4ffadc85c2bd87e..52b6d54245b00bd983cf8d8218e11c42ee8a15bc 100644 (file)
@@ -1,6 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
+ *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -78,7 +77,7 @@ void SidebarTreeView::dropEvent(QDropEvent* event)
     }
     else {
         event->acceptProposedAction();
-        //m_controller->indicateDroppedUrls(urls, event->pos());
+        emit urlsDropped(urls, event->pos());
     }
 }
 
index acec0761459c93cc683bdd8a19f32fbbe67c1b30..8b1f039a01efbd4ae5ca025195882f1dea3376da 100644 (file)
@@ -1,6 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz                                      *
- *   peter.penz@gmx.at                                                     *
+ *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
 #ifndef SIDEBARTREEVIEW_H
 #define SIDEBARTREEVIEW_H
 
+#include <kurl.h>
 #include <QTreeView>
 
 class DolphinMainWindow;
 
 /**
- * @brief
+ * @brief Tree view widget which is used for the sidebar panel.
+ *
+ * @see TreeViewSidebarPage
  */
 class SidebarTreeView : public QTreeView
 {
@@ -36,6 +38,17 @@ public:
     explicit SidebarTreeView(DolphinMainWindow* mainWindow, QWidget* parent = 0);
     virtual ~SidebarTreeView();
 
+signals:
+   /**
+     * Is emitted if the URLs \a urls have been dropped.
+     * @param pos Position relative to the tree view where the
+     *            dropping has been done. It is recommended
+     *            to get the corresponding model index from
+     *            this position to find out the destination.
+     */
+    void urlsDropped(const KUrl::List& urls,
+                     const QPoint& pos);
+
 protected:
     virtual bool event(QEvent* event);
     virtual void dragEnterEvent(QDragEnterEvent* event);
index b1fcc8daa87655d9a055d68dde1f9d09a8bd6fa8..d9c2e8800c5b21679f6a8d3e04176b02b2fdfcbe 100644 (file)
@@ -78,8 +78,8 @@ TreeViewSidebarPage::TreeViewSidebarPage(DolphinMainWindow* mainWindow,
 
     connect(m_treeView, SIGNAL(clicked(const QModelIndex&)),
             this, SLOT(updateActiveView(const QModelIndex&)));
-    connect(m_treeView, SIGNAL(doubleClicked(const QModelIndex&)),
-            this, SLOT(slotDoubleClicked(const QModelIndex&)));
+    connect(m_treeView, SIGNAL(urlsDropped(const KUrl::List&, const QPoint&)),
+            this, SLOT(dropUrls(const KUrl::List&, const QPoint&)));
 
     QVBoxLayout* layout = new QVBoxLayout(this);
     layout->addWidget(m_treeView);
@@ -201,6 +201,24 @@ void TreeViewSidebarPage::updateActiveView(const QModelIndex& index)
     }
 }
 
+void TreeViewSidebarPage::dropUrls(const KUrl::List& urls,
+                                   const QPoint& pos)
+{
+    const QModelIndex index = m_treeView->indexAt(pos);
+    if (index.isValid()) {
+#if defined(USE_PROXY_MODEL)
+        const QModelIndex& dirIndex = m_proxyModel->mapToSource(index);
+        KFileItem* item = m_dirModel->itemForIndex(dirIndex);
+#else
+        KFileItem* item = m_dirModel->itemForIndex(index);
+#endif
+        Q_ASSERT(item != 0);
+        if (item->isDir()) {
+            mainWindow()->dropUrls(urls, item->url());
+        }
+    }
+}
+
 void TreeViewSidebarPage::connectToActiveView()
 {
     const QWidget* parent = parentWidget();
index 9810908558e55140f29a2ed2d7e251dff78a6fda..ca98277eb72d4e6d78ddb82fec7c6fc370c793ef 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>
+ *   Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                  *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -25,7 +25,6 @@
 
 class KDirLister;
 class KDirModel;
-class KUrl;
 
 class DolphinSortFilterProxyModel;
 class SidebarTreeView;
@@ -73,6 +72,12 @@ private slots:
      */
     void updateActiveView(const QModelIndex& index);
 
+    /**
+     * Is emitted if the URLs \a urls have been dropped
+     * to the position \a pos. */
+    void dropUrls(const KUrl::List& urls,
+                  const QPoint& pos);
+
 private:
     /**
      * Connects to signals from the currently active Dolphin view to get
@@ -88,4 +93,4 @@ private:
     KUrl m_selectedUrl;
 };
 
-#endif // BOOKMARKSSIDEBARPAGE_H
+#endif // TREEVIEWSIDEBARPAGE_H