]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistview.cpp
Enable basic drag and drop support for the Places Panel
[dolphin.git] / src / kitemviews / kitemlistview.cpp
index 2177c629653f17ee33f4af07568b24091341b065..ebcf48680388b28512b304b31d2be84afc0d82a7 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <QCursor>
 #include <QGraphicsSceneMouseEvent>
 
 #include <QCursor>
 #include <QGraphicsSceneMouseEvent>
+#include <QGraphicsView>
 #include <QPainter>
 #include <QPropertyAnimation>
 #include <QStyle>
 #include <QPainter>
 #include <QPropertyAnimation>
 #include <QStyle>
@@ -566,8 +567,21 @@ KItemListHeader* KItemListView::header() const
 
 QPixmap KItemListView::createDragPixmap(const QSet<int>& indexes) const
 {
 
 QPixmap KItemListView::createDragPixmap(const QSet<int>& indexes) const
 {
-    Q_UNUSED(indexes);
-    return QPixmap();
+    QPixmap pixmap;
+
+    if (indexes.count() == 1) {
+        KItemListWidget* item = m_visibleItems.value(indexes.toList().first());
+        QGraphicsView* graphicsView = scene()->views()[0];
+        if (item && graphicsView) {
+            pixmap = item->createDragPixmap(0, graphicsView);
+        }
+    } else {
+        // TODO: Not implemented yet. Probably extend the interface
+        // from KItemListWidget::createDragPixmap() to return a pixmap
+        // that can be used for multiple indexes.
+    }
+
+    return pixmap;
 }
 
 void KItemListView::editRole(int index, const QByteArray& role)
 }
 
 void KItemListView::editRole(int index, const QByteArray& role)
@@ -960,9 +974,17 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
 #endif
         m_endTransactionAnimationHint = NoAnimation;
         endTransaction();
 #endif
         m_endTransactionAnimationHint = NoAnimation;
         endTransaction();
+
         updateSiblingsInformation();
     }
 
         updateSiblingsInformation();
     }
 
+    if (m_grouped && (hasMultipleRanges || itemRanges.first().count < m_model->count())) {
+        // In case if items of the same group have been inserted before an item that
+        // currently represents the first item of the group, the group header of
+        // this item must be removed.
+        updateVisibleGroupHeaders();
+    }
+
     if (useAlternateBackgrounds()) {
         updateAlternateBackgrounds();
     }
     if (useAlternateBackgrounds()) {
         updateAlternateBackgrounds();
     }
@@ -1078,6 +1100,12 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
         updateSiblingsInformation();
     }
 
         updateSiblingsInformation();
     }
 
+    if (m_grouped && (hasMultipleRanges || m_model->count() > 0)) {
+        // In case if the first item of a group has been removed, the group header
+        // must be applied to the next visible item.
+        updateVisibleGroupHeaders();
+    }
+
     if (useAlternateBackgrounds()) {
         updateAlternateBackgrounds();
     }
     if (useAlternateBackgrounds()) {
         updateAlternateBackgrounds();
     }
@@ -1892,8 +1920,10 @@ void KItemListView::updateGroupHeaderLayout(KItemListWidget* widget)
         // In the vertical scroll orientation the group header should always span
         // the whole width no matter which temporary position the parent widget
         // has. In this case the x-position and width will be adjusted manually.
         // In the vertical scroll orientation the group header should always span
         // the whole width no matter which temporary position the parent widget
         // has. In this case the x-position and width will be adjusted manually.
-        groupHeader->setPos(-widget->x(), -groupHeaderRect.height());
-        groupHeader->resize(size().width(), groupHeaderRect.size().height());
+        const qreal x = -widget->x() - itemOffset();
+        const qreal width = maximumItemOffset();
+        groupHeader->setPos(x, -groupHeaderRect.height());
+        groupHeader->resize(width, groupHeaderRect.size().height());
     } else {
         groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -widget->y());
         groupHeader->resize(groupHeaderRect.size());
     } else {
         groupHeader->setPos(groupHeaderRect.x() - itemRect.x(), -widget->y());
         groupHeader->resize(groupHeaderRect.size());