forked from qt-creator/qt-creator
Add find support to the help side panel.
Task: 248199
This commit is contained in:
@@ -78,3 +78,67 @@ bool HelpFindSupport::findStep(const QString &txt, QTextDocument::FindFlags find
|
|||||||
QTC_ASSERT(m_centralWidget, return false);
|
QTC_ASSERT(m_centralWidget, return false);
|
||||||
return m_centralWidget->find(txt, findFlags, 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
|
||||||
|
}
|
||||||
|
|||||||
@@ -34,6 +34,10 @@
|
|||||||
|
|
||||||
#include <find/ifindsupport.h>
|
#include <find/ifindsupport.h>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class HelpViewer;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Help {
|
namespace Help {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -65,6 +69,31 @@ private:
|
|||||||
CentralWidget *m_centralWidget;
|
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 Internal
|
||||||
} // namespace Help
|
} // namespace Help
|
||||||
|
|
||||||
|
|||||||
@@ -373,6 +373,9 @@ void HelpPlugin::createRightPaneSideBar()
|
|||||||
rightPaneLayout->addWidget(rightPaneToolBar);
|
rightPaneLayout->addWidget(rightPaneToolBar);
|
||||||
|
|
||||||
m_helpViewerForSideBar = new HelpViewer(m_helpEngine, 0);
|
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);
|
rightPaneLayout->addWidget(m_helpViewerForSideBar);
|
||||||
m_core->addContextObject(new Core::BaseContext(m_helpViewerForSideBar, QList<int>()
|
m_core->addContextObject(new Core::BaseContext(m_helpViewerForSideBar, QList<int>()
|
||||||
<< m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_HELP_SIDEBAR),
|
<< m_core->uniqueIDManager()->uniqueIdentifier(Constants::C_HELP_SIDEBAR),
|
||||||
|
|||||||
Reference in New Issue
Block a user