if (selectionModel() != m_view->selectionModel()) {
selectionModel()->deleteLater();
setSelectionModel(m_view->selectionModel());
+ clearSelection();
}
}
{
}
+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...
const bool isActive = (widget == column);
widget->setActive(isActive);
if (isActive) {
- m_controller->setUrl(widget->url());
+ m_controller->setUrl(widget->url());
}
}
}
}
}
+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"
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);
*/
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;
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
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) {
*/
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.