From: APTX Date: Wed, 5 Nov 2014 23:11:58 +0000 (+0100) Subject: Allow using the return key to open files in MyList TreeView. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=569932e32439d8f6baa5e2ca562283f6ecb84cbd;p=localmylist.git Allow using the return key to open files in MyList TreeView. It was already possible to open files with the return key from the filter box, but not when navigating the actual TreeView. --- diff --git a/localmylist-management/mylistview.cpp b/localmylist-management/mylistview.cpp index 09a5090..038472c 100644 --- a/localmylist-management/mylistview.cpp +++ b/localmylist-management/mylistview.cpp @@ -10,6 +10,7 @@ #include #include #include +#include MyListView::MyListView(QWidget *parent) : QTreeView(parent) @@ -50,6 +51,19 @@ MyListView::MyListView(QWidget *parent) : } } +void MyListView::keyPressEvent(QKeyEvent *event) +{ + if (event->key() == Qt::Key_Return && currentIndex().isValid()) + { + emit openFileRequested(currentIndex()); + event->accept(); + } + else + { + QTreeView::keyPressEvent(event); + } +} + MyListFilterModel *MyListView::myListFilterModel() const { return qobject_cast(model()); diff --git a/localmylist-management/mylistview.h b/localmylist-management/mylistview.h index e500c0f..b324364 100644 --- a/localmylist-management/mylistview.h +++ b/localmylist-management/mylistview.h @@ -12,6 +12,9 @@ class MyListView : public QTreeView public: explicit MyListView(QWidget *parent = 0); +protected: + void keyPressEvent(QKeyEvent *event); + signals: void openFileRequested(const QModelIndex &index); void renameFilesRequested(const QModelIndex &index);