]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Reanimated drag & drop support again after introducing the DolphinController. It...
authorPeter Penz <peter.penz19@gmail.com>
Fri, 16 Feb 2007 17:03:02 +0000 (17:03 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 16 Feb 2007 17:03:02 +0000 (17:03 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=634228

src/dolphincontextmenu.cpp
src/dolphincontextmenu.h
src/dolphincontroller.cpp
src/dolphincontroller.h
src/dolphindetailsview.cpp
src/dolphiniconsview.cpp
src/dolphinview.cpp
src/dolphinview.h

index 8cc79e9554363e64ef1683a48a192d21f233555d..f40b4787881d79e87aa903584be60774e25f2112 100644 (file)
 #include <QDir>
 
 DolphinContextMenu::DolphinContextMenu(DolphinView* parent,
 #include <QDir>
 
 DolphinContextMenu::DolphinContextMenu(DolphinView* parent,
-                                       KFileItem* fileInfo,
-                                       const QPoint& pos) :
+                                       KFileItem* fileInfo) :
    m_dolphinView(parent),
    m_dolphinView(parent),
-   m_fileInfo(fileInfo),
-   m_pos(pos)
+   m_fileInfo(fileInfo)
 {
 }
 
 {
 }
 
@@ -104,7 +102,7 @@ void DolphinContextMenu::openViewportContextMenu()
 
     QAction* propertiesAction = popup->addAction(i18n("Properties..."));
 
 
     QAction* propertiesAction = popup->addAction(i18n("Properties..."));
 
-    QAction* activatedAction = popup->exec(m_pos);
+    QAction* activatedAction = popup->exec(QCursor::pos());
     if (activatedAction == propertiesAction) {
         new KPropertiesDialog(dolphin->activeView()->url());
     }
     if (activatedAction == propertiesAction) {
         new KPropertiesDialog(dolphin->activeView()->url());
     }
@@ -185,7 +183,7 @@ void DolphinContextMenu::openItemContextMenu()
     QAction* propertiesAction = dolphin->actionCollection()->action("properties");
     popup->addAction(propertiesAction);
 
     QAction* propertiesAction = dolphin->actionCollection()->action("properties");
     popup->addAction(propertiesAction);
 
-    QAction* activatedAction = popup->exec(m_pos);
+    QAction* activatedAction = popup->exec(QCursor::pos());
 
     if ((bookmarkAction!= 0) && (activatedAction == bookmarkAction)) {
         const KUrl selectedUrl(m_fileInfo->url());
 
     if ((bookmarkAction!= 0) && (activatedAction == bookmarkAction)) {
         const KUrl selectedUrl(m_fileInfo->url());
index 69554b01f710346ac59ea7030c6042ca1d463ee2..82bc9f24d9ed61ba843793e9d8735482ba5072bb 100644 (file)
@@ -57,11 +57,9 @@ public:
      * @fileInfo  Pointer to the file item the context menu
      *            is applied. If 0 is passed, the context menu
      *            is above the viewport.
      * @fileInfo  Pointer to the file item the context menu
      *            is applied. If 0 is passed, the context menu
      *            is above the viewport.
-     * @pos       Position of the upper left edge of the context menu.
      */
     DolphinContextMenu(DolphinView* parent,
      */
     DolphinContextMenu(DolphinView* parent,
-                       KFileItem* fileInfo,
-                       const QPoint& pos);
+                       KFileItem* fileInfo);
 
     virtual ~DolphinContextMenu();
 
 
     virtual ~DolphinContextMenu();
 
@@ -104,7 +102,6 @@ private:
 
     DolphinView* m_dolphinView;
     KFileItem* m_fileInfo;
 
     DolphinView* m_dolphinView;
     KFileItem* m_fileInfo;
-    QPoint m_pos;
 
     struct Entry {
         int type;
 
     struct Entry {
         int type;
index c39776349c47ff8486ce44a5ded9e2d1469dc03b..8089cfd2b1451dbc4596b2d5c05eb59e0cf8b813 100644 (file)
@@ -28,11 +28,10 @@ DolphinController::~DolphinController()
 {
 }
 
 {
 }
 
-void DolphinController::triggerContextMenuRequest(const QPoint& pos,
-                                                  const QPoint& globalPos)
+void DolphinController::triggerContextMenuRequest(const QPoint& pos)
 {
     emit activated();
 {
     emit activated();
-    emit requestContextMenu(pos, globalPos);
+    emit requestContextMenu(pos);
 }
 
 void DolphinController::triggerActivation()
 }
 
 void DolphinController::triggerActivation()
@@ -40,6 +39,13 @@ void DolphinController::triggerActivation()
     emit activated();
 }
 
     emit activated();
 }
 
+void DolphinController::indicateDroppedUrls(const KUrl::List& urls,
+                                            const QPoint& pos)
+{
+    emit urlsDropped(urls, pos);
+}
+
+
 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting)
 {
     emit sortingChanged(sorting);
 void DolphinController::indicateSortingChange(DolphinView::Sorting sorting)
 {
     emit sortingChanged(sorting);
index 8229ade1eda0f6b457cea45d472ccab77a3eb984..bde01c28ecd378f7cfe5ebbf402156905842c288 100644 (file)
@@ -56,11 +56,13 @@ public:
     void setUrl(const KUrl& url) { m_url = url; }
     const KUrl& url() const { return m_url; }
 
     void setUrl(const KUrl& url) { m_url = url; }
     const KUrl& url() const { return m_url; }
 
-    void triggerContextMenuRequest(const QPoint& pos,
-                                   const QPoint& globalPos);
+    void triggerContextMenuRequest(const QPoint& pos);
 
     void triggerActivation();
 
 
     void triggerActivation();
 
+    void indicateDroppedUrls(const KUrl::List& urls,
+                             const QPoint& pos);
+
     void indicateSortingChange(DolphinView::Sorting sorting);
 
     void indicateSortOrderChange(Qt::SortOrder order);
     void indicateSortingChange(DolphinView::Sorting sorting);
 
     void indicateSortOrderChange(Qt::SortOrder order);
@@ -76,17 +78,24 @@ signals:
      *                  context menu should be opened. It is recommended
      *                  to get the corresponding model index from
      *                  this position.
      *                  context menu should be opened. It is recommended
      *                  to get the corresponding model index from
      *                  this position.
-     * @param globalPos Global position where the context menu should
-     *                  be opened.
      */
      */
-    void requestContextMenu(const QPoint& pos,
-                            const QPoint& globalPos);
+    void requestContextMenu(const QPoint& pos);
 
     /**
      * Is emitted if the view has been activated by e. g. a mouse click.
      */
     void activated();
 
 
     /**
      * Is emitted if the view has been activated by e. g. a mouse click.
      */
     void activated();
 
+    /**
+     * Is emitted if the URLs \a urls have been dropped.
+     * @param pos Position relative to the view widget 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);
+
     /** Is emitted if the sorting has been changed to \a sorting. */
     void sortingChanged(DolphinView::Sorting sorting);
 
     /** Is emitted if the sorting has been changed to \a sorting. */
     void sortingChanged(DolphinView::Sorting sorting);
 
index 411a410d3a782c681b4f7dff29bb8251c5d3db9f..0b350f8b2fb85d643c18b747ddd701a77180eb1b 100644 (file)
@@ -91,8 +91,7 @@ QStyleOptionViewItem DolphinDetailsView::viewOptions() const
 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
 {
     QTreeView::contextMenuEvent(event);
 void DolphinDetailsView::contextMenuEvent(QContextMenuEvent* event)
 {
     QTreeView::contextMenuEvent(event);
-    m_controller->triggerContextMenuRequest(event->pos(),
-                                            event->globalPos());
+    m_controller->triggerContextMenuRequest(event->pos());
 }
 
 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
 }
 
 void DolphinDetailsView::mouseReleaseEvent(QMouseEvent* event)
@@ -110,18 +109,14 @@ void DolphinDetailsView::dragEnterEvent(QDragEnterEvent* event)
 
 void DolphinDetailsView::dropEvent(QDropEvent* event)
 {
 
 void DolphinDetailsView::dropEvent(QDropEvent* event)
 {
-    QTreeView::dropEvent(event);
-    // TODO: temporary deactivated until DolphinController will support this
-
-    /*const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
-    if (!urls.isEmpty()) {
+    const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
+    if (urls.isEmpty() || (event->source() == this)) {
+        QTreeView::dropEvent(event);
+    }
+    else {
         event->acceptProposedAction();
         event->acceptProposedAction();
-
-        // TODO: handle dropping above a directory
-
-        const KUrl& destination = m_controller->url();
-        m_controller->emitDropUrlsSignal(urls, destination);
-    }*/
+        m_controller->indicateDroppedUrls(urls, event->pos());
+    }
 }
 
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
 }
 
 void DolphinDetailsView::setSortIndicatorSection(DolphinView::Sorting sorting)
index 7c32715db8b6b19cb0c0395560e3ada6390f5f23..3f9df031665c207e4e0437725de97a09bc86fab4 100644 (file)
@@ -65,8 +65,7 @@ QStyleOptionViewItem DolphinIconsView::viewOptions() const
 void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
 {
     QListView::contextMenuEvent(event);
 void DolphinIconsView::contextMenuEvent(QContextMenuEvent* event)
 {
     QListView::contextMenuEvent(event);
-    m_controller->triggerContextMenuRequest(event->pos(),
-                                            event->globalPos());
+    m_controller->triggerContextMenuRequest(event->pos());
 }
 
 void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
 }
 
 void DolphinIconsView::mouseReleaseEvent(QMouseEvent* event)
@@ -84,31 +83,14 @@ void DolphinIconsView::dragEnterEvent(QDragEnterEvent* event)
 
 void DolphinIconsView::dropEvent(QDropEvent* event)
 {
 
 void DolphinIconsView::dropEvent(QDropEvent* event)
 {
-    QListView::dropEvent(event);
-    // TODO: temporary deactivated until DolphinController will support this
-
-    /*    KFileItem* directory = 0;
-    bool dropIntoDirectory = false;
-    const QModelIndex index = indexAt(event->pos());
-    if (index.isValid()) {
-        KFileItem* item = m_dolphinView->fileItem(index);
-        assert(item != 0);
-        dropIntoDirectory = item->isDir();
-        if (dropIntoDirectory) {
-            directory = item;
-        }
-    }
-
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
     const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData());
-    if (urls.isEmpty() || (event->source() == this) && !dropIntoDirectory) {
+    if (urls.isEmpty() || (event->source() == this)) {
         QListView::dropEvent(event);
     }
     else {
         event->acceptProposedAction();
         QListView::dropEvent(event);
     }
     else {
         event->acceptProposedAction();
-        const KUrl& destination = (directory == 0) ? m_dolphinView->url() :
-                                                     directory->url();
-        m_dolphinView->mainWindow()->dropUrls(urls, destination);
-    }*/
+        m_controller->indicateDroppedUrls(urls, event->pos());
+    }
 }
 
 #include "dolphiniconsview.moc"
 }
 
 #include "dolphiniconsview.moc"
index d1416c40a39c05c7677e2e9bcb9eb7420e2ffc87..920224583e21043f3c0127fd97021484275e9da7 100644 (file)
@@ -112,8 +112,10 @@ DolphinView::DolphinView(DolphinMainWindow* mainWindow,
     m_proxyModel->setSourceModel(m_dirModel);
 
     m_controller = new DolphinController(this);
     m_proxyModel->setSourceModel(m_dirModel);
 
     m_controller = new DolphinController(this);
-    connect(m_controller, SIGNAL(requestContextMenu(const QPoint&, const QPoint&)),
-            this, SLOT(openContextMenu(const QPoint&, const QPoint&)));
+    connect(m_controller, SIGNAL(requestContextMenu(const QPoint&)),
+            this, SLOT(openContextMenu(const QPoint&)));
+    connect(m_controller, SIGNAL(urlsDropped(const KUrl::List&, const QPoint&)),
+            this, SLOT(dropUrls(const KUrl::List&, const QPoint&)));
     connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
             this, SLOT(updateSorting(DolphinView::Sorting)));
     connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
     connect(m_controller, SIGNAL(sortingChanged(DolphinView::Sorting)),
             this, SLOT(updateSorting(DolphinView::Sorting)));
     connect(m_controller, SIGNAL(sortOrderChanged(Qt::SortOrder)),
@@ -855,7 +857,7 @@ void DolphinView::changeNameFilter(const QString& nameFilter)
 #endif
 }
 
 #endif
 }
 
-void DolphinView::openContextMenu(const QPoint& pos, const QPoint& globalPos)
+void DolphinView::openContextMenu(const QPoint& pos)
 {
     KFileItem* item = 0;
 
 {
     KFileItem* item = 0;
 
@@ -864,10 +866,29 @@ void DolphinView::openContextMenu(const QPoint& pos, const QPoint& globalPos)
         item = fileItem(index);
     }
 
         item = fileItem(index);
     }
 
-    DolphinContextMenu contextMenu(this, item, globalPos);
+    DolphinContextMenu contextMenu(this, item);
     contextMenu.open();
 }
 
     contextMenu.open();
 }
 
+void DolphinView::dropUrls(const KUrl::List& urls,
+                           const QPoint& pos)
+{
+    KFileItem* directory = 0;
+    const QModelIndex index = itemView()->indexAt(pos);
+    if (index.isValid()) {
+        KFileItem* item = fileItem(index);
+        assert(item != 0);
+        if (item->isDir()) {
+            // the URLs are dropped above a directory
+            directory = item;
+        }
+    }
+
+    const KUrl& destination = (directory == 0) ? url() :
+                                                 directory->url();
+    m_mainWindow->dropUrls(urls, destination);
+}
+
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
 {
     ViewProperties props(url());
 void DolphinView::updateSorting(DolphinView::Sorting sorting)
 {
     ViewProperties props(url());
index 875b6b1144d9b4afe9a88713dd118a1a590ba90a..5b820fe8e631b02220afebc2420e4f366d7ee8e7 100644 (file)
@@ -430,7 +430,20 @@ private slots:
      */
     void changeNameFilter(const QString& nameFilter);
 
      */
     void changeNameFilter(const QString& nameFilter);
 
-    void openContextMenu(const QPoint& pos, const QPoint& globalPos);
+    /**
+     * Opens the context menu on position \a pos. The position
+     * is used to check whether the context menu is related to an
+     * item or to the viewport.
+     */
+    void openContextMenu(const QPoint& pos);
+
+    /**
+     * Drops the URLs \a urls at the position \a pos.
+     * The position is used to check whether the dropping
+     * is done above an item or above the viewport.
+     */
+    void dropUrls(const KUrl::List& urls,
+                  const QPoint& pos);
 
     /**
      * Updates the view properties of the current URL to the
 
     /**
      * Updates the view properties of the current URL to the