]> Some of my projects - localmylist.git/commitdiff
MyListTab keyboard selection of rows from filter line.
authorAPTX <marek321@gmail.com>
Tue, 30 Apr 2013 23:18:47 +0000 (01:18 +0200)
committerAPTX <marek321@gmail.com>
Tue, 30 Apr 2013 23:18:47 +0000 (01:18 +0200)
Pressing return opens first unwatched file.

localmylist-management/filterlineedit.cpp [new file with mode: 0644]
localmylist-management/filterlineedit.h [new file with mode: 0644]
localmylist-management/localmylist-management.pro
localmylist-management/tabs/mylisttab.cpp
localmylist-management/tabs/mylisttab.h
localmylist-management/tabs/mylisttab.ui

diff --git a/localmylist-management/filterlineedit.cpp b/localmylist-management/filterlineedit.cpp
new file mode 100644 (file)
index 0000000..0445650
--- /dev/null
@@ -0,0 +1,22 @@
+#include "filterlineedit.h"
+
+#include <QKeyEvent>
+
+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 (file)
index 0000000..b214ca0
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef FILTERLINEEDIT_H
+#define FILTERLINEEDIT_H
+
+#include <QLineEdit>
+
+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
index 76e1e9ad2ee7bfd797cd573e645b8a60a342b91f..43cd8c72a1e2233ec0b2bf2ff80581872b92b52f 100644 (file)
@@ -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 \
index 47feace8c5d853dacc9d1bb105365fbf6a55c602..c119de3c87bf1e89d7a6f069c42a12856e5a566a 100644 (file)
@@ -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 &current, 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);
+}
index a9b1c96c8372a929d9997b6db6c1d651427841f5..9ff1538544373b11be66bf39e61ecc40d7a062e3 100644 (file)
@@ -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 &current, const QModelIndex &previous);
+       void currentSelectionChanged();
+
 private:
        LocalMyList::MyListModel *myListModel() const;
 
+       void updateSelection();
+
        MyListFilterModel *myListFilterModel;
+       int selectedRow;
 
        Ui::MyListTab *ui;
 };
index ca4b6d1f61e5994c337738a8c2d928dcdf2d2b1f..16b6144692603b4c54b798a016379ff7108617b5 100644 (file)
@@ -26,7 +26,7 @@
    <item>
     <layout class="QHBoxLayout" name="filterLayout">
      <item>
-      <widget class="QLineEdit" name="filterInput"/>
+      <widget class="FilterLineEdit" name="filterInput"/>
      </item>
      <item>
       <widget class="QComboBox" name="filterType"/>
    <extends>QTreeView</extends>
    <header>mylistview.h</header>
   </customwidget>
+  <customwidget>
+   <class>FilterLineEdit</class>
+   <extends>QLineEdit</extends>
+   <header>filterlineedit.h</header>
+  </customwidget>
  </customwidgets>
  <resources/>
  <connections/>