+ // Order the items in a way that the preview for the visible items
+ // is generated first, as this improves the feeled performance a lot.
+ //
+ // Implementation note: using KDirModel::itemForUrl() would lead to a more
+ // readable code, but it is slower as iterating all model indicess
+ // and checking whether the index is part of 'items'.
+
+ const int itemCount = items.count();
+ const QRect visibleArea = m_view->viewport()->rect();
+
+ const int rowCount = m_proxyModel->rowCount();
+ for (int row = 0; row < rowCount; ++row) {
+ const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
+ const QRect itemRect = m_view->visualRect(proxyIndex);
+ const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
+
+ KFileItem item = m_dolphinModel->itemForIndex(dirIndex); // O(1)
+ const KUrl url = item.url();
+
+ // check whether the item is part of the item list 'items'
+ int index = -1;
+ for (int i = 0; i < itemCount; ++i) {
+ if (items[i].url() == url) {
+ index = i;
+ break;
+ }
+ }
+
+ if ((index > 0) && itemRect.intersects(visibleArea)) {
+ // The current item is (at least partly) visible. Move it
+ // to the front of the list, so that the preview is
+ // generated earlier.
+ items.removeAt(index);
+ items.insert(0, item);