From e287058acb772b55b679a694062361d3fb0e8f89 Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Thu, 21 Feb 2008 11:56:31 +0000 Subject: Prevent code duplication by moving the duplications into the DolphinController. Maybe it might be a good idea to let the DolphinController be aware also about his QAbstractItemView -> it might be possible to directly connect signals of the dolphin view implementations with the controller. I'll check this... (I did not backport this cleanup as I think it has too many changes to be handled as bugfix) CCMAIL: faure@kde.org CCMAIL: edulix@gmail.com svn path=/trunk/KDE/kdebase/apps/; revision=777719 --- src/dolphincontroller.cpp | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) (limited to 'src/dolphincontroller.cpp') diff --git a/src/dolphincontroller.cpp b/src/dolphincontroller.cpp index f5fd5e836..1bd59fffa 100644 --- a/src/dolphincontroller.cpp +++ b/src/dolphincontroller.cpp @@ -19,6 +19,9 @@ #include "dolphincontroller.h" +#include +#include + DolphinController::DolphinController(DolphinView* dolphinView) : QObject(dolphinView), m_zoomInPossible(false), @@ -96,14 +99,46 @@ void DolphinController::triggerZoomOut() emit zoomOut(); } -void DolphinController::triggerItem(const KFileItem& item) +void DolphinController::handleKeyPressEvent(QKeyEvent* event, QAbstractItemView* view) +{ + const QItemSelectionModel* selModel = view->selectionModel(); + const QModelIndex currentIndex = selModel->currentIndex(); + const bool trigger = currentIndex.isValid() + && (event->key() == Qt::Key_Return) + && (selModel->selectedIndexes().count() > 0); + if (trigger) { + const QModelIndexList indexList = selModel->selectedIndexes(); + foreach (const QModelIndex& index, indexList) { + triggerItem(index, view); + } + } +} + +KFileItem DolphinController::itemForIndex(const QModelIndex& index, QAbstractItemView* view) const { - emit itemTriggered(item); + QAbstractProxyModel* proxyModel = static_cast(view->model()); + KDirModel* dirModel = static_cast(proxyModel->sourceModel()); + const QModelIndex dirIndex = proxyModel->mapToSource(index); + return dirModel->itemForIndex(dirIndex); } -void DolphinController::emitItemEntered(const KFileItem& item) +void DolphinController::triggerItem(const QModelIndex& index, QAbstractItemView* view) { - emit itemEntered(item); + const KFileItem item = itemForIndex(index, view); + if (index.isValid() && (index.column() == KDirModel::Name)) { + emit itemTriggered(item); + } else { + view->clearSelection(); + emit itemEntered(item); + } +} + +void DolphinController::emitItemEntered(const QModelIndex& index, QAbstractItemView* view) +{ + KFileItem item = itemForIndex(index, view); + if (!item.isNull()) { + emit itemEntered(item); + } } void DolphinController::emitViewportEntered() -- cgit v1.3