From a0631d294bd3b0fc990b3006e4c030379d0ac613 Mon Sep 17 00:00:00 2001 From: con <qtc-committer@nokia.com> Date: Tue, 17 Mar 2009 17:47:14 +0100 Subject: [PATCH] Add find support to the help side panel. Task: 248199 --- src/plugins/help/helpfindsupport.cpp | 64 ++++++++++++++++++++++++++++ src/plugins/help/helpfindsupport.h | 29 +++++++++++++ src/plugins/help/helpplugin.cpp | 3 ++ 3 files changed, 96 insertions(+) diff --git a/src/plugins/help/helpfindsupport.cpp b/src/plugins/help/helpfindsupport.cpp index 7254afbc29d..0f28634ad39 100644 --- a/src/plugins/help/helpfindsupport.cpp +++ b/src/plugins/help/helpfindsupport.cpp @@ -78,3 +78,67 @@ bool HelpFindSupport::findStep(const QString &txt, QTextDocument::FindFlags find QTC_ASSERT(m_centralWidget, return false); return m_centralWidget->find(txt, findFlags, false); } + +HelpViewerFindSupport::HelpViewerFindSupport(HelpViewer *viewer) + : m_viewer(viewer) +{ +} + +QString HelpViewerFindSupport::currentFindString() const +{ + QTC_ASSERT(m_viewer, return QString()); + return m_viewer->selectedText(); +} + +bool HelpViewerFindSupport::findIncremental(const QString &txt, QTextDocument::FindFlags findFlags) +{ + QTC_ASSERT(m_viewer, return false); + findFlags &= ~QTextDocument::FindBackward; + return find(txt, findFlags, true); +} + +bool HelpViewerFindSupport::findStep(const QString &txt, QTextDocument::FindFlags findFlags) +{ + QTC_ASSERT(m_viewer, return false); + return find(txt, findFlags, false); +} + +bool HelpViewerFindSupport::find(const QString &txt, QTextDocument::FindFlags findFlags, bool incremental) +{ + QTC_ASSERT(m_viewer, return false); +#if !defined(QT_NO_WEBKIT) + Q_UNUSED(incremental); + QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; + if (findFlags & QTextDocument::FindBackward) + options |= QWebPage::FindBackward; + if (findFlags & QTextDocument::FindCaseSensitively) + options |= QWebPage::FindCaseSensitively; + + return m_viewer->findText(txt, options); +#else + QTextCursor cursor = viewer->textCursor(); + QTextDocument *doc = viewer->document(); + QTextBrowser *browser = qobject_cast<QTextBrowser*>(viewer); + + if (!browser || !doc || cursor.isNull()) + return false; + if (incremental) + cursor.setPosition(cursor.selectionStart()); + + QTextCursor found = doc->find(txt, cursor, findFlags); + if (found.isNull()) { + if ((findFlags&QTextDocument::FindBackward) == 0) + cursor.movePosition(QTextCursor::Start); + else + cursor.movePosition(QTextCursor::End); + found = doc->find(txt, cursor, findFlags); + if (found.isNull()) { + return false; + } + } + if (!found.isNull()) { + viewer->setTextCursor(found); + } + return true; +#endif +} diff --git a/src/plugins/help/helpfindsupport.h b/src/plugins/help/helpfindsupport.h index bb777242220..e7aedeb8bf7 100644 --- a/src/plugins/help/helpfindsupport.h +++ b/src/plugins/help/helpfindsupport.h @@ -34,6 +34,10 @@ #include <find/ifindsupport.h> +QT_BEGIN_NAMESPACE +class HelpViewer; +QT_END_NAMESPACE + namespace Help { namespace Internal { @@ -65,6 +69,31 @@ private: CentralWidget *m_centralWidget; }; +class HelpViewerFindSupport : public Find::IFindSupport +{ + Q_OBJECT +public: + HelpViewerFindSupport(HelpViewer *viewer); + + bool isEnabled() const { return true; } + bool supportsReplace() const { return false; } + void resetIncrementalSearch() {} + void clearResults() {} + QString currentFindString() const; + QString completedFindString() const { return QString(); } + + bool findIncremental(const QString &txt, QTextDocument::FindFlags findFlags); + bool findStep(const QString &txt, QTextDocument::FindFlags findFlags); + bool replaceStep(const QString &, const QString &, + QTextDocument::FindFlags ) { return false; } + int replaceAll(const QString &, const QString &, + QTextDocument::FindFlags ) { return 0; } + +private: + bool find(const QString &ttf, QTextDocument::FindFlags findFlags, bool incremental); + HelpViewer *m_viewer; +}; + } // namespace Internal } // namespace Help diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 55f8690af2e..af4765d547c 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -373,6 +373,9 @@ void HelpPlugin::createRightPaneSideBar() rightPaneLayout->addWidget(rightPaneToolBar); m_helpViewerForSideBar = new HelpViewer(m_helpEngine, 0); + Aggregation::Aggregate *agg = new Aggregation::Aggregate(); + agg->add(m_helpViewerForSideBar); + agg->add(new HelpViewerFindSupport(m_helpViewerForSideBar)); rightPaneLayout->addWidget(m_helpViewerForSideBar); m_core->addContextObject(new Core::BaseContext(m_helpViewerForSideBar, QList<int>() << m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_HELP_SIDEBAR), -- GitLab