-void KItemListView::prepareLayoutForIncreasedItemCount(const QSizeF& size, SizeType sizeType)
-{
- // Calculate the first visible index and last visible index for the current size
- const int currentFirst = m_layouter->firstVisibleIndex();
- const int currentLast = m_layouter->lastVisibleIndex();
-
- const QSizeF currentSize = (sizeType == LayouterSize) ? m_layouter->size() : m_layouter->itemSize();
-
- // Calculate the first visible index and last visible index for the new size
- setLayouterSize(size, sizeType);
- const int newFirst = m_layouter->firstVisibleIndex();
- const int newLast = m_layouter->lastVisibleIndex();
-
- if ((currentFirst != newFirst) || (currentLast != newLast)) {
- // At least one index has been changed. Assure that widgets for all possible
- // visible items get created so that a move-animation can be started later.
- const int maxVisibleItems = m_layouter->maximumVisibleItems();
- int minFirst = qMin(newFirst, currentFirst);
- const int maxLast = qMax(newLast, currentLast);
-
- if (maxLast - minFirst + 1 < maxVisibleItems) {
- // Increasing the size might result in a smaller KItemListView::offset().
- // Decrease the first visible index in a way that at least the maximum
- // visible items are shown.
- minFirst = qMax(0, maxLast - maxVisibleItems + 1);
- }
-
- if (maxLast - minFirst > maxVisibleItems + maxVisibleItems / 2) {
- // The creating of widgets is quite expensive. Assure that never more
- // than 50 % of the maximum visible items get created for the animations.
- return;
- }
-
- setLayouterSize(currentSize, sizeType);
- for (int i = minFirst; i <= maxLast; ++i) {
- if (!m_visibleItems.contains(i)) {
- KItemListWidget* widget = createWidget(i);
- const QRectF itemRect = m_layouter->itemRect(i);
- widget->setPos(itemRect.topLeft());
- widget->resize(itemRect.size());
- }
- }
- setLayouterSize(size, sizeType);
- }
-}
-