Merge pull request #135 from ZiDoMs/iss71

Change focus on pressing enter
This commit is contained in:
Michael Beeuwsaert 2014-06-02 20:27:44 -05:00
commit 10cb243c53
4 changed files with 21 additions and 0 deletions

View File

@ -171,7 +171,10 @@ MainWindow::MainWindow(QWidget *parent) :
// (Only the frame is larger than the list item, which is different from default behaviour.) // (Only the frame is larger than the list item, which is different from default behaviour.)
ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows); ui->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
#endif #endif
bool treeViewClicked = false;
connect(ui->treeView, &QTreeView::clicked, [&](const QModelIndex& index) { connect(ui->treeView, &QTreeView::clicked, [&](const QModelIndex& index) {
treeViewClicked = true;
ui->treeView->activated(index); ui->treeView->activated(index);
}); });
connect(ui->treeView, &QTreeView::activated, [&](const QModelIndex& index) { connect(ui->treeView, &QTreeView::activated, [&](const QModelIndex& index) {
@ -182,6 +185,11 @@ MainWindow::MainWindow(QWidget *parent) :
url.setFragment(url_l[1]); url.setFragment(url_l[1]);
} }
ui->webView->load(url); ui->webView->load(url);
if (!treeViewClicked)
ui->webView->focus();
else
treeViewClicked = false;
} }
}); });
connect(ui->forwardButton, &QPushButton::clicked, this, &MainWindow::forward); connect(ui->forwardButton, &QPushButton::clicked, this, &MainWindow::forward);
@ -204,6 +212,8 @@ MainWindow::MainWindow(QWidget *parent) :
}); });
connect(&zealSearch, &ZealSearchModel::queryCompleted, [&]() { connect(&zealSearch, &ZealSearchModel::queryCompleted, [&]() {
treeViewClicked = true;
ui->treeView->setModel(&zealSearch); ui->treeView->setModel(&zealSearch);
ui->treeView->reset(); ui->treeView->reset();
ui->treeView->setColumnHidden(1, true); ui->treeView->setColumnHidden(1, true);

View File

@ -80,6 +80,11 @@ void SearchableWebView::load(const QUrl &url) {
webView.load(url); webView.load(url);
} }
void SearchableWebView::focus()
{
webView.setFocus();
}
QWebPage * SearchableWebView::page() const { QWebPage * SearchableWebView::page() const {
return webView.page(); return webView.page();
} }

View File

@ -11,6 +11,7 @@ class SearchableWebView : public QWidget
public: public:
explicit SearchableWebView(QWidget *parent = 0); explicit SearchableWebView(QWidget *parent = 0);
void load(const QUrl& url); void load(const QUrl& url);
void focus();
QSize sizeHint() const; QSize sizeHint() const;
QWebSettings * settings() const; QWebSettings * settings() const;
QWebPage * page() const; QWebPage * page() const;

View File

@ -37,6 +37,11 @@ bool ZealSearchEdit::eventFilter(QObject *obj, QEvent *ev)
return true; return true;
} }
if(keyEvent->key() == Qt::Key_Return) {
emit treeView->activated(treeView->selectionModel()->currentIndex());
return true;
}
if(keyEvent->key() == Qt::Key_Escape) { if(keyEvent->key() == Qt::Key_Escape) {
clearQuery(); clearQuery();
} }