From b0f99d18b86ab340b3ea1135abcf77e004844059 Mon Sep 17 00:00:00 2001 From: APTX Date: Wed, 1 May 2013 01:18:47 +0200 Subject: [PATCH] MyListTab keyboard selection of rows from filter line. Pressing return opens first unwatched file. --- localmylist-management/filterlineedit.cpp | 22 +++++++ localmylist-management/filterlineedit.h | 20 ++++++ .../localmylist-management.pro | 2 + localmylist-management/tabs/mylisttab.cpp | 61 ++++++++++++++++++- localmylist-management/tabs/mylisttab.h | 11 ++++ localmylist-management/tabs/mylisttab.ui | 7 ++- 6 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 localmylist-management/filterlineedit.cpp create mode 100644 localmylist-management/filterlineedit.h diff --git a/localmylist-management/filterlineedit.cpp b/localmylist-management/filterlineedit.cpp new file mode 100644 index 0000000..0445650 --- /dev/null +++ b/localmylist-management/filterlineedit.cpp @@ -0,0 +1,22 @@ +#include "filterlineedit.h" + +#include + +FilterLineEdit::FilterLineEdit(QWidget *parent) : + QLineEdit(parent) +{ +} + +void FilterLineEdit::keyPressEvent(QKeyEvent *e) +{ + switch (e->key()) + { + case Qt::Key_Up: + emit keyUpPressed(); + break; + case Qt::Key_Down: + emit keyDownPressed(); + break; + } + QLineEdit::keyPressEvent(e); +} diff --git a/localmylist-management/filterlineedit.h b/localmylist-management/filterlineedit.h new file mode 100644 index 0000000..b214ca0 --- /dev/null +++ b/localmylist-management/filterlineedit.h @@ -0,0 +1,20 @@ +#ifndef FILTERLINEEDIT_H +#define FILTERLINEEDIT_H + +#include + +class FilterLineEdit : public QLineEdit +{ + Q_OBJECT +public: + explicit FilterLineEdit(QWidget *parent = 0); + +signals: + void keyUpPressed(); + void keyDownPressed(); + +protected: + void keyPressEvent(QKeyEvent *e); +}; + +#endif // FILTERLINEEDIT_H diff --git a/localmylist-management/localmylist-management.pro b/localmylist-management/localmylist-management.pro index 76e1e9a..43cd8c7 100644 --- a/localmylist-management/localmylist-management.pro +++ b/localmylist-management/localmylist-management.pro @@ -17,6 +17,7 @@ SOURCES += main.cpp\ reporteditordialog.cpp \ versiondialog.cpp \ mylistitemdelegate.cpp \ + filterlineedit.cpp \ tabwidget.cpp \ abstracttab.cpp \ tabs/mylisttab.cpp \ @@ -31,6 +32,7 @@ HEADERS += mainwindow.h \ reporteditordialog.h \ versiondialog.h \ mylistitemdelegate.h \ + filterlineedit.h \ tabwidget.h \ abstracttab.h \ tabs/mylisttab.h \ diff --git a/localmylist-management/tabs/mylisttab.cpp b/localmylist-management/tabs/mylisttab.cpp index 47feace..c119de3 100644 --- a/localmylist-management/tabs/mylisttab.cpp +++ b/localmylist-management/tabs/mylisttab.cpp @@ -19,7 +19,8 @@ using namespace LocalMyList; MyListTab::MyListTab(QWidget *parent) : AbstractTabBase(parent), - ui(new Ui::MyListTab) + ui(new Ui::MyListTab), + selectedRow(-1) { ui->setupUi(this); m_label = tr("MyList"); @@ -60,10 +61,16 @@ void MyListTab::init() << tr("Regexp")); connect(ui->myListView, SIGNAL(renameTest(int)), mainWindow(), SLOT(openRenameScriptEditor(int))); + connect(ui->myListView->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentSelectionChanged(QModelIndex,QModelIndex))); + connect(ui->filterInput, SIGNAL(textChanged(QString)), this, SLOT(currentSelectionChanged())); myListFilterModel->configChanged(); + selectedRow = -1; +} +void MyListTab::activate() +{ ui->filterInput->setFocus(); } @@ -80,6 +87,7 @@ void MyListTab::saveSettings(QSettings *settings) void MyListTab::on_refreshButton_clicked() { myListModel()->reload(); + selectedRow = -1; } void MyListTab::on_myListView_openFileRequested(const QModelIndex &index) @@ -228,7 +236,58 @@ void MyListTab::on_filterType_currentIndexChanged(int) on_filterInput_textChanged(ui->filterInput->text()); } +void MyListTab::on_filterInput_keyUpPressed() +{ + selectedRow = qMax(-1, selectedRow - 1); + updateSelection(); + +} + +void MyListTab::on_filterInput_keyDownPressed() +{ + int newSelectedRow = qMin(myListModel()->rowCount() - 1, selectedRow + 1); + + if (selectedRow == newSelectedRow) + return; + + selectedRow = newSelectedRow; + updateSelection(); +} + +void MyListTab::on_filterInput_returnPressed() +{ + if (selectedRow < 0) + return; + + const QModelIndex idx = myListFilterModel->index(selectedRow, 0); + on_myListView_openFileRequested(idx); +} + +void MyListTab::currentSelectionChanged(const QModelIndex ¤t, const QModelIndex &) +{ + selectedRow = current.row(); +} + +void MyListTab::currentSelectionChanged() +{ + selectedRow = -1; +} + MyListModel *MyListTab::myListModel() const { return m_mainWindow->myListModel(); } + +void MyListTab::updateSelection() +{ + if (selectedRow < 0) + { + ui->myListView->selectionModel()->clear(); + return; + } + + const QModelIndex idx = myListFilterModel->index(selectedRow, 0); + ui->myListView->selectionModel()-> + setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect + | QItemSelectionModel::Rows); +} diff --git a/localmylist-management/tabs/mylisttab.h b/localmylist-management/tabs/mylisttab.h index a9b1c96..9ff1538 100644 --- a/localmylist-management/tabs/mylisttab.h +++ b/localmylist-management/tabs/mylisttab.h @@ -27,6 +27,7 @@ public: static QString name(); void init(); + void activate(); void loadSettings(QSettings *settings); void saveSettings(QSettings *settings); @@ -41,10 +42,20 @@ private slots: void on_filterInput_textChanged(const QString &filter); void on_filterType_currentIndexChanged(int); + void on_filterInput_keyUpPressed(); + void on_filterInput_keyDownPressed(); + void on_filterInput_returnPressed(); + + void currentSelectionChanged(const QModelIndex ¤t, const QModelIndex &previous); + void currentSelectionChanged(); + private: LocalMyList::MyListModel *myListModel() const; + void updateSelection(); + MyListFilterModel *myListFilterModel; + int selectedRow; Ui::MyListTab *ui; }; diff --git a/localmylist-management/tabs/mylisttab.ui b/localmylist-management/tabs/mylisttab.ui index ca4b6d1..16b6144 100644 --- a/localmylist-management/tabs/mylisttab.ui +++ b/localmylist-management/tabs/mylisttab.ui @@ -26,7 +26,7 @@ - + @@ -68,6 +68,11 @@ QTreeView
mylistview.h
+ + FilterLineEdit + QLineEdit +
filterlineedit.h
+
-- 2.52.0