Commit 722b2318 authored by con's avatar con

More fixes for setting focus correctly.

Reviewed-by: dt
parent b3284cc1
......@@ -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);
}
......
......@@ -129,7 +129,6 @@ private slots:
private:
void setup(bool showButtons);
void expandItems();
void focusInEvent(QFocusEvent *e);
bool eventFilter(QObject *object, QEvent *event);
private:
......
......@@ -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);
}
......
......@@ -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;
......
......@@ -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());
......
......@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment