X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0439ed0e78dbe943b5e72fb3dbc0bdce40cdb7f7..d6488887ecf69d7f192b94de8dce34fae0b7eb76:/src/dolphincolumnwidget.cpp diff --git a/src/dolphincolumnwidget.cpp b/src/dolphincolumnwidget.cpp index eea70a8e3..677215972 100644 --- a/src/dolphincolumnwidget.cpp +++ b/src/dolphincolumnwidget.cpp @@ -26,8 +26,8 @@ #include "dolphinmodel.h" #include "dolphinsortfilterproxymodel.h" #include "dolphinsettings.h" - #include "dolphin_columnmodesettings.h" +#include "draganddrophelper.h" #include #include @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -69,7 +70,6 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, setSelectionMode(QAbstractItemView::ExtendedSelection); setDragDropMode(QAbstractItemView::DragDrop); setDropIndicatorShown(false); - setFocusPolicy(Qt::NoFocus); // TODO: Remove this check when 4.3.2 is released and KDE requires it... this // check avoids a division by zero happening on versions before 4.3.1. @@ -111,7 +111,8 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_dirLister->setAutoUpdate(true); m_dirLister->setMainWindow(this); m_dirLister->setDelayedMimeTypes(true); - m_dirLister->setShowingDotFiles(m_view->m_controller->showHiddenFiles()); + 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&))); @@ -123,6 +124,7 @@ DolphinColumnWidget::DolphinColumnWidget(QWidget* parent, m_proxyModel->setSourceModel(m_dolphinModel); setModel(m_proxyModel); + new KMimeTypeResolver(this, m_dolphinModel); m_dirLister->openUrl(url, KDirLister::NoFlags); } @@ -177,6 +179,29 @@ void DolphinColumnWidget::setShowPreview(bool show) } } +void DolphinColumnWidget::updateBackground() +{ + QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); + if (!m_active || !m_view->m_active) { + color.setAlpha(150); + } + QPalette palette = viewport()->palette(); + palette.setColor(viewport()->backgroundRole(), color); + viewport()->setPalette(palette); + + update(); +} + +void DolphinColumnWidget::setNameFilter(const QString& nameFilter) +{ + m_proxyModel->setFilterRegExp(nameFilter); +} + +void DolphinColumnWidget::startDrag(Qt::DropActions supportedActions) +{ + DragAndDropHelper::startDrag(this, supportedActions); +} + void DolphinColumnWidget::dragEnterEvent(QDragEnterEvent* event) { if (event->mimeData()->hasUrls()) { @@ -202,7 +227,14 @@ void DolphinColumnWidget::dragMoveEvent(QDragMoveEvent* event) // TODO: remove this code when the issue #160611 is solved in Qt 4.4 const QModelIndex index = indexAt(event->pos()); setDirtyRegion(m_dropRect); - m_dropRect = visualRect(index); + + m_dropRect.setSize(QSize()); // set as invalid + if (index.isValid()) { + const KFileItem item = itemForIndex(index); + if (!item.isNull() && item.isDir()) { + m_dropRect = visualRect(index); + } + } setDirtyRegion(m_dropRect); } @@ -210,11 +242,12 @@ void DolphinColumnWidget::dropEvent(QDropEvent* event) { const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); if (!urls.isEmpty()) { - event->acceptProposedAction(); + const QModelIndex index = indexAt(event->pos()); + const KFileItem item = itemForIndex(index); m_view->m_controller->indicateDroppedUrls(urls, url(), - indexAt(event->pos()), - event->source()); + item); + event->acceptProposedAction(); } QListView::dropEvent(event); m_dragging = false; @@ -246,15 +279,16 @@ void DolphinColumnWidget::paintEvent(QPaintEvent* event) // TODO: remove this code when the issue #160611 is solved in Qt 4.4 if (m_dragging) { const QBrush& brush = m_viewOptions.palette.brush(QPalette::Normal, QPalette::Highlight); - DolphinController::drawHoverIndication(viewport(), m_dropRect, brush); + DragAndDropHelper::drawHoverIndication(viewport(), m_dropRect, brush); } } void DolphinColumnWidget::mousePressEvent(QMouseEvent* event) { - m_view->m_controller->triggerActivation(); + m_view->m_controller->requestActivation(); if (!m_active) { m_view->requestActivation(this); + m_view->m_controller->triggerUrlChangeRequest(m_url); } QListView::mousePressEvent(event); @@ -278,6 +312,7 @@ void DolphinColumnWidget::contextMenuEvent(QContextMenuEvent* event) { if (!m_active) { m_view->requestActivation(this); + m_view->m_controller->triggerUrlChangeRequest(m_url); } QListView::contextMenuEvent(event); @@ -299,9 +334,10 @@ void DolphinColumnWidget::selectionChanged(const QItemSelection& selected, const selModel->select(selected, QItemSelectionModel::Select); selModel->select(deselected, QItemSelectionModel::Deselect); } + void DolphinColumnWidget::triggerItem(const QModelIndex& index) { - const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index)); + const KFileItem item = itemForIndex(index); m_view->m_controller->triggerItem(item); } @@ -310,7 +346,7 @@ 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->showPreview()) { + if (m_view->m_controller->dolphinView()->showPreview()) { KIO::PreviewJob* job = KIO::filePreview(items, 128); connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)), this, SLOT(showPreview(const KFileItem&, const QPixmap&))); @@ -351,10 +387,7 @@ void DolphinColumnWidget::slotEntered(const QModelIndex& index) void DolphinColumnWidget::activate() { - if (m_view->hasFocus()) { - setFocus(Qt::OtherFocusReason); - } - m_view->setFocusProxy(this); + setFocus(Qt::OtherFocusReason); // TODO: Connecting to the signal 'activated()' is not possible, as kstyle // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is @@ -367,11 +400,6 @@ void DolphinColumnWidget::activate() this, SLOT(triggerItem(const QModelIndex&))); } - const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); - QPalette palette = viewport()->palette(); - palette.setColor(viewport()->backgroundRole(), bgColor); - viewport()->setPalette(palette); - if (!m_childUrl.isEmpty()) { // assure that the current index is set on the index that represents // the child URL @@ -380,11 +408,13 @@ void DolphinColumnWidget::activate() selectionModel()->setCurrentIndex(proxyIndex, QItemSelectionModel::Current); } - update(); + updateBackground(); } void DolphinColumnWidget::deactivate() { + clearFocus(); + // TODO: Connecting to the signal 'activated()' is not possible, as kstyle // does not forward the single vs. doubleclick to it yet (KDE 4.1?). Hence it is // necessary connecting the signal 'singleClick()' or 'doubleClick'. @@ -396,11 +426,8 @@ void DolphinColumnWidget::deactivate() this, SLOT(triggerItem(const QModelIndex&))); } - const QPalette palette = m_view->viewport()->palette(); - viewport()->setPalette(palette); - selectionModel()->clear(); - update(); + updateBackground(); } bool DolphinColumnWidget::isCutItem(const KFileItem& item) const @@ -424,4 +451,11 @@ bool DolphinColumnWidget::isCutItem(const KFileItem& item) const return false; } +KFileItem DolphinColumnWidget::itemForIndex(const QModelIndex& index) const +{ + const QModelIndex dirIndex = m_proxyModel->mapToSource(index); + return m_dolphinModel->itemForIndex(dirIndex); +} + + #include "dolphincolumnwidget.moc"