31 , m_searchLineEdit(
new QLineEdit)
32 , m_indexWidget(HelpEngineWrapper::instance().indexWidget())
35 QVBoxLayout *layout =
new QVBoxLayout(
this);
36 QLabel *l =
new QLabel(tr(
"&Look for:"));
39 l->setBuddy(m_searchLineEdit);
40 m_searchLineEdit->setClearButtonEnabled(
true);
41 connect(m_searchLineEdit, &QLineEdit::textChanged,
42 this, &IndexWindow::filterIndices);
43 m_searchLineEdit->installEventFilter(
this);
44 layout->setContentsMargins(4, 4, 4, 4);
45 layout->addWidget(m_searchLineEdit);
47 HelpEngineWrapper &helpEngine = HelpEngineWrapper::instance();
48 m_indexWidget->installEventFilter(
this);
49 connect(helpEngine.indexModel(), &QHelpIndexModel::indexCreationStarted,
50 this, &IndexWindow::disableSearchLineEdit);
51 connect(helpEngine.indexModel(), &QHelpIndexModel::indexCreated,
52 this, &IndexWindow::enableSearchLineEdit);
53 connect(m_indexWidget, &QHelpIndexWidget::documentActivated,
54 this, [
this](
const QHelpLink &link) {
55 emit linkActivated(link.url);
57 connect(m_indexWidget, &QHelpIndexWidget::documentsActivated,
58 this, &IndexWindow::documentsActivated);
59 connect(m_searchLineEdit, &QLineEdit::returnPressed,
60 m_indexWidget, &QHelpIndexWidget::activateCurrentItem);
61 layout->addWidget(m_indexWidget);
63 m_indexWidget->viewport()->installEventFilter(
this);
80bool IndexWindow::eventFilter(QObject *obj, QEvent *e)
83 if (obj == m_searchLineEdit && e->type() == QEvent::KeyPress) {
84 QKeyEvent *ke =
static_cast<QKeyEvent*>(e);
85 QModelIndex idx = m_indexWidget->currentIndex();
88 idx = m_indexWidget->model()->index(idx.row()-1,
89 idx.column(), idx.parent());
91 m_indexWidget->setCurrentIndex(idx);
96 idx = m_indexWidget->model()->index(idx.row() + 1,
97 idx.column(), idx.parent());
99 m_indexWidget->setCurrentIndex(idx);
104 emit escapePressed();
108 }
else if (obj == m_indexWidget && e->type() == QEvent::ContextMenu) {
109 QContextMenuEvent *ctxtEvent =
static_cast<QContextMenuEvent*>(e);
110 QModelIndex idx = m_indexWidget->indexAt(ctxtEvent->pos());
113 QAction *curTab = menu.addAction(tr(
"Open Link"));
114 QAction *newTab = menu.addAction(tr(
"Open Link in New Tab"));
115 menu.move(m_indexWidget->mapToGlobal(ctxtEvent->pos()));
117 QAction *action = menu.exec();
118 if (curTab == action)
119 m_indexWidget->activateCurrentItem();
120 else if (newTab == action) {
121 open(m_indexWidget, idx);
124 }
else if (m_indexWidget && obj == m_indexWidget->viewport()
125 && e->type() == QEvent::MouseButtonRelease) {
126 QMouseEvent *mouseEvent =
static_cast<QMouseEvent*>(e);
127 QModelIndex idx = m_indexWidget->indexAt(mouseEvent->pos());
129 Qt::MouseButtons button = mouseEvent->button();
130 if (((button == Qt::LeftButton) && (mouseEvent->modifiers() & Qt::ControlModifier))
131 || (button == Qt::MiddleButton)) {
132 open(m_indexWidget, idx);
137 else if (obj == m_indexWidget && e->type() == QEvent::KeyPress) {
138 QKeyEvent *ke =
static_cast<QKeyEvent*>(e);
139 if (ke->key() == Qt::Key_Return || ke->key() == Qt::Key_Enter)
140 m_indexWidget->activateCurrentItem();
143 return QWidget::eventFilter(obj, e);