+QList<int> KItemListView::recycleInvisibleItems(int firstVisibleIndex, int lastVisibleIndex)
+{
+ // Determine all items that are completely invisible and might be
+ // reused for items that just got (at least partly) visible.
+ // Items that do e.g. an animated moving of their position are not
+ // marked as invisible: This assures that a scrolling inside the view
+ // can be done without breaking an animation.
+
+ QList<int> items;
+
+ QHashIterator<int, KItemListWidget*> it(m_visibleItems);
+ while (it.hasNext()) {
+ it.next();
+ KItemListWidget* widget = it.value();
+ const int index = widget->index();
+ const bool invisible = (index < firstVisibleIndex) || (index > lastVisibleIndex);
+ if (invisible && !m_animation->isStarted(widget)) {
+ widget->setVisible(false);
+ items.append(index);
+
+ if (m_grouped) {
+ recycleGroupHeaderForWidget(widget);
+ }
+ }
+ }
+
+ return items;
+}
+
+bool KItemListView::moveWidget(KItemListWidget* widget, const QPointF& newPos)
+{
+ // The moving-animation should only be started, if it is done within one
+ // row or one column. Otherwise instead of a moving-animation a
+ // create-animation on the new position will be used instead. This is done
+ // to prevent "irritating" moving-animations.
+ const QPointF oldPos = widget->pos();
+ const qreal xDiff = qAbs(oldPos.x() - newPos.x());
+ const qreal yDiff = qAbs(oldPos.y() - newPos.y());
+ if (xDiff <= m_itemSize.width() || yDiff <= m_itemSize.height()) {
+ // The moving animation is done inside a column or a row.
+ m_animation->start(widget, KItemListViewAnimation::MovingAnimation, newPos);
+ return true;
+ }
+
+ m_animation->stop(widget);
+ m_animation->start(widget, KItemListViewAnimation::CreateAnimation);
+ return false;
+}
+