From 46d40e704703c23fe9b30487ebfca68b89763422 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Sun, 13 Jan 2008 16:54:24 +0000 Subject: [PATCH] Improve the feeled preview performance by assuring that the preview is generated first for the visible items. svn path=/trunk/KDE/kdebase/apps/; revision=760897 --- src/dolphincolumnwidget.cpp | 2 +- src/dolphinview.cpp | 5 +++-- src/iconmanager.cpp | 30 +++++++++++++++++++++++++----- src/iconmanager.h | 18 +++++++++++------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index a51e3ef9f..6b0fe0912 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -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); diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 56a3d54de..09ddbc29e 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -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; } } diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp index 77e773167..a5e72eabf 100644 --- a/src/iconmanager.cpp +++ b/src/iconmanager.cpp @@ -20,6 +20,7 @@ #include "iconmanager.h" #include "dolphinmodel.h" +#include "dolphinsortfilterproxymodel.h" #include #include @@ -28,17 +29,21 @@ #include #include +#include #include #include -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(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); diff --git a/src/iconmanager.h b/src/iconmanager.h index 175e4a07e..2636c81c6 100644 --- a/src/iconmanager.h +++ b/src/iconmanager.h @@ -20,6 +20,7 @@ #ifndef ICONMANAGER_H #define ICONMANAGER_H +#include #include #include @@ -27,9 +28,9 @@ #include 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 m_previewJobs; - DolphinModel* m_dolphinModel; + bool m_showPreview; - QList m_cutItemsCache; + QAbstractItemView* m_view; + QList m_previewJobs; + DolphinModel* m_dolphinModel; + DolphinSortFilterProxyModel* m_proxyModel; + + QList m_cutItemsCache; }; inline bool IconManager::showPreview() const -- 2.47.3