]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistview.cpp
Places Panel: Prepare code to save state of bookmarks
[dolphin.git] / src / kitemviews / kitemlistview.cpp
index 8ecd1e2126fc3cf58ed61a69f269c6c8f45aa198..d1d8749aa851f20733808d3d575cc279d9a2c14d 100644 (file)
@@ -761,13 +761,8 @@ void KItemListView::onControllerChanged(KItemListController* current, KItemListC
 
 void KItemListView::onModelChanged(KItemModelBase* current, KItemModelBase* previous)
 {
+    Q_UNUSED(current);
     Q_UNUSED(previous);
-
-    m_sizeHintResolver->clearCache();
-    const int itemCount = current->count();
-    if (itemCount > 0) {
-        m_sizeHintResolver->itemsInserted(0, itemCount);
-    }
 }
 
 void KItemListView::onScrollOrientationChanged(Qt::Orientation current, Qt::Orientation previous)
@@ -927,6 +922,13 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
             }
         }
 
+        // 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.
+        if (m_grouped && index + count < m_model->count()) {
+            updateGroupHeaderForWidget(m_visibleItems.value(index + count));
+        }
+
         if (m_model->count() == count && m_activeTransactions == 0) {
             // Check whether a scrollbar is required to show the inserted items. In this case
             // the size of the layouter will be decreased before calling doLayout(): This prevents
@@ -1054,6 +1056,12 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
             }
         }
 
+        // In case if the first item of a group has been removed, the group header
+        // must be applied to the next visible item.
+        if (m_grouped && index < m_model->count()) {
+            updateGroupHeaderForWidget(m_visibleItems.value(index));
+        }
+
         if (!hasMultipleRanges) {
             // The decrease-layout-size optimization in KItemListView::slotItemsInserted()
             // assumes an updated geometry. If items are removed during an active transaction,
@@ -1446,6 +1454,8 @@ void KItemListView::setModel(KItemModelBase* model)
                    this,    SLOT(slotSortRoleChanged(QByteArray,QByteArray)));
     }
 
+    m_sizeHintResolver->clearCache();
+
     m_model = model;
     m_layouter->setModel(model);
     m_grouped = model->groupedSorting();
@@ -1468,6 +1478,7 @@ void KItemListView::setModel(KItemModelBase* model)
 
         const int itemCount = m_model->count();
         if (itemCount > 0) {
+            m_sizeHintResolver->itemsInserted(0, itemCount);
             slotItemsInserted(KItemRangeList() << KItemRange(0, itemCount));
         }
     }
@@ -1703,17 +1714,22 @@ bool KItemListView::moveWidget(KItemListWidget* widget,const QPointF& newPos)
 
     bool startMovingAnim = false;
 
-    // When having a grid the moving-animation should only be started, if it is done within
-    // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
-    // Otherwise instead of a moving-animation a create-animation on the new position will be used
-    // instead. This is done to prevent overlapping (and confusing) moving-animations.
-    const int index = widget->index();
-    const Cell cell = m_visibleCells.value(index);
-    if (cell.column >= 0 && cell.row >= 0) {
-        if (scrollOrientation() == Qt::Vertical) {
-            startMovingAnim = (cell.row == m_layouter->itemRow(index));
-        } else {
-            startMovingAnim = (cell.column == m_layouter->itemColumn(index));
+    if (m_itemSize.isEmpty()) {
+        // The items are not aligned in a grid but either as columns or rows.
+        startMovingAnim = !supportsItemExpanding();
+    } else {
+        // When having a grid the moving-animation should only be started, if it is done within
+        // one row in the vertical scroll-orientation or one column in the horizontal scroll-orientation.
+        // Otherwise instead of a moving-animation a create-animation on the new position will be used
+        // instead. This is done to prevent overlapping (and confusing) moving-animations.
+        const int index = widget->index();
+        const Cell cell = m_visibleCells.value(index);
+        if (cell.column >= 0 && cell.row >= 0) {
+            if (scrollOrientation() == Qt::Vertical) {
+                startMovingAnim = (cell.row == m_layouter->itemRow(index));
+            } else {
+                startMovingAnim = (cell.column == m_layouter->itemColumn(index));
+            }
         }
     }
 
@@ -1889,8 +1905,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.
-        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());
@@ -2223,6 +2241,12 @@ bool KItemListView::changesItemGridLayout(const QSizeF& newGridSize,
 
 bool KItemListView::animateChangedItemCount(int changedItemCount) const
 {
+    if (m_itemSize.isEmpty()) {
+        // We have only columns or only rows, but no grid: An animation is usually
+        // welcome when inserting or removing items.
+        return !supportsItemExpanding();
+    }
+
     if (m_layouter->size().isEmpty() || m_layouter->itemSize().isEmpty()) {
         return false;
     }