From: Frank Reininghaus Date: Wed, 10 Aug 2011 12:30:32 +0000 (+0200) Subject: Make sure that key presses are handled in KItemListController X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/6d6fe76dcf46ae71e31d730981118cdcddb16f8b?ds=sidebyside Make sure that key presses are handled in KItemListController Key press events are forwarded from KItemListContainer to KItemListController. Right now, only the 'Home' and 'End' keys are handled (arrow keys require some more work because their action depends on the view mode). Note: 1. Before key presses are handled, the view has to be clicked with the mouse. It seems that the view does not have the keyboard focus initially. 2. The view does not scroll to the new current item yet. --- diff --git a/src/kitemviews/kitemlistcontainer.cpp b/src/kitemviews/kitemlistcontainer.cpp index e247df0c7..906f44640 100644 --- a/src/kitemviews/kitemlistcontainer.cpp +++ b/src/kitemviews/kitemlistcontainer.cpp @@ -26,6 +26,7 @@ #include "kitemlistview.h" #include "kitemmodelbase.h" +#include #include #include #include @@ -82,6 +83,20 @@ KItemListController* KItemListContainer::controller() const return m_controller; } +void KItemListContainer::keyPressEvent(QKeyEvent* event) +{ + // TODO: We should find a better way to handle the key press events in the view. + // The reasons why we need this hack are: + // 1. Without reimplementing keyPressEvent() here, the event would not reach the QGraphicsView. + // 2. By default, the KItemListView does not have the keyboard focus in the QGraphicsScene, so + // simply sending the event to the QGraphicsView which is the KItemListContainer's viewport + // does not work. + KItemListView* view = m_controller->view(); + if (view) { + QApplication::sendEvent(view, event); + } +} + void KItemListContainer::showEvent(QShowEvent* event) { QAbstractScrollArea::showEvent(event); diff --git a/src/kitemviews/kitemlistcontainer.h b/src/kitemviews/kitemlistcontainer.h index 4994eb249..e71a7b083 100644 --- a/src/kitemviews/kitemlistcontainer.h +++ b/src/kitemviews/kitemlistcontainer.h @@ -49,6 +49,7 @@ public: KItemListController* controller() const; protected: + virtual void keyPressEvent(QKeyEvent* event); virtual void showEvent(QShowEvent* event); virtual void resizeEvent(QResizeEvent* event); virtual void scrollContentsBy(int dx, int dy); diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index dcd62ad52..79e42e413 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -119,7 +119,14 @@ bool KItemListController::hideEvent(QHideEvent* event) bool KItemListController::keyPressEvent(QKeyEvent* event) { - Q_UNUSED(event); + switch (event->key()) { + case Qt::Key_Home: + m_selectionManager->setCurrentItem(0); + break; + case Qt::Key_End: + m_selectionManager->setCurrentItem(m_model->count() - 1); + break; + } return false; }