X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/9169072302fb564b519508204bde68fda720bf52..093efca22dfd247f06e2a669ad968300e71ef08d:/src/dolphincolumnview.cpp diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index 586b6a1c2..3f6523ebe 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include /** @@ -117,6 +118,7 @@ ColumnWidget::ColumnWidget(QWidget* parent, viewport()->setAttribute(Qt::WA_Hover); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setSelectionBehavior(SelectItems); setSelectionMode(QAbstractItemView::ExtendedSelection); setDragDropMode(QAbstractItemView::DragDrop); @@ -385,6 +387,7 @@ DolphinColumnView::DolphinColumnView(QWidget* parent, DolphinController* control QAbstractItemView(parent), m_controller(controller), m_restoreActiveColumnFocus(false), + m_dirListerCompleted(false), m_index(-1), m_contentX(0), m_columns(), @@ -471,10 +474,33 @@ void DolphinColumnView::setModel(QAbstractItemModel* model) connect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), this, SLOT(triggerReloadColumns(const QModelIndex&))); + KDirLister* dirLister = m_dolphinModel->dirLister(); + connect(dirLister, SIGNAL(started(const KUrl&)), + this, SLOT(slotDirListerStarted(const KUrl&))); + connect(dirLister, SIGNAL(completed()), + this, SLOT(slotDirListerCompleted())); + activeColumn()->setModel(model); QAbstractItemView::setModel(model); } +void DolphinColumnView::invertSelection() +{ + // TODO: this approach of inverting the selection is quite slow. It should + // be possible to speedup the implementation by using QItemSelection, but + // all adempts have failed yet... + + ColumnWidget* column = activeColumn(); + QItemSelectionModel* selModel = column->selectionModel(); + + KDirLister* dirLister = m_dolphinModel->dirLister(); + const KFileItemList list = dirLister->itemsForDir(column->url()); + foreach (KFileItem* item, list) { + const QModelIndex index = m_dolphinModel->indexForUrl(item->url()); + selModel->select(m_proxyModel->mapFromSource(index), QItemSelectionModel::Toggle); + } +} + void DolphinColumnView::reload() { // Due to the reloading of the model all columns will be reset to show @@ -492,22 +518,31 @@ void DolphinColumnView::reload() m_restoreActiveColumnFocus = true; } column->hide(); - column->setRootIndex(QModelIndex()); - } + } // all columns are hidden, now reload the directory lister KDirLister* dirLister = m_dolphinModel->dirLister(); - connect(dirLister, SIGNAL(completed()), - this, SLOT(expandToActiveUrl())); - const KUrl rootUrl = m_columns[0]->url(); + const KUrl& rootUrl = m_columns[0]->url(); dirLister->openUrl(rootUrl, false, true); + updateColumns(); } void DolphinColumnView::showColumn(const KUrl& url) { const KUrl& rootUrl = m_columns[0]->url(); if (!rootUrl.isParentOf(url)) { - // the URL is no child URL of the column view, hence do nothing + // the URL is no child URL of the column view, hence clear all columns + // and reset the root column + QList::iterator start = m_columns.begin() + 1; + QList::iterator end = m_columns.end(); + for (QList::iterator it = start; it != end; ++it) { + (*it)->deleteLater(); + } + m_columns.erase(start, end); + m_index = 0; + m_columns[0]->setActive(true); + m_columns[0]->setUrl(url); + assureVisibleActiveColumn(); return; } @@ -580,6 +615,8 @@ void DolphinColumnView::showColumn(const KUrl& url) columnIndex++; ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl); + column->setVerticalScrollMode(ColumnWidget::ScrollPerPixel); + column->setHorizontalScrollMode(ColumnWidget::ScrollPerPixel); column->setModel(model()); column->setRootIndex(proxyIndex); column->setActive(false); @@ -604,8 +641,11 @@ void DolphinColumnView::showColumn(const KUrl& url) activeColumn()->setActive(false); m_index = columnIndex; activeColumn()->setActive(true); +} - expandToActiveUrl(); +void DolphinColumnView::selectAll() +{ + activeColumn()->selectAll(); } bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const @@ -747,21 +787,29 @@ void DolphinColumnView::expandToActiveUrl() Q_ASSERT(lastIndex >= 0); const KUrl& activeUrl = m_columns[lastIndex]->url(); const KUrl rootUrl = m_dolphinModel->dirLister()->url(); - if (rootUrl.isParentOf(activeUrl) && (rootUrl != activeUrl)) { + const bool expand = m_dirListerCompleted + && rootUrl.isParentOf(activeUrl) + && !rootUrl.equals(activeUrl, KUrl::CompareWithoutTrailingSlash); + if (expand) { m_dolphinModel->expandToUrl(activeUrl); - reloadColumns(); } + updateColumns(); } -void DolphinColumnView::triggerReloadColumns(const QModelIndex& index) +void DolphinColumnView::triggerUpdateColumns(const QModelIndex& index) { Q_UNUSED(index); - // the reloading of the columns may not be done in the context of this slot - QMetaObject::invokeMethod(this, "reloadColumns", Qt::QueuedConnection); + // the updating of the columns may not be done in the context of this slot + QMetaObject::invokeMethod(this, "updateColumns", Qt::QueuedConnection); } -void DolphinColumnView::reloadColumns() +void DolphinColumnView::updateColumns() { + KDirLister* dirLister = m_dolphinModel->dirLister(); + foreach (ColumnWidget* column, m_columns) { + dirLister->updateDirectory(column->url()); + } + const int end = m_columns.count() - 2; // next to last column for (int i = 0; i <= end; ++i) { ColumnWidget* nextColumn = m_columns[i + 1]; @@ -784,6 +832,18 @@ void DolphinColumnView::reloadColumns() assureVisibleActiveColumn(); } +void DolphinColumnView::slotDirListerStarted(const KUrl& url) +{ + Q_UNUSED(url); + m_dirListerCompleted = false; +} + +void DolphinColumnView::slotDirListerCompleted() +{ + m_dirListerCompleted = true; + QMetaObject::invokeMethod(this, "expandToActiveUrl", Qt::QueuedConnection); +} + bool DolphinColumnView::isZoomInPossible() const { ColumnModeSettings* settings = DolphinSettings::instance().columnModeSettings(); @@ -871,14 +931,4 @@ void DolphinColumnView::requestActivation(ColumnWidget* column) } } -void DolphinColumnView::deleteInactiveChildColumns() -{ - QList::iterator start = m_columns.begin() + m_index + 1; - QList::iterator end = m_columns.end(); - for (QList::iterator it = start; it != end; ++it) { - (*it)->deleteLater(); - } - m_columns.erase(start, end); -} - #include "dolphincolumnview.moc"