feat: start instance on enter/return

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-10-10 19:18:25 +02:00
parent 1dc3e95e25
commit 3beaa58718
No known key found for this signature in database
GPG Key ID: C10411294912A422
2 changed files with 20 additions and 0 deletions

View File

@ -31,6 +31,7 @@
#include "ui/instanceview/InstanceTableProxyModel.h"
#include <QHeaderView>
#include <QKeyEvent>
#include <QSize>
#include <QSortFilterProxyModel>
@ -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<QKeyEvent*>(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()) {

View File

@ -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();