]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Improve the feeled preview performance by assuring that the preview is generated...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 13 Jan 2008 16:54:24 +0000 (16:54 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 13 Jan 2008 16:54:24 +0000 (16:54 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=760897

src/dolphincolumnwidget.cpp
src/dolphinview.cpp
src/iconmanager.cpp
src/iconmanager.h

index a51e3ef9fc6f334f167d04011e8f276e98c3aefe..6b0fe09122d422189ce04d8c6b85b6c636ccc7aa 100644 (file)
@@ -119,7 +119,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent,
 
     setModel(m_proxyModel);
     new KMimeTypeResolver(this, m_dolphinModel);
-    m_iconManager = new IconManager(this, m_dolphinModel);
+    m_iconManager = new IconManager(this, m_proxyModel);
     m_iconManager->setShowPreview(m_view->m_controller->dolphinView()->showPreview());
 
     m_dirLister->openUrl(url, KDirLister::NoFlags);
index 56a3d54de7c9be217e94bf6eef07d3107aec1a05..09ddbc29e673bed0d418c393e0fcf9a584d01740 100644 (file)
@@ -120,8 +120,6 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_controller, SIGNAL(viewportEntered()),
             this, SLOT(clearHoverInformation()));
 
-    m_iconManager = new IconManager(this, m_dolphinModel);
-
     applyViewProperties(url);
     m_topLayout->addWidget(itemView());
 }
@@ -834,6 +832,8 @@ void DolphinView::createView()
     view->setSelectionMode(QAbstractItemView::ExtendedSelection);
 
     new KMimeTypeResolver(view, m_dolphinModel);
+    m_iconManager = new IconManager(view, m_proxyModel);
+
     m_topLayout->insertWidget(1, view);
 
     connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
@@ -856,6 +856,7 @@ void DolphinView::deleteView()
         m_detailsView = 0;
         m_columnView = 0;
         m_fileItemDelegate = 0;
+        m_iconManager = 0;
     }
 }
 
index 77e7731679d61e2360cf62bc536c5ff10b23287b..a5e72eabf2cf679d9926e6e600e2ed0fffb7d97d 100644 (file)
@@ -20,6 +20,7 @@
 #include "iconmanager.h"
 
 #include "dolphinmodel.h"
+#include "dolphinsortfilterproxymodel.h"
 
 #include <kiconeffect.h>
 #include <kio/previewjob.h>
 #include <konqmimedata.h>
 
 #include <QApplication>
+#include <QAbstractItemView>
 #include <QClipboard>
 #include <QIcon>
 
-IconManager::IconManager(QObject* parent, DolphinModel* model) :
+IconManager::IconManager(QAbstractItemView* parent, DolphinSortFilterProxyModel* model) :
     QObject(parent),
     m_showPreview(false),
+    m_view(parent),
     m_previewJobs(),
-    m_dolphinModel(model),
+    m_dolphinModel(0),
+    m_proxyModel(model),
     m_cutItemsCache()
 {
-    connect(model->dirLister(), SIGNAL(newItems(const KFileItemList&)),
+    m_dolphinModel = static_cast<DolphinModel*>(m_proxyModel->sourceModel());
+    connect(m_dolphinModel->dirLister(), SIGNAL(newItems(const KFileItemList&)),
             this, SLOT(generatePreviews(const KFileItemList&)));
 
     QClipboard* clipboard = QApplication::clipboard();
@@ -71,7 +76,23 @@ void IconManager::generatePreviews(const KFileItemList& items)
         return;
     }
 
-    KIO::PreviewJob* job = KIO::filePreview(items, 128);
+    const QRect visibleArea = m_view->viewport()->rect();
+
+    // Order the items in a way that the preview for the visible items
+    // is generated first, as this improves the feeled performance a lot.
+    KFileItemList orderedItems;
+    foreach (KFileItem item, items) {
+        const QModelIndex dirIndex = m_dolphinModel->indexForItem(item);
+        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+        const QRect itemRect = m_view->visualRect(proxyIndex);
+        if (itemRect.intersects(visibleArea)) {
+            orderedItems.insert(0, item);
+        } else {
+            orderedItems.append(item);
+        }
+    }
+
+    KIO::PreviewJob* job = KIO::filePreview(orderedItems, 128);
     connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
             this, SLOT(replaceIcon(const KFileItem&, const QPixmap&)));
     connect(job, SIGNAL(finished(KJob*)),
@@ -104,7 +125,6 @@ void IconManager::replaceIcon(const KFileItem& item, const QPixmap& pixmap)
     }
 }
 
-
 void IconManager::slotPreviewJobFinished(KJob* job)
 {
     const int index = m_previewJobs.indexOf(job);
index 175e4a07eb801b2275d0aee3716f17f40d61ed22..2636c81c63874c458257fbe7ee3834cb8e5dcef0 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef ICONMANAGER_H
 #define ICONMANAGER_H
 
+#include <kfileitem.h>
 #include <kurl.h>
 
 #include <QList>
@@ -27,9 +28,9 @@
 #include <QPixmap>
 
 class DolphinModel;
-class KFileItem;
-class KFileItemList;
+class DolphinSortFilterProxyModel;
 class KJob;
+class QAbstractItemView;
 
 /**
  * @brief Manages the icon state of a directory model.
@@ -43,7 +44,7 @@ class IconManager : public QObject
     Q_OBJECT
 
 public:
-    IconManager(QObject* parent, DolphinModel* model);
+    IconManager(QAbstractItemView* parent, DolphinSortFilterProxyModel* model);
     virtual ~IconManager();
     void setShowPreview(bool show);
     bool showPreview() const;
@@ -92,11 +93,14 @@ private:
         QPixmap pixmap;
     };
 
-   bool m_showPreview;
-   QList<KJob*> m_previewJobs;
-   DolphinModel* m_dolphinModel;
+    bool m_showPreview;
 
-   QList<CutItem> m_cutItemsCache;
+    QAbstractItemView* m_view;
+    QList<KJob*> m_previewJobs;
+    DolphinModel* m_dolphinModel;
+    DolphinSortFilterProxyModel* m_proxyModel;
+
+    QList<CutItem> m_cutItemsCache;
 };
 
 inline bool IconManager::showPreview() const