From: Peter Penz Date: Tue, 20 Mar 2012 12:22:12 +0000 (+0100) Subject: Fix alternate background issue X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/0dcb51b927f70afa6cba0b9185abb1f323052696 Fix alternate background issue When items get inserted or deleted, the alternate background must be updated. --- diff --git a/src/kitemviews/kitemlistview.cpp b/src/kitemviews/kitemlistview.cpp index d7777b541..678b09bff 100644 --- a/src/kitemviews/kitemlistview.cpp +++ b/src/kitemviews/kitemlistview.cpp @@ -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 it(m_visibleItems); - while (it.hasNext()) { - it.next(); - updateAlternateBackgroundForWidget(it.value()); - } + updateAlternateBackgrounds(); } if (itemSize.isEmpty()) { @@ -253,9 +249,9 @@ void KItemListView::setVisibleRoles(const QList& roles) const QList 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 it(m_visibleItems); while (it.hasNext()) { @@ -263,7 +259,7 @@ void KItemListView::setVisibleRoles(const QList& 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& 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 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 it(m_visibleItems); + while (it.hasNext()) { + it.next(); + updateAlternateBackgroundForWidget(it.value()); + } +} + void KItemListView::updateAlternateBackgroundForWidget(KItemListWidget* widget) { bool enabled = useAlternateBackgrounds(); diff --git a/src/kitemviews/kitemlistview.h b/src/kitemviews/kitemlistview.h index 8f6e11e38..bbdb4081c 100644 --- a/src/kitemviews/kitemlistview.h +++ b/src/kitemviews/kitemlistview.h @@ -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.