diff --git a/src/shared/help/bookmarkmanager.cpp b/src/shared/help/bookmarkmanager.cpp index 96c8643765732bbb9de25b1bbbe1a0738315ce7b..cf696b9f94c486ecce012fb20f7bb5fcf0820fae 100644 --- a/src/shared/help/bookmarkmanager.cpp +++ b/src/shared/help/bookmarkmanager.cpp @@ -429,6 +429,8 @@ void BookmarkWidget::setup(bool showButtons) vlayout->addWidget(label); searchField = new QLineEdit(this); + setFocusProxy(searchField); + searchField->installEventFilter(this); vlayout->addWidget(searchField); connect(searchField, SIGNAL(textChanged(const QString &)), this, SLOT(filterChanged())); @@ -509,19 +511,6 @@ void BookmarkWidget::expandItems() } } -void BookmarkWidget::focusInEvent(QFocusEvent *e) -{ - if (e->reason() != Qt::MouseFocusReason) { - searchField->selectAll(); - searchField->setFocus(); - - QModelIndex index = treeView->indexAt(QPoint(1, 1)); - if (index.isValid()) - treeView->setCurrentIndex(index); - - } -} - bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) { if ((object == this) || (object == treeView->viewport())) { @@ -576,6 +565,15 @@ bool BookmarkWidget::eventFilter(QObject *object, QEvent *e) } } } + } else if (object == searchField && e->type() == QEvent::FocusIn) { + if (static_cast<QFocusEvent *>(e)->reason() != Qt::MouseFocusReason) { + searchField->selectAll(); + searchField->setFocus(); + + QModelIndex index = treeView->indexAt(QPoint(1, 1)); + if (index.isValid()) + treeView->setCurrentIndex(index); + } } return QWidget::eventFilter(object, e); } diff --git a/src/shared/help/bookmarkmanager.h b/src/shared/help/bookmarkmanager.h index 00f93f670c88fee6ca3b441bc9633c3db0acc218..008c9d1b7dc9acea50475427e15ae8011e04c7ae 100644 --- a/src/shared/help/bookmarkmanager.h +++ b/src/shared/help/bookmarkmanager.h @@ -129,7 +129,6 @@ private slots: private: void setup(bool showButtons); void expandItems(); - void focusInEvent(QFocusEvent *e); bool eventFilter(QObject *object, QEvent *event); private: diff --git a/src/shared/help/contentwindow.cpp b/src/shared/help/contentwindow.cpp index ca722034333915a02b925ac4c52e2d2ed33f288f..e7dcab7da414b146a3644c1cab8cfa976101a516 100644 --- a/src/shared/help/contentwindow.cpp +++ b/src/shared/help/contentwindow.cpp @@ -43,8 +43,10 @@ ContentWindow::ContentWindow(QHelpEngine *helpEngine) , m_expandDepth(-2) { m_contentWidget = m_helpEngine->contentWidget(); + m_contentWidget->installEventFilter(this); m_contentWidget->viewport()->installEventFilter(this); m_contentWidget->setContextMenuPolicy(Qt::CustomContextMenu); + setFocusProxy(m_contentWidget); QVBoxLayout *layout = new QVBoxLayout(this); layout->setMargin(4); @@ -90,18 +92,6 @@ void ContentWindow::expandToDepth(int depth) m_contentWidget->expandToDepth(depth); } -void ContentWindow::focusInEvent(QFocusEvent *e) -{ - if (e->reason() != Qt::MouseFocusReason) - m_contentWidget->setFocus(); -} - -void ContentWindow::keyPressEvent(QKeyEvent *e) -{ - if (e->key() == Qt::Key_Escape) - emit escapePressed(); -} - bool ContentWindow::eventFilter(QObject *o, QEvent *e) { if (m_contentWidget && o == m_contentWidget->viewport() @@ -125,6 +115,9 @@ bool ContentWindow::eventFilter(QObject *o, QEvent *e) itemClicked(index); } } + } else if (o == m_contentWidget && e->type() == QEvent::KeyPress) { + if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Escape) + emit escapePressed(); } return QWidget::eventFilter(o, e); } diff --git a/src/shared/help/contentwindow.h b/src/shared/help/contentwindow.h index 81eee24e57f5090f01ae1923f974be11e7b4a7bf..ec98ea53212bf045fc59bebce7d4996a819f165e 100644 --- a/src/shared/help/contentwindow.h +++ b/src/shared/help/contentwindow.h @@ -63,8 +63,6 @@ private slots: void itemClicked(const QModelIndex &index); private: - void focusInEvent(QFocusEvent *e); - void keyPressEvent(QKeyEvent *e); bool eventFilter(QObject *o, QEvent *e); bool isPdfFile(QHelpContentItem *item) const; diff --git a/src/shared/help/indexwindow.cpp b/src/shared/help/indexwindow.cpp index 8ae9f4e0a9346caf100e3af2059cbc6186c81cf1..208f2357a916ef96724d0b92624d361499f77613 100644 --- a/src/shared/help/indexwindow.cpp +++ b/src/shared/help/indexwindow.cpp @@ -54,6 +54,7 @@ IndexWindow::IndexWindow(QHelpEngine *helpEngine, QWidget *parent) m_searchLineEdit = new QLineEdit(); l->setBuddy(m_searchLineEdit); + setFocusProxy(m_searchLineEdit); connect(m_searchLineEdit, SIGNAL(textChanged(QString)), this, SLOT(filterIndices(QString))); m_searchLineEdit->installEventFilter(this); @@ -112,6 +113,11 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) break; default: ; // stop complaining } + } else if (obj == m_searchLineEdit + && e->type() == QEvent::FocusIn + && static_cast<QFocusEvent *>(e)->reason() != Qt::MouseFocusReason) { + m_searchLineEdit->selectAll(); + m_searchLineEdit->setFocus(); } else if (obj == m_indexWidget && e->type() == QEvent::ContextMenu) { QContextMenuEvent *ctxtEvent = static_cast<QContextMenuEvent*>(e); QModelIndex idx = m_indexWidget->indexAt(ctxtEvent->pos()); @@ -147,6 +153,7 @@ bool IndexWindow::eventFilter(QObject *obj, QEvent *e) m_indexWidget->activateCurrentItem(); } #endif + return QWidget::eventFilter(obj, e); } @@ -166,14 +173,6 @@ void IndexWindow::setSearchLineEditText(const QString &text) m_searchLineEdit->setText(text); } -void IndexWindow::focusInEvent(QFocusEvent *e) -{ - if (e->reason() != Qt::MouseFocusReason) { - m_searchLineEdit->selectAll(); - m_searchLineEdit->setFocus(); - } -} - void IndexWindow::open(QHelpIndexWidget* indexWidget, const QModelIndex &index) { QHelpIndexModel *model = qobject_cast<QHelpIndexModel*>(indexWidget->model()); diff --git a/src/shared/help/indexwindow.h b/src/shared/help/indexwindow.h index 21d32fbf0eb103d94fa20f2e532f7158119ca4d3..a283d64c21b3808046290662e5f1c171028fe6e7 100644 --- a/src/shared/help/indexwindow.h +++ b/src/shared/help/indexwindow.h @@ -69,7 +69,6 @@ private slots: private: bool eventFilter(QObject *obj, QEvent *e); - void focusInEvent(QFocusEvent *e); void open(QHelpIndexWidget* indexWidget, const QModelIndex &index); QLineEdit *m_searchLineEdit;