diff options
author | con <qtc-committer@nokia.com> | 2009-03-17 17:47:14 +0100 |
---|---|---|
committer | con <qtc-committer@nokia.com> | 2009-03-17 17:48:22 +0100 |
commit | a0631d294bd3b0fc990b3006e4c030379d0ac613 (patch) | |
tree | 0961b025d784d097df36ca5b543a26af61f0825f /src/plugins/help/helpfindsupport.cpp | |
parent | cc89dcc75b5bda35c9493c33fb1ab21c4b5ae89f (diff) | |
download | qt-creator-a0631d294bd3b0fc990b3006e4c030379d0ac613.tar.gz |
Add find support to the help side panel.
Task: 248199
Diffstat (limited to 'src/plugins/help/helpfindsupport.cpp')
-rw-r--r-- | src/plugins/help/helpfindsupport.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
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<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 +} |