From a0631d294bd3b0fc990b3006e4c030379d0ac613 Mon Sep 17 00:00:00 2001 From: con Date: Tue, 17 Mar 2009 17:47:14 +0100 Subject: Add find support to the help side panel. Task: 248199 --- src/plugins/help/helpfindsupport.cpp | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/plugins/help/helpfindsupport.cpp') diff --git a/src/plugins/help/helpfindsupport.cpp b/src/plugins/help/helpfindsupport.cpp index 7254afbc29..0f28634ad3 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(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 +} -- cgit v1.2.1