]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Further preperations for drag & drop support in the places panel
authorPeter Penz <peter.penz19@gmail.com>
Sat, 26 May 2012 11:40:48 +0000 (13:40 +0200)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 26 May 2012 11:41:30 +0000 (13:41 +0200)
src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemlistview.cpp
src/panels/places/placesitemmodel.cpp
src/panels/places/placesitemmodel.h
src/panels/places/placespanel.cpp
src/panels/places/placespanel.h
src/views/dolphinitemlistview.cpp

index 645b2d34a0ecc6a30275baf20d1e28663c75d103..1b9c53ccffe9260e479af171a3fa745b02da3d09 100644 (file)
@@ -795,12 +795,10 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent* event, cons
             if (m_model->supportsDropping(index)) {
                 newHoveredWidget->setHovered(true);
             } else if (m_model->sortRole().isEmpty()) {
-                // The model supports the inserting of items on
-                // the given index as no sort-role has been
-                // specified. Assure that a drag-indicator
+                // The model supports inserting of items on
+                // the given index. Assure that a drop-indicator
                 // is shown by the view.
-                const int dropIndex = m_view->showDropIndicator(pos);
-                Q_UNUSED(dropIndex); // TODO
+                m_view->showDropIndicator(pos);
             }
             emit itemHovered(index);
 
@@ -825,8 +823,15 @@ bool KItemListController::dropEvent(QGraphicsSceneDragDropEvent* event, const QT
     m_view->setAutoScroll(false);
 
     const QPointF pos = transform.map(event->pos());
-    const int index = m_view->itemAt(pos);
-    emit itemDropEvent(index, event);
+    if (m_model->sortRole().isEmpty()) {
+        // The model supports inserting of items on
+        // a given index.
+        const int dropIndex = m_view->showDropIndicator(pos);
+        m_view->hideDropIndicator();
+        emit itemDropEvent(dropIndex, event);
+    } else {
+        emit itemDropEvent(m_view->itemAt(pos), event);
+    }
 
     return true;
 }
index 1586c9d96bd705cc304e5541b5b6df89a3987f87..ee69c89904850209beea50d87274861756c53c29 100644 (file)
@@ -2313,15 +2313,20 @@ int KItemListView::showDropIndicator(const QPointF& pos)
         const QPointF mappedPos = widget->mapFromItem(this, pos);
         const QRectF rect = itemRect(widget->index());
         if (mappedPos.y() >= 0 && mappedPos.y() <= rect.height()) {
-            const qreal y = (mappedPos.y () < rect.height() / 2) ?
-                            rect.top() : rect.bottom();
+            const bool isAboveItem = (mappedPos.y () < rect.height() / 2);
+            const qreal y = isAboveItem ? rect.top() : rect.bottom();
 
             const QRectF draggingInsertIndicator(rect.left(), y, rect.width(), 1);
             if (m_dropIndicator != draggingInsertIndicator) {
                 m_dropIndicator = draggingInsertIndicator;
                 update();
             }
-            return widget->index();
+
+            int index = widget->index();
+            if (!isAboveItem) {
+                ++index;
+            }
+            return index;
         }
     }
 
index 2a3dfa441826c83e83c9f065d229c0accc49c891..6723391db4efff3d2765bf17bb6389fe00e74e57 100644 (file)
@@ -331,14 +331,21 @@ QMimeData* PlacesItemModel::createMimeData(const QSet<int>& indexes) const
     if (!urls.isEmpty()) {
         urls.populateMimeData(mimeData);
     }
-
-    const QString internalMimeType = "application/x-dolphinplacesmodel-" +
-                                     QString::number((qptrdiff)this);
-    mimeData->setData(internalMimeType, itemData);
+    mimeData->setData(internalMimeType(), itemData);
 
     return mimeData;
 }
 
+void PlacesItemModel::dropMimeData(int index, const QMimeData* mimeData)
+{
+    Q_UNUSED(index); // TODO
+    if (mimeData->hasFormat(internalMimeType())) {
+        // TODO
+    } else if (mimeData->hasFormat("text/uri-list")) {
+        // TODO
+    }
+}
+
 KUrl PlacesItemModel::convertedUrl(const KUrl& url)
 {
     KUrl newUrl = url;
@@ -879,6 +886,12 @@ void PlacesItemModel::triggerBookmarksSaving()
     }
 }
 
+QString PlacesItemModel::internalMimeType() const
+{
+    return "application/x-dolphinplacesmodel-" +
+            QString::number((qptrdiff)this);
+}
+
 bool PlacesItemModel::equalBookmarkIdentifiers(const KBookmark& b1, const KBookmark& b2)
 {
     const QString udi1 = b1.metaDataItem("UDI");
index 18264f06a8163837f0fb5f224b0684014aca5cc9..95a994e769dd950484a3ef93ce14a3886d2348f6 100644 (file)
@@ -108,6 +108,8 @@ public:
     /** @reimp */
     virtual QMimeData* createMimeData(const QSet<int>& indexes) const;
 
+    void dropMimeData(int index, const QMimeData* mimeData);
+
     /**
      * @return Converts the URL, which contains "virtual" URLs for system-items like
      *         "search:/documents" into a Nepomuk-Query-URL that will be handled by
@@ -195,6 +197,8 @@ private:
      */
     void triggerBookmarksSaving();
 
+    QString internalMimeType() const;
+
     /**
      * @return True if the bookmarks have the same identifiers. The identifier
      *         is the unique "ID"-property in case if no UDI is set, otherwise
index 968c9af455bacf135089fd519a8888ae2fd6a47e..deef429358b055ba128f78c54cf31a57f1a51b20 100644 (file)
@@ -43,6 +43,7 @@
 #include "placesitemlistwidget.h"
 #include "placesitemmodel.h"
 #include <views/draganddrophelper.h>
+#include <QGraphicsSceneDragDropEvent>
 #include <QVBoxLayout>
 #include <QShowEvent>
 
@@ -88,6 +89,7 @@ void PlacesPanel::showEvent(QShowEvent* event)
         connect(m_controller, SIGNAL(itemMiddleClicked(int)), this, SLOT(slotItemMiddleClicked(int)));
         connect(m_controller, SIGNAL(itemContextMenuRequested(int,QPointF)), this, SLOT(slotItemContextMenuRequested(int,QPointF)));
         connect(m_controller, SIGNAL(viewContextMenuRequested(QPointF)), this, SLOT(slotViewContextMenuRequested(QPointF)));
+        connect(m_controller, SIGNAL(itemDropEvent(int,QGraphicsSceneDragDropEvent*)), this, SLOT(slotItemDropEvent(int,QGraphicsSceneDragDropEvent*)));
 
         KItemListContainer* container = new KItemListContainer(m_controller, this);
         container->setEnabledFrame(false);
@@ -252,6 +254,11 @@ void PlacesPanel::slotViewContextMenuRequested(const QPointF& pos)
     selectClosestItem();
 }
 
+void PlacesPanel::slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event)
+{
+    m_model->dropMimeData(index, event->mimeData());
+}
+
 void PlacesPanel::slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent)
 {
     Q_UNUSED(parent);
index b3f259f563ef3637d187eb2444288063f9ae0815..d78b4ba610ed602a03010f917c760066c5d57703 100644 (file)
@@ -28,6 +28,7 @@ class KItemListController;
 class PlacesItemEditDialog;
 class PlacesItem;
 class PlacesItemModel;
+class QGraphicsSceneDragDropEvent;
 
 /**
  * @brief Combines bookmarks and mounted devices as list.
@@ -54,6 +55,7 @@ private slots:
     void slotItemMiddleClicked(int index);
     void slotItemContextMenuRequested(int index, const QPointF& pos);
     void slotViewContextMenuRequested(const QPointF& pos);
+    void slotItemDropEvent(int index, QGraphicsSceneDragDropEvent* event);
     void slotUrlsDropped(const KUrl& dest, QDropEvent* event, QWidget* parent);
     void slotTrashUpdated(KJob* job);
 
index 156ca204f2edcc56ee7d5786666cd14cf2486367..a031b1699f9e4bee94eea38b308cc113dca16c54 100644 (file)
@@ -173,7 +173,7 @@ void DolphinItemListView::updateGridSize()
         if (previewsShown()) {
             // Optimize the width for previews with a 3:2 aspect ratio instead
             // of a 1:1 ratio to avoid wasting too much vertical space when
-            // photos.
+            // showing photos.
             const int minWidth = iconSize * 3 / 2;
             itemWidth = qMax(itemWidth, minWidth);
         }