]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix alternate background issue
authorPeter Penz <peter.penz19@gmail.com>
Tue, 20 Mar 2012 12:22:12 +0000 (13:22 +0100)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 20 Mar 2012 16:23:27 +0000 (17:23 +0100)
When items get inserted or deleted, the alternate background
must be updated.

src/kitemviews/kitemlistview.cpp
src/kitemviews/kitemlistview.h

index d7777b541380ed3c0c04df22b9fb15df4496e739..678b09bffc8672c6f656eb3e22b298f3dde892a6 100644 (file)
@@ -157,21 +157,17 @@ void KItemListView::setItemSize(const QSizeF& itemSize)
                                                 itemSize,
                                                 m_layouter->itemMargin());
 
-    const bool updateAlternateBackgrounds = (m_visibleRoles.count() > 1) &&
-                                            (( m_itemSize.isEmpty() && !itemSize.isEmpty()) ||
-                                             (!m_itemSize.isEmpty() && itemSize.isEmpty()));
+    const bool alternateBackgroundsChanged = (m_visibleRoles.count() > 1) &&
+                                             (( m_itemSize.isEmpty() && !itemSize.isEmpty()) ||
+                                              (!m_itemSize.isEmpty() && itemSize.isEmpty()));
 
     m_itemSize = itemSize;
 
-    if (updateAlternateBackgrounds) {
+    if (alternateBackgroundsChanged) {
         // For an empty item size alternate backgrounds are drawn if more than
         // one role is shown. Assure that the backgrounds for visible items are
         // updated when changing the size in this context.
-        QHashIterator<int, KItemListWidget*> it(m_visibleItems);
-        while (it.hasNext()) {
-            it.next();
-            updateAlternateBackgroundForWidget(it.value());
-        }
+        updateAlternateBackgrounds();
     }
 
     if (itemSize.isEmpty()) {
@@ -253,9 +249,9 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
     const QList<QByteArray> previousRoles = m_visibleRoles;
     m_visibleRoles = roles;
 
-    const bool updateAlternateBackgrounds = m_itemSize.isEmpty() &&
-                                            ((roles.count() > 1 && previousRoles.count() <= 1) ||
-                                             (roles.count() <= 1 && previousRoles.count() > 1));
+    const bool alternateBackgroundsChanged = m_itemSize.isEmpty() &&
+                                             ((roles.count() > 1 && previousRoles.count() <= 1) ||
+                                              (roles.count() <= 1 && previousRoles.count() > 1));
 
     QHashIterator<int, KItemListWidget*> it(m_visibleItems);
     while (it.hasNext()) {
@@ -263,7 +259,7 @@ void KItemListView::setVisibleRoles(const QList<QByteArray>& roles)
         KItemListWidget* widget = it.value();
         widget->setVisibleRoles(roles);
         widget->setVisibleRolesSizes(m_stretchedVisibleRolesSizes);
-        if (updateAlternateBackgrounds) {
+        if (alternateBackgroundsChanged) {
             updateAlternateBackgroundForWidget(widget);
         }
     }
@@ -898,6 +894,10 @@ void KItemListView::slotItemsInserted(const KItemRangeList& itemRanges)
         endTransaction();
         updateSiblingsInformation();
     }
+
+    if (useAlternateBackgrounds()) {
+        updateAlternateBackgrounds();
+    }
 }
 
 void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
@@ -999,6 +999,10 @@ void KItemListView::slotItemsRemoved(const KItemRangeList& itemRanges)
         endTransaction();
         updateSiblingsInformation();
     }
+
+    if (useAlternateBackgrounds()) {
+        updateAlternateBackgrounds();
+    }
 }
 
 void KItemListView::slotItemsMoved(const KItemRange& itemRange, const QList<int>& movedToIndexes)
@@ -1085,13 +1089,8 @@ void KItemListView::slotGroupedSortingChanged(bool current)
         // Changing the group mode requires to update the alternate backgrounds
         // as with the enabled group mode the altering is done on base of the first
         // group item.
-        QHashIterator<int, KItemListWidget*> it(m_visibleItems);
-        while (it.hasNext()) {
-            it.next();
-            updateAlternateBackgroundForWidget(it.value());
-        }
+        updateAlternateBackgrounds();
     }
-
     updateSiblingsInformation();
     doLayout(NoAnimation);
 }
@@ -1875,6 +1874,15 @@ int KItemListView::groupIndexForItem(int index) const
     return mid;
 }
 
+void KItemListView::updateAlternateBackgrounds()
+{
+    QHashIterator<int, KItemListWidget*> it(m_visibleItems);
+    while (it.hasNext()) {
+        it.next();
+        updateAlternateBackgroundForWidget(it.value());
+    }
+}
+
 void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget* widget)
 {
     bool enabled = useAlternateBackgrounds();
index 8f6e11e385649c670aafbe92ebcb2e24a12f9e82..bbdb4081ca574d8bfc42b0561f63e2c964c5060b 100644 (file)
@@ -498,6 +498,12 @@ private:
      */
     int groupIndexForItem(int index) const;
 
+    /**
+     * Updates the alternate background for all visible items.
+     * @see updateAlternateBackgroundForWidget()
+     */
+    void updateAlternateBackgrounds();
+
     /**
      * Updates the alternateBackground-property of the widget dependent
      * on the state of useAlternateBackgrounds() and the grouping state.