X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/603681ba79d6fc313c8e3152249d63cdcbdb2c89..89bb4eaf198a1427a1000f3f77dcabaee5fdae93:/src/dolphincolumnwidget.cpp diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index 6f88fd277..3bb1f36c2 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -37,6 +37,8 @@ #include #include +#include "iconmanager.h" + #include #include #include @@ -47,7 +49,6 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, const KUrl& url) : QListView(parent), m_active(true), - m_showPreview(false), m_view(columnView), m_url(url), m_childUrl(), @@ -56,7 +57,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_dirLister(0), m_dolphinModel(0), m_proxyModel(0), - m_previewJob(0), + m_iconManager(0), m_dragging(false), m_dropRect() { @@ -107,8 +108,6 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_dirLister->setDelayedMimeTypes(true); const bool showHiddenFiles = m_view->m_controller->dolphinView()->showHiddenFiles(); m_dirLister->setShowingDotFiles(showHiddenFiles); - connect(m_dirLister, SIGNAL(newItems(const KFileItemList&)), - this, SLOT(generatePreviews(const KFileItemList&))); m_dolphinModel = new DolphinModel(this); m_dolphinModel->setDirLister(m_dirLister); @@ -116,9 +115,12 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_proxyModel = new DolphinSortFilterProxyModel(this); m_proxyModel->setSourceModel(m_dolphinModel); + m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive); setModel(m_proxyModel); new KMimeTypeResolver(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); } @@ -130,11 +132,6 @@ DolphinColumnWidget::~DolphinColumnWidget() delete m_dolphinModel; m_dolphinModel = 0; m_dirLister = 0; // deleted by m_dolphinModel - - if (m_previewJob != 0) { - m_previewJob->kill(); - m_previewJob = 0; - } } void DolphinColumnWidget::setDecorationSize(const QSize& size) @@ -175,20 +172,24 @@ void DolphinColumnWidget::setShowHiddenFiles(bool show) void DolphinColumnWidget::setShowPreview(bool show) { - if (show != m_showPreview) { - m_dirLister->stop(); - m_dirLister->openUrl(m_url, KDirLister::Reload); - } + m_iconManager->setShowPreview(show); + + m_dirLister->stop(); + m_dirLister->openUrl(m_url, KDirLister::Reload); } void DolphinColumnWidget::updateBackground() { - QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); - if (!m_active || !m_view->m_active) { - color.setAlpha(150); - } + // TODO: The alpha-value 150 is copied from DolphinView::setActive(). When + // cleaning up the cut-indication of DolphinColumnWidget with the code from + // DolphinView a common helper-class should be available which can be shared + // by all view implementations -> no hardcoded value anymore + const QPalette::ColorRole role = viewport()->backgroundRole(); + QColor color = viewport()->palette().color(role); + color.setAlpha((m_active && m_view->m_active) ? 255 : 150); + QPalette palette = viewport()->palette(); - palette.setColor(viewport()->backgroundRole(), color); + palette.setColor(role, color); viewport()->setPalette(palette); update(); @@ -358,51 +359,6 @@ void DolphinColumnWidget::triggerItem(const QModelIndex& index) m_view->m_controller->triggerItem(item); } -void DolphinColumnWidget::generatePreviews(const KFileItemList& items) -{ - // TODO: same implementation as in DolphinView; create helper class - // for generatePreviews(), showPreview() and isCutItem() - - if (m_view->m_controller->dolphinView()->showPreview()) { - if (m_previewJob != 0) { - m_previewJob->kill(); - m_previewJob = 0; - } - - m_previewJob = KIO::filePreview(items, 128); - connect(m_previewJob, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), - this, SLOT(replaceIcon(const KFileItem&, const QPixmap&))); - connect(m_previewJob, SIGNAL(finished(KJob*)), - this, SLOT(slotPreviewJobFinished(KJob*))); - } -} - -void DolphinColumnWidget::replaceIcon(const KFileItem& item, const QPixmap& pixmap) -{ - // TODO: same implementation as in DolphinView; create helper class - // for generatePreviews(), showPreview() and isCutItem() - - Q_ASSERT(!item.isNull()); - const bool showPreview = m_view->m_controller->dolphinView()->showPreview(); - if (!showPreview || (item.url().directory() != m_dirLister->url().path())) { - // the preview job is still working on items of an older URL, hence - // the item is not part of the directory model anymore - return; - } - - const QModelIndex idx = m_dolphinModel->indexForItem(item); - if (idx.isValid() && (idx.column() == 0)) { - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); - if (KonqMimeData::decodeIsCutSelection(mimeData) && isCutItem(item)) { - KIconEffect iconEffect; - const QPixmap cutPixmap = iconEffect.apply(pixmap, KIconLoader::Desktop, KIconLoader::DisabledState); - m_dolphinModel->setData(idx, QIcon(cutPixmap), Qt::DecorationRole); - } else { - m_dolphinModel->setData(idx, QIcon(pixmap), Qt::DecorationRole); - } - } -} - void DolphinColumnWidget::slotEntered(const QModelIndex& index) { const QModelIndex dirIndex = m_proxyModel->mapToSource(index); @@ -410,12 +366,6 @@ void DolphinColumnWidget::slotEntered(const QModelIndex& index) m_view->m_controller->emitItemEntered(item); } -void DolphinColumnWidget::slotPreviewJobFinished(KJob* job) -{ - Q_ASSERT(job == m_previewJob); - m_previewJob = 0; -} - void DolphinColumnWidget::activate() { setFocus(Qt::OtherFocusReason); @@ -431,13 +381,8 @@ void DolphinColumnWidget::activate() this, SLOT(triggerItem(const QModelIndex&))); } - if (!m_childUrl.isEmpty()) { - // assure that the current index is set on the index that represents - // the child URL - const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_childUrl); - const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); - selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::Current); - } + if (selectionModel() && selectionModel()->currentIndex().isValid()) + selectionModel()->setCurrentIndex(selectionModel()->currentIndex(), QItemSelectionModel::SelectCurrent); updateBackground(); } @@ -457,31 +402,12 @@ void DolphinColumnWidget::deactivate() this, SLOT(triggerItem(const QModelIndex&))); } + const QModelIndex current = selectionModel()->currentIndex(); selectionModel()->clear(); + selectionModel()->setCurrentIndex(current, QItemSelectionModel::NoUpdate); updateBackground(); } -bool DolphinColumnWidget::isCutItem(const KFileItem& item) const -{ - // TODO: same implementation as in DolphinView; create helper class - // for generatePreviews(), showPreview() and isCutItem() - - const QMimeData* mimeData = QApplication::clipboard()->mimeData(); - const KUrl::List cutUrls = KUrl::List::fromMimeData(mimeData); - - const KUrl& itemUrl = item.url(); - KUrl::List::const_iterator it = cutUrls.begin(); - const KUrl::List::const_iterator end = cutUrls.end(); - while (it != end) { - if (*it == itemUrl) { - return true; - } - ++it; - } - - return false; -} - KFileItem DolphinColumnWidget::itemForIndex(const QModelIndex& index) const { const QModelIndex dirIndex = m_proxyModel->mapToSource(index);