diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 045292a1a5a7faee56b65eff9eedc242af4651f2..574c108032978d470d73b98b494b47248b63ba02 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -80,6 +80,12 @@ #include <QtHelp/QHelpEngine> +#if !defined(QT_NO_WEBKIT) +#include <QtWebKit/QWebElement> +#include <QtWebKit/QWebElementCollection> +#include <QtWebKit/QWebFrame> +#endif + using namespace Core::Constants; using namespace Help::Internal; @@ -691,13 +697,11 @@ void HelpPlugin::activateContext() } else if (m_core->modeManager()->currentMode() == m_mode) return; - QString id; - QMap<QString, QUrl> links; - // Find out what to show + QMap<QString, QUrl> links; if (IContext *context = m_core->currentContextObject()) { - id = context->contextHelpId(); - links = Core::HelpManager::instance()->linksForIdentifier(id); + m_idFromContext = context->contextHelpId(); + links = Core::HelpManager::instance()->linksForIdentifier(m_idFromContext); } if (HelpViewer* viewer = viewerForContextMode()) { @@ -705,16 +709,24 @@ void HelpPlugin::activateContext() // No link found or no context object viewer->setHtml(tr("<html><head><title>No Documentation</title>" "</head><body><br/><center><b>%1</b><br/>No documentation " - "available.</center></body></html>").arg(id)); + "available.</center></body></html>").arg(m_idFromContext)); viewer->setSource(QUrl()); } else { const QUrl &source = *links.begin(); - if (viewer->source() != source) + const QUrl &oldSource = viewer->source(); + if (source != oldSource) { + viewer->stop(); viewer->setSource(source); + } viewer->setFocus(); + connect(viewer, SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); + + if (source.toString().remove(source.fragment()) + == oldSource.toString().remove(oldSource.fragment())) { + highlightSearchTerms(); + } } - if (viewer != m_helpViewerForSideBar) - activateHelpMode(); } } @@ -822,6 +834,45 @@ void HelpPlugin::addBookmark() manager->showBookmarkDialog(m_centralWidget, viewer->title(), url); } +void HelpPlugin::highlightSearchTerms() +{ + if (HelpViewer* viewer = viewerForContextMode()) { + disconnect(viewer, SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); + +#if !defined(QT_NO_WEBKIT) + const QString &attrValue = m_idFromContext.mid(m_idFromContext + .lastIndexOf(QChar(':')) + 1); + if (attrValue.isEmpty()) + return; + + const QWebElement &document = viewer->page()->mainFrame()->documentElement(); + const QWebElementCollection &collection = document.findAll(QLatin1String("h3.fn a")); + + const QLatin1String property("background-color"); + foreach (const QWebElement &element, collection) { + const QString &name = element.attribute(QLatin1String("name")); + if (name.isEmpty()) + continue; + + if (m_oldAttrValue == name) { + QWebElement parent = element.parent(); + parent.setStyleProperty(property, m_styleProperty); + } + + if (attrValue == name) { + QWebElement parent = element.parent(); + m_styleProperty = parent.styleProperty(property, + QWebElement::InlineStyle); + parent.setStyleProperty(property, QLatin1String("yellow")); + } + } + m_oldAttrValue = attrValue; +#endif + viewer->findText(m_idFromContext, 0, false, true); + } +} + void HelpPlugin::handleHelpRequest(const QUrl &url) { if (HelpViewer::launchWithExternalApp(url)) diff --git a/src/plugins/help/helpplugin.h b/src/plugins/help/helpplugin.h index a5099db7f7d586e4394aa042ec80b2818e951541..d7927fc221ceedeb2dedd7861142f8ab3b19ad62 100644 --- a/src/plugins/help/helpplugin.h +++ b/src/plugins/help/helpplugin.h @@ -98,6 +98,7 @@ private slots: void updateCloseButton(); void setupHelpEngineIfNeeded(); + void highlightSearchTerms(); void handleHelpRequest(const QUrl &url); private: @@ -134,6 +135,10 @@ private: Core::MiniSplitter *m_splitter; QToolButton *m_closeButton; + + QString m_oldAttrValue; + QString m_styleProperty; + QString m_idFromContext; }; } // namespace Internal