mirror of
https://github.com/zealdocs/zeal.git
synced 2024-11-26 07:37:15 +03:00
Pass return/enter and arrow keys from search box to tree view
This commit is contained in:
parent
93cf5a8c0a
commit
fde2910228
@ -29,6 +29,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
ui->lineEdit->setTreeView(ui->treeView);
|
||||||
ui->treeView->setModel(&zealList);
|
ui->treeView->setModel(&zealList);
|
||||||
ui->treeView->setColumnHidden(1, true);
|
ui->treeView->setColumnHidden(1, true);
|
||||||
connect(ui->treeView, &QTreeView::activated, [&](const QModelIndex& index) {
|
connect(ui->treeView, &QTreeView::activated, [&](const QModelIndex& index) {
|
||||||
@ -38,6 +39,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
ui->treeView->setModel(&zealSearch);
|
ui->treeView->setModel(&zealSearch);
|
||||||
ui->treeView->reset();
|
ui->treeView->reset();
|
||||||
ui->treeView->setColumnHidden(1, true);
|
ui->treeView->setColumnHidden(1, true);
|
||||||
|
ui->treeView->setCurrentIndex(zealSearch.index(0, 0, QModelIndex()));
|
||||||
});
|
});
|
||||||
connect(ui->lineEdit, &QLineEdit::textChanged, [&](const QString& text) {
|
connect(ui->lineEdit, &QLineEdit::textChanged, [&](const QString& text) {
|
||||||
if(!text.isEmpty()) {
|
if(!text.isEmpty()) {
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<widget class="QWidget" name="">
|
<widget class="QWidget" name="">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="lineEdit"/>
|
<widget class="ZealSearchEdit" name="lineEdit"/>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTreeView" name="treeView">
|
<widget class="QTreeView" name="treeView">
|
||||||
@ -78,6 +78,11 @@
|
|||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>QtWebKit/QWebView</header>
|
<header>QtWebKit/QWebView</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>ZealSearchEdit</class>
|
||||||
|
<extends>QLineEdit</extends>
|
||||||
|
<header>zealsearchedit.h</header>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
@ -16,13 +16,15 @@ SOURCES += main.cpp\
|
|||||||
zeallistmodel.cpp \
|
zeallistmodel.cpp \
|
||||||
zealsearchmodel.cpp \
|
zealsearchmodel.cpp \
|
||||||
zealdocsetsregistry.cpp \
|
zealdocsetsregistry.cpp \
|
||||||
zealsearchresult.cpp
|
zealsearchresult.cpp \
|
||||||
|
zealsearchedit.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
zeallistmodel.h \
|
zeallistmodel.h \
|
||||||
zealsearchmodel.h \
|
zealsearchmodel.h \
|
||||||
zealdocsetsregistry.h \
|
zealdocsetsregistry.h \
|
||||||
zealsearchresult.h
|
zealsearchresult.h \
|
||||||
|
zealsearchedit.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui
|
FORMS += mainwindow.ui
|
||||||
|
|
||||||
|
28
zeal/zealsearchedit.cpp
Normal file
28
zeal/zealsearchedit.cpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "zealsearchedit.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QKeyEvent>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
ZealSearchEdit::ZealSearchEdit(QWidget *parent) :
|
||||||
|
QLineEdit(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ZealSearchEdit::setTreeView(QTreeView *view)
|
||||||
|
{
|
||||||
|
treeView = view;
|
||||||
|
this->installEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZealSearchEdit::eventFilter(QObject *obj, QEvent *ev)
|
||||||
|
{
|
||||||
|
if(obj == this && ev->type() == QEvent::KeyPress) {
|
||||||
|
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(ev);
|
||||||
|
if(keyEvent->key() == Qt::Key_Down || keyEvent->key() == Qt::Key_Up ||
|
||||||
|
keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
|
||||||
|
QCoreApplication::instance()->sendEvent(treeView, keyEvent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QLineEdit::eventFilter(obj, ev);
|
||||||
|
}
|
26
zeal/zealsearchedit.h
Normal file
26
zeal/zealsearchedit.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef ZEALSEARCHEDIT_H
|
||||||
|
#define ZEALSEARCHEDIT_H
|
||||||
|
|
||||||
|
#include <QEvent>
|
||||||
|
#include <QTreeView>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
|
class ZealSearchEdit : public QLineEdit
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ZealSearchEdit(QWidget *parent = 0);
|
||||||
|
void setTreeView(QTreeView *view);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
bool eventFilter(QObject *obj, QEvent *ev);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTreeView *treeView;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ZEALSEARCHEDIT_H
|
Loading…
Reference in New Issue
Block a user