diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dolphincolumnview.cpp | 32 | ||||
| -rw-r--r-- | src/dolphincolumnview.h | 14 | ||||
| -rw-r--r-- | src/dolphinview.cpp | 32 | ||||
| -rw-r--r-- | src/dolphinview.h | 6 |
4 files changed, 62 insertions, 22 deletions
diff --git a/src/dolphincolumnview.cpp b/src/dolphincolumnview.cpp index f4a5ef19a..ee7fb52aa 100644 --- a/src/dolphincolumnview.cpp +++ b/src/dolphincolumnview.cpp @@ -173,6 +173,7 @@ void ColumnWidget::obtainSelectionModel() if (selectionModel() != m_view->selectionModel()) { selectionModel()->deleteLater(); setSelectionModel(m_view->selectionModel()); + clearSelection(); } } @@ -428,6 +429,16 @@ DolphinColumnView::~DolphinColumnView() { } +void DolphinColumnView::invertSelection() +{ + selectActiveColumn(QItemSelectionModel::Toggle); +} + +void DolphinColumnView::selectAll() +{ + selectActiveColumn(QItemSelectionModel::Select); +} + QAbstractItemView* DolphinColumnView::createColumn(const QModelIndex& index) { // let the column widget be aware about its URL... @@ -598,7 +609,7 @@ void DolphinColumnView::requestActivation(QWidget* column) const bool isActive = (widget == column); widget->setActive(isActive); if (isActive) { - m_controller->setUrl(widget->url()); + m_controller->setUrl(widget->url()); } } } @@ -618,4 +629,23 @@ void DolphinColumnView::requestSelectionModel(QAbstractItemView* view) } } +void DolphinColumnView::selectActiveColumn(QItemSelectionModel::SelectionFlags flags) +{ + // TODO: this approach of selecting the active column is very slow. It should be + // possible to speedup the implementation by using QItemSelection, but all adempts + // have failed yet... + + QItemSelectionModel* selModel = selectionModel(); + + const QAbstractProxyModel* proxyModel = static_cast<const QAbstractProxyModel*>(model()); + const KDirModel* dirModel = static_cast<const KDirModel*>(proxyModel->sourceModel()); + KDirLister* dirLister = dirModel->dirLister(); + + const KFileItemList list = dirLister->itemsForDir(m_controller->url()); + foreach (KFileItem* item, list) { + const QModelIndex index = dirModel->indexForUrl(item->url()); + selModel->select(proxyModel->mapFromSource(index), flags); + } +} + #include "dolphincolumnview.moc" diff --git a/src/dolphincolumnview.h b/src/dolphincolumnview.h index 03f210229..b2471fdb7 100644 --- a/src/dolphincolumnview.h +++ b/src/dolphincolumnview.h @@ -41,6 +41,15 @@ public: explicit DolphinColumnView(QWidget* parent, DolphinController* controller); virtual ~DolphinColumnView(); + /** + * Inverts the selection for the current active column. + */ + void invertSelection(); + +public slots: + /** @see QAbstractItemView::selectAll() */ + virtual void selectAll(); + protected: virtual QAbstractItemView* createColumn(const QModelIndex& index); virtual void mousePressEvent(QMouseEvent* event); @@ -86,6 +95,11 @@ private: */ void requestSelectionModel(QAbstractItemView* view); + /** + * Helper method for selecting all items of an active column by \a flags. + */ + void selectActiveColumn(QItemSelectionModel::SelectionFlags flags); + private: DolphinController* m_controller; diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 7fc727475..a9f160d00 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -269,12 +269,27 @@ bool DolphinView::supportsCategorizedSorting() const void DolphinView::selectAll() { - selectAll(QItemSelectionModel::Select); + itemView()->selectAll(); } void DolphinView::invertSelection() { - selectAll(QItemSelectionModel::Toggle); + if (isColumnViewActive()) { + // In opposite to QAbstractItemView::selectAll() there is no virtual method + // for adjusting the invertion of a selection. As the generic approach by using + // the selection model does not work for the column view, we delegate this task: + m_columnView->invertSelection(); + } else { + QItemSelectionModel* selectionModel = itemView()->selectionModel(); + const QAbstractItemModel* itemModel = selectionModel->model(); + + const QModelIndex topLeft = itemModel->index(0, 0); + const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1, + itemModel->columnCount() - 1); + + QItemSelection selection(topLeft, bottomRight); + selectionModel->select(selection, QItemSelectionModel::Toggle); + } } bool DolphinView::hasSelection() const @@ -878,19 +893,6 @@ void DolphinView::createView() this, SLOT(emitContentsMoved())); } -void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags) -{ - QItemSelectionModel* selectionModel = itemView()->selectionModel(); - const QAbstractItemModel* itemModel = selectionModel->model(); - - const QModelIndex topLeft = itemModel->index(0, 0); - const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1, - itemModel->columnCount() - 1); - - QItemSelection selection(topLeft, bottomRight); - selectionModel->select(selection, flags); -} - QAbstractItemView* DolphinView::itemView() const { if (m_detailsView != 0) { diff --git a/src/dolphinview.h b/src/dolphinview.h index b26a27069..39e39ef3f 100644 --- a/src/dolphinview.h +++ b/src/dolphinview.h @@ -497,12 +497,6 @@ private: void createView(); /** - * Selects all items by using the selection flags \a flags. This is a helper - * method for the slots DolphinView::selectAll() and DolphinView::invertSelection(). - */ - void selectAll(QItemSelectionModel::SelectionFlags flags); - - /** * Returns a pointer to the currently used item view, which is either * a ListView or a TreeView. */ |
