X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/772a55aafc2e558302d042eb65026b9b50302ccc..093efca22dfd247f06e2a669ad968300e71ef08d:/src/dolphincolumnview.cpp diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index a89ab1848..3f6523ebe 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include /** @@ -56,19 +57,20 @@ public: * drawn in a lighter color. All operations are applied to this column. */ void setActive(bool active); - inline bool isActive() const; + bool isActive() const; /** * Sets the directory URL of the child column that is shown next to * this column. This property is only used for a visual indication * of the shown directory, it does not trigger a loading of the model. */ - inline void setChildUrl(const KUrl& url); - inline const KUrl& childUrl() const; + void setChildUrl(const KUrl& url); + const KUrl& childUrl() const; - /** - * Returns the directory URL that is shown inside the column widget. - */ + /** Sets the directory URL that is shown inside the column widget. */ + void setUrl(const KUrl& url); + + /** Returns the directory URL that is shown inside the column widget. */ inline const KUrl& url() const; protected: @@ -116,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); @@ -187,6 +190,11 @@ inline const KUrl& ColumnWidget::childUrl() const return m_childUrl; } +inline void ColumnWidget::setUrl(const KUrl& url) +{ + m_url = url; +} + const KUrl& ColumnWidget::url() const { return m_url; @@ -289,7 +297,7 @@ void ColumnWidget::keyPressEvent(QKeyEvent* event) && (event->key() == Qt::Key_Return) && (selModel->selectedIndexes().count() <= 1); if (triggerItem) { - m_view->triggerItem(currentIndex); + m_view->m_controller->triggerItem(currentIndex); } } @@ -331,10 +339,10 @@ void ColumnWidget::activate() // necessary connecting the signal 'singleClick()' or 'doubleClick'. if (KGlobalSettings::singleClick()) { connect(this, SIGNAL(clicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } else { connect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } const QColor bgColor = KColorScheme(QPalette::Active, KColorScheme::View).background().color(); @@ -360,10 +368,10 @@ void ColumnWidget::deactivate() // necessary connecting the signal 'singleClick()' or 'doubleClick'. if (KGlobalSettings::singleClick()) { disconnect(this, SIGNAL(clicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } else { disconnect(this, SIGNAL(doubleClicked(const QModelIndex&)), - m_view, SLOT(triggerItem(const QModelIndex&))); + m_view->m_controller, SLOT(triggerItem(const QModelIndex&))); } const QPalette palette = m_view->viewport()->palette(); @@ -379,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(), @@ -465,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 @@ -486,24 +518,43 @@ 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 baseUrl = m_columns[0]->url(); - dirLister->openUrl(baseUrl, false, true); + const KUrl& rootUrl = m_columns[0]->url(); + dirLister->openUrl(rootUrl, false, true); + updateColumns(); } void DolphinColumnView::showColumn(const KUrl& url) { - if (!m_columns[0]->url().isParentOf(url)) { - // the URL is no child URL of the column view, hence do nothing + const KUrl& rootUrl = m_columns[0]->url(); + if (!rootUrl.isParentOf(url)) { + // 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; } + KDirLister* dirLister = m_dolphinModel->dirLister(); + const KUrl dirListerUrl = dirLister->url(); + if (dirListerUrl != rootUrl) { + // It is possible that root URL of the directory lister is adjusted + // after creating the column widget (e. g. when restoring the history + // having a different root URL than the controller indicates). + m_columns[0]->setUrl(dirListerUrl); + } + int columnIndex = 0; foreach (ColumnWidget* column, m_columns) { if (column->url() == url) { @@ -514,8 +565,18 @@ void DolphinColumnView::showColumn(const KUrl& url) // the column is no parent of the requested URL, hence // just delete all remaining columns if (columnIndex > 0) { - setActiveColumnIndex(columnIndex - 1); - deleteInactiveChildColumns(); + QList::iterator start = m_columns.begin() + columnIndex; + QList::iterator end = m_columns.end(); + for (QList::iterator it = start; it != end; ++it) { + (*it)->deleteLater(); + } + m_columns.erase(start, end); + + const int maxIndex = m_columns.count() - 1; + Q_ASSERT(maxIndex >= 0); + if (m_index > maxIndex) { + m_index = maxIndex; + } break; } } @@ -534,6 +595,8 @@ void DolphinColumnView::showColumn(const KUrl& url) QString path = activeUrl.url(KUrl::AddTrailingSlash); const QString targetPath = url.url(KUrl::AddTrailingSlash); + + columnIndex = lastIndex; int slashIndex = path.count('/'); bool hasSubPath = (slashIndex >= 0); while (hasSubPath) { @@ -544,12 +607,45 @@ void DolphinColumnView::showColumn(const KUrl& url) path += subPath + '/'; ++slashIndex; + const KUrl childUrl = KUrl(path); const QModelIndex dirIndex = m_dolphinModel->indexForUrl(KUrl(path)); - if (dirIndex.isValid()) { - triggerItem(m_proxyModel->mapFromSource(dirIndex)); - } + const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); + + m_columns[columnIndex]->setChildUrl(childUrl); + 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); + + m_columns.append(column); + + // Before invoking layoutColumns() the column must be set visible temporary. + // To prevent a flickering the initial geometry is set to a hidden position. + column->setGeometry(QRect(-1, -1, 1, 1)); + column->show(); + layoutColumns(); + updateScrollBar(); + + // the layout is finished, now let the column be invisible until it + // gets a valid root index due to expandToActiveUrl() + column->hide(); } } + + // set the last column as active column without modifying the controller + // and hence the history + activeColumn()->setActive(false); + m_index = columnIndex; + activeColumn()->setActive(true); +} + +void DolphinColumnView::selectAll() +{ + activeColumn()->selectAll(); } bool DolphinColumnView::isIndexHidden(const QModelIndex& index) const @@ -661,41 +757,6 @@ void DolphinColumnView::zoomOut() } } -void DolphinColumnView::triggerItem(const QModelIndex& index) -{ - m_controller->triggerItem(index); - - const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers(); - if ((modifiers & Qt::ControlModifier) || (modifiers & Qt::ShiftModifier)) { - return; - } - - const KFileItem item = m_dolphinModel->itemForIndex(m_proxyModel->mapToSource(index)); - if ((item.url() != activeColumn()->url()) && item.isDir()) { - deleteInactiveChildColumns(); - - const KUrl& childUrl = m_controller->url(); - activeColumn()->setChildUrl(childUrl); - - ColumnWidget* column = new ColumnWidget(viewport(), this, childUrl); - column->setModel(model()); - column->setRootIndex(index); - - m_columns.append(column); - - setActiveColumnIndex(m_index + 1); - - // Before invoking layoutColumns() the column must be shown. To prevent - // a flickering the initial geometry is set to be invisible. - column->setGeometry(QRect(-1, -1, 1, 1)); - column->show(); - - layoutColumns(); - updateScrollBar(); - assureVisibleActiveColumn(); - } -} - void DolphinColumnView::moveContentHorizontally(int x) { m_contentX = -x; @@ -725,29 +786,37 @@ void DolphinColumnView::expandToActiveUrl() const int lastIndex = m_columns.count() - 1; Q_ASSERT(lastIndex >= 0); const KUrl& activeUrl = m_columns[lastIndex]->url(); - const KUrl baseUrl = m_dolphinModel->dirLister()->url(); - if (baseUrl.isParentOf(activeUrl) && (baseUrl != activeUrl)) { + const KUrl rootUrl = m_dolphinModel->dirLister()->url(); + 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); - disconnect(m_dolphinModel, SIGNAL(expand(const QModelIndex&)), - this, SLOT(triggerReloadColumns(const QModelIndex&))); - // 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]; const QModelIndex rootIndex = nextColumn->rootIndex(); - if (!rootIndex.isValid()) { + if (rootIndex.isValid()) { + nextColumn->show(); + } else { const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_columns[i]->childUrl()); const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex); if (proxyIndex.isValid()) { @@ -760,6 +829,19 @@ 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 @@ -849,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"