#include "kitemlistview.h"
#include "kitemmodelbase.h"
+#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPropertyAnimation>
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);
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);
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;
}