summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Penz <peter.penz19@gmail.com>2012-03-20 12:22:12 (GMT)
committerPeter Penz <peter.penz19@gmail.com>2012-03-20 16:22:40 (GMT)
commitf3e6298235238634bc34a23fdadd999c04fb5e1a (patch)
treefdd2328e18abda878c839d643ad4aea298560eed
parent06858a5fde5aef25131300a7a2a88dbddec27eb2 (diff)
Fix alternate background issue
When items get inserted or deleted, the alternate background must be updated.
-rw-r--r--dolphin/src/kitemviews/kitemlistview.cpp46
-rw-r--r--dolphin/src/kitemviews/kitemlistview.h6
2 files changed, 33 insertions, 19 deletions
diff --git a/dolphin/src/kitemviews/kitemlistview.cpp b/dolphin/src/kitemviews/kitemlistview.cpp
index d7777b5..678b09b 100644
--- a/dolphin/src/kitemviews/kitemlistview.cpp
+++ b/dolphin/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<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();
diff --git a/dolphin/src/kitemviews/kitemlistview.h b/dolphin/src/kitemviews/kitemlistview.h
index 8f6e11e..bbdb408 100644
--- a/dolphin/src/kitemviews/kitemlistview.h
+++ b/dolphin/src/kitemviews/kitemlistview.h
@@ -499,6 +499,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.
*/