X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8c6e717eadc966196f72b7552012c12f46c720ce..44d938cf4b421e6c8d39a069809ffbf807f1e02e:/src/iconmanager.cpp diff --git a/src/iconmanager.cpp b/src/iconmanager.cpp index cde15b00b..cfdf13a7c 100644 --- a/src/iconmanager.cpp +++ b/src/iconmanager.cpp @@ -49,7 +49,7 @@ IconManager::IconManager(QAbstractItemView* parent, DolphinSortFilterProxyModel* m_dolphinModel = static_cast(m_proxyModel->sourceModel()); connect(m_dolphinModel->dirLister(), SIGNAL(newItems(const KFileItemList&)), - this, SLOT(updateIcons(const KFileItemList&))); + this, SLOT(generatePreviews(const KFileItemList&))); QClipboard* clipboard = QApplication::clipboard(); connect(clipboard, SIGNAL(dataChanged()), @@ -96,11 +96,37 @@ void IconManager::updatePreviews() generatePreviews(itemList); } -void IconManager::updateIcons(const KFileItemList& items) +void IconManager::generatePreviews(const KFileItemList &items) { - if (m_showPreview) { - generatePreviews(items); + if (!m_showPreview) { + return; } + + 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); + } + } + + const QSize size = m_view->iconSize(); + KIO::PreviewJob* job = KIO::filePreview(orderedItems, 128, 128); + connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), + this, SLOT(addToPreviewQueue(const KFileItem&, const QPixmap&))); + connect(job, SIGNAL(finished(KJob*)), + this, SLOT(slotPreviewJobFinished(KJob*))); + + m_previewJobs.append(job); + m_previewTimer->start(200); } void IconManager::addToPreviewQueue(const KFileItem& item, const QPixmap& pixmap) @@ -135,63 +161,36 @@ void IconManager::updateCutItems() void IconManager::dispatchPreviewQueue() { - const int previewsCount = m_previews.count(); - if (previewsCount == 0) { - return; - } - - // Applying the previews to the model must be done step by step - // in larger blocks: Applying a preview immediately when getting the signal - // 'gotPreview()' from the PreviewJob is too expensive, as a relayout - // of the view would be triggered for each single preview. - - int dispatchCount = 30; - if (dispatchCount > previewsCount) { - dispatchCount = previewsCount; - } + int previewsCount = m_previews.count(); + if (previewsCount > 0) { + // Applying the previews to the model must be done step by step + // in larger blocks: Applying a preview immediately when getting the signal + // 'gotPreview()' from the PreviewJob is too expensive, as a relayout + // of the view would be triggered for each single preview. + + int dispatchCount = 30; + if (dispatchCount > m_previews.count()) { + dispatchCount = m_previews.count(); + } - for (int i = 0; i < dispatchCount; ++i) { - const Preview& preview = m_previews.first(); - replaceIcon(preview.item, preview.pixmap); - m_previews.pop_front(); - } + for (int i = 0; i < dispatchCount; ++i) { + const Preview& preview = m_previews.first(); + replaceIcon(preview.item, preview.pixmap); + m_previews.pop_front(); + } - if (m_previews.count() > 0) { - // there are still pending previews; if no preview job is - // working, poll more aggressively: - const int timeout = (m_previewJobs.count() > 0) ? 200 : 10; - m_previewTimer->start(timeout); + previewsCount = m_previews.count(); } -} - -void IconManager::generatePreviews(const KFileItemList &items) -{ - Q_ASSERT(m_showPreview); - 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); - } + const bool workingPreviewJobs = (m_previewJobs.count() > 0); + if (workingPreviewJobs) { + // poll for previews as long as not all preview jobs are finished + m_previewTimer->start(200); + } else if (previewsCount > 0) { + // all preview jobs are finished but there are still pending previews + // in the queue -> poll more aggressively + m_previewTimer->start(10); } - - const QSize size = m_view->iconSize(); - KIO::PreviewJob* job = KIO::filePreview(orderedItems, 128, 128); - connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(addToPreviewQueue(const KFileItem&, const QPixmap&))); - connect(job, SIGNAL(finished(KJob*)), - this, SLOT(slotPreviewJobFinished(KJob*))); - - m_previewJobs.append(job); - m_previewTimer->start(200); } void IconManager::replaceIcon(const KFileItem& item, const QPixmap& pixmap) @@ -316,14 +315,6 @@ bool IconManager::applyImageFrame(QPixmap& icon) painter.begin(&framedIcon); painter.drawPixmap(frame, frame, icon); - // draw a white frame around the icon - painter.setPen(Qt::NoPen); - painter.setBrush(palette.brush(QPalette::Normal, QPalette::Base)); - painter.drawRect(0, 0, width, frame); - painter.drawRect(0, height - frame, width, frame); - painter.drawRect(0, frame, frame, height - doubleFrame); - painter.drawRect(width - frame, frame, frame, height - doubleFrame); - // add a border painter.setPen(palette.color(QPalette::Text)); painter.setBrush(Qt::NoBrush);