X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/0ad893ae2b2bcc88c56587b57d227d65e593d2db..1ae377cd6ced8477fe235ca6a8006fef91e1fc33:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 8ed0d993e..101f98724 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -83,7 +83,6 @@ DolphinView::DolphinView(QWidget* parent, m_viewModeController(0), m_viewAccessor(proxyModel), m_selectionChangedTimer(0), - m_rootUrl(), m_activeItemUrl(), m_restoredContentsPosition(), m_createdItemUrl(), @@ -279,18 +278,9 @@ bool DolphinView::supportsCategorizedSorting() const return m_viewAccessor.supportsCategorizedSorting(); } -bool DolphinView::hasSelection() const +KFileItemList DolphinView::items() const { - const QAbstractItemView* view = m_viewAccessor.itemView(); - return (view != 0) && view->selectionModel()->hasSelection(); -} - -void DolphinView::markUrlsAsSelected(const QList& urls) -{ - foreach (const KUrl& url, urls) { - KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); - m_selectedItems.append(item); - } + return m_viewAccessor.dirLister()->items(); } KFileItemList DolphinView::selectedItems() const @@ -324,9 +314,21 @@ int DolphinView::selectedItemsCount() const return view->selectionModel()->selectedIndexes().count(); } -QItemSelectionModel* DolphinView::selectionModel() const +void DolphinView::markUrlsAsSelected(const QList& urls) { - return m_viewAccessor.itemView()->selectionModel(); + foreach (const KUrl& url, urls) { + KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url); + m_selectedItems.append(item); + } +} + +void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled) +{ + const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern); + const QItemSelectionModel::SelectionFlags command = enabled + ? QItemSelectionModel::Select + : QItemSelectionModel::Deselect; + m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command); } void DolphinView::setZoomLevel(int level) @@ -901,13 +903,18 @@ bool DolphinView::itemsExpandable() const void DolphinView::restoreState(QDataStream& stream) { - // current item + // Restore the URL of the current item that had the keyboard focus stream >> m_activeItemUrl; - // view position + // Restore the root URL + KUrl rootUrl; + stream >> rootUrl; + m_viewAccessor.setRootUrl(rootUrl); + + // Restore the view position stream >> m_restoredContentsPosition; - // expanded folders (only relevant for the details view - will be ignored by the view in other view modes) + // Restore expanded folders (only relevant for the details view - will be ignored by the view in other view modes) QSet urlsToExpand; stream >> urlsToExpand; const DolphinDetailsViewExpander* expander = m_viewAccessor.setExpandedUrls(urlsToExpand); @@ -922,7 +929,7 @@ void DolphinView::restoreState(QDataStream& stream) void DolphinView::saveState(QDataStream& stream) { - // current item + // Save the URL of the current item that has the keyboard focus KFileItem currentItem; const QAbstractItemView* view = m_viewAccessor.itemView(); @@ -932,22 +939,31 @@ void DolphinView::saveState(QDataStream& stream) currentItem = m_viewAccessor.dirModel()->itemForIndex(dirModelIndex); } - KUrl currentUrl; + KUrl currentItemUrl; if (!currentItem.isNull()) { - currentUrl = currentItem.url(); + currentItemUrl = currentItem.url(); } - stream << currentUrl; + stream << currentItemUrl; + + // Save the root URL + stream << m_viewAccessor.rootUrl(); - // view position + // Save view position const int x = view->horizontalScrollBar()->value(); const int y = view->verticalScrollBar()->value(); stream << QPoint(x, y); - // expanded folders (only relevant for the details view - the set will be empty in other view modes) + // Save expanded folders (only relevant for the details view - the set will be empty in other view modes) stream << m_viewAccessor.expandedUrls(); } +bool DolphinView::hasSelection() const +{ + const QAbstractItemView* view = m_viewAccessor.itemView(); + return (view != 0) && view->selectionModel()->hasSelection(); +} + void DolphinView::observeCreatedItem(const KUrl& url) { m_createdItemUrl = url; @@ -1097,6 +1113,7 @@ void DolphinView::applyViewProperties() if (m_viewAccessor.itemView() == 0) { createView(); } + Q_ASSERT(m_viewAccessor.itemView() != 0); Q_ASSERT(m_viewAccessor.itemDelegate() != 0); @@ -1248,7 +1265,32 @@ void DolphinView::addNewFileNames(const QMimeData* mimeData) } } +QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const +{ + QItemSelection matchingIndexes; + const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel(); + const DolphinModel* dolphinModel = m_viewAccessor.dirModel(); + + const int rowCount = proxyModel->rowCount(parent); + + for (int row = 0; row < rowCount; ++row) { + QModelIndex index = proxyModel->index(row, 0, parent); + QModelIndex sourceIndex = proxyModel->mapToSource(index); + + if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) { + matchingIndexes += QItemSelectionRange(index); + } + + if (proxyModel->hasChildren(index)) { + matchingIndexes += childrenMatchingPattern(index, pattern); + } + } + + return matchingIndexes; +} + DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) : + m_rootUrl(), m_iconsView(0), m_detailsView(0), m_columnsContainer(0), @@ -1289,6 +1331,12 @@ void DolphinView::ViewAccessor::createView(QWidget* parent, m_columnsContainer = new DolphinColumnViewContainer(parent, dolphinViewController, viewModeController); + if (!m_rootUrl.isEmpty() && m_rootUrl.isParentOf(viewModeController->url())) { + // The column-view must show several columns starting with m_rootUrl as + // first column and viewModeController->url() as last column. + m_columnsContainer->showColumn(m_rootUrl); + m_columnsContainer->showColumn(viewModeController->url()); + } break; default: @@ -1332,7 +1380,6 @@ void DolphinView::ViewAccessor::deleteView() } } - void DolphinView::ViewAccessor::prepareUrlChange(const KUrl& url) { if (m_columnsContainer != 0) { @@ -1370,9 +1417,14 @@ QWidget* DolphinView::ViewAccessor::layoutTarget() const return itemView(); } +void DolphinView::ViewAccessor::setRootUrl(const KUrl& rootUrl) +{ + m_rootUrl = rootUrl; +} + KUrl DolphinView::ViewAccessor::rootUrl() const { - return (m_columnsContainer != 0) ? m_columnsContainer->rootUrl() : KUrl(); + return (m_columnsContainer != 0) ? m_columnsContainer->rootUrl() : m_rootUrl; } bool DolphinView::ViewAccessor::supportsCategorizedSorting() const @@ -1385,7 +1437,6 @@ bool DolphinView::ViewAccessor::itemsExpandable() const return (m_detailsView != 0) && m_detailsView->itemsExpandable(); } - QSet DolphinView::ViewAccessor::expandedUrls() const { if (m_detailsView != 0) { @@ -1458,9 +1509,4 @@ void DolphinView::restoreContentsPosition() } } -KFileItemList DolphinView::allItems() const -{ - return m_viewAccessor.dirLister()->items(); -} - #include "dolphinview.moc"