diff --git a/launcher/ui/instanceview/InstancesView.cpp b/launcher/ui/instanceview/InstancesView.cpp index 77d17f998..3016a221c 100644 --- a/launcher/ui/instanceview/InstancesView.cpp +++ b/launcher/ui/instanceview/InstancesView.cpp @@ -31,6 +31,7 @@ #include "ui/instanceview/InstanceTableProxyModel.h" #include +#include #include #include @@ -89,6 +90,7 @@ void InstancesView::prepareModel() void InstancesView::createTable() { m_table = new QTableView(this); + m_table->installEventFilter(this); m_table->setModel(m_tableProxy); m_table->setItemDelegate(new InstanceDelegate(this, m_iconSize, false)); @@ -137,6 +139,7 @@ void InstancesView::createTable() void InstancesView::createGrid() { m_grid = new QListView(this); + m_grid->installEventFilter(this); m_grid->setModel(m_gridProxy); m_grid->setModelColumn(InstanceList::NameColumn); m_grid->setItemDelegate(new InstanceDelegate(this, m_iconSize, true)); @@ -169,6 +172,20 @@ InstancePtr InstancesView::currentInstance() return nullptr; } +bool InstancesView::eventFilter(QObject* obj, QEvent* event) +{ + if (event->type() == QEvent::KeyPress) { + QKeyEvent* keyEvent = static_cast(event); + switch (keyEvent->key()) { + case Qt::Key_Return: + case Qt::Key_Enter: + activateInstance(currentView()->selectionModel()->currentIndex()); + return true; + } + } + return QObject::eventFilter(obj, event); +} + void InstancesView::activateInstance(const QModelIndex& index) { if (index.isValid()) { diff --git a/launcher/ui/instanceview/InstancesView.h b/launcher/ui/instanceview/InstancesView.h index 1401c2f54..cfa3a10ef 100644 --- a/launcher/ui/instanceview/InstancesView.h +++ b/launcher/ui/instanceview/InstancesView.h @@ -68,6 +68,9 @@ class InstancesView : public QStackedWidget { void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight); void contextMenuRequested(const QPoint pos); + protected: + bool eventFilter(QObject *obj, QEvent *event) override; + private: void createTable(); void createGrid();