┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/dolphincontroller.cpp
diff options
context:
space:
mode:
authorPeter Penz <[email protected]>2008-02-21 11:56:31 +0000
committerPeter Penz <[email protected]>2008-02-21 11:56:31 +0000
commite287058acb772b55b679a694062361d3fb0e8f89 (patch)
tree624ba47b804fbddecd0e3d52a992a0f58223ee58 /src/dolphincontroller.cpp
parentc73591380173b52504aaceb74314f617b2e04f6c (diff)
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: [email protected] CCMAIL: [email protected] svn path=/trunk/KDE/kdebase/apps/; revision=777719
Diffstat (limited to 'src/dolphincontroller.cpp')
-rw-r--r--src/dolphincontroller.cpp43
1 files changed, 39 insertions, 4 deletions
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 <kdirmodel.h>
+#include <QAbstractProxyModel>
+
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<QAbstractProxyModel*>(view->model());
+ KDirModel* dirModel = static_cast<KDirModel*>(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()