diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-01-25 15:42:29 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-01-25 15:42:29 (GMT) |
commit | 3cddd896db542fdbae219cc937fa91192f79e944 (patch) | |
tree | 843d68f22d515637573f6c39384444878aae8508 /tools | |
parent | 41422ea0072d0af5fb378c3754b697ec0534a27f (diff) | |
parent | f9c5f15162365137f524a52d173553886f0adb8d (diff) | |
download | Qt-3cddd896db542fdbae219cc937fa91192f79e944.zip Qt-3cddd896db542fdbae219cc937fa91192f79e944.tar.gz Qt-3cddd896db542fdbae219cc937fa91192f79e944.tar.bz2 |
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/berlin-staging-1 into 4.6-integration
* '4.6' of scm.dev.nokia.troll.no:qt/berlin-staging-1:
Use HighlightAllOccurrences to have highlighting after full text search.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/assistant/tools/assistant/centralwidget.cpp | 95 | ||||
-rw-r--r-- | tools/assistant/tools/assistant/centralwidget.h | 8 |
2 files changed, 67 insertions, 36 deletions
diff --git a/tools/assistant/tools/assistant/centralwidget.cpp b/tools/assistant/tools/assistant/centralwidget.cpp index 0b177ae..c8f41e4 100644 --- a/tools/assistant/tools/assistant/centralwidget.cpp +++ b/tools/assistant/tools/assistant/centralwidget.cpp @@ -358,7 +358,7 @@ void CentralWidget::zoomOut() void CentralWidget::findNext() { - find(findWidget->editFind->text(), true, false); + find(findWidget->editFind->text(), true); } void CentralWidget::nextPage() @@ -389,7 +389,7 @@ void CentralWidget::previousPage() void CentralWidget::findPrevious() { - find(findWidget->editFind->text(), false, true); + find(findWidget->editFind->text(), false); } void CentralWidget::closeTab() @@ -697,7 +697,7 @@ HelpViewer *CentralWidget::newEmptyTab() void CentralWidget::findCurrentText(const QString &text) { - find(text, false, false); + find(text, true); } void CentralWidget::connectSignals() @@ -896,19 +896,35 @@ void CentralWidget::keyPressEvent(QKeyEvent *e) QWidget::keyPressEvent(e); } -void CentralWidget::find(const QString &ttf, bool forward, bool backward) +void CentralWidget::find(const QString &ttf, bool forward) { QPalette p = findWidget->editFind->palette(); p.setColor(QPalette::Active, QPalette::Base, Qt::white); - if (!ttf.isEmpty()) { - HelpViewer *viewer = currentHelpViewer(); + bool found = false; - bool found = false; +#if defined(QT_NO_WEBKIT) + found = findInTextBrowser(ttf, forward); +#else + found = findInWebPage(ttf, forward); +#endif + + if (!found && !ttf.isEmpty()) + p.setColor(QPalette::Active, QPalette::Base, QColor(255, 102, 102)); + + if (!findWidget->isVisible()) + findWidget->show(); + findWidget->editFind->setPalette(p); +} + +bool CentralWidget::findInWebPage(const QString &ttf, bool forward) +{ #if !defined(QT_NO_WEBKIT) - if (viewer) { - QWebPage::FindFlags options; - if (backward) + if (HelpViewer *viewer = currentHelpViewer()) { + bool found = false; + QWebPage::FindFlags options; + if (!ttf.isEmpty()) { + if (!forward) options |= QWebPage::FindBackward; if (findWidget->checkCase->isChecked()) @@ -923,30 +939,27 @@ void CentralWidget::find(const QString &ttf, bool forward, bool backward) if (found) findWidget->labelWrapped->show(); } - } else if (tabWidget->currentWidget() == m_searchWidget) { - QTextBrowser *browser = qFindChild<QTextBrowser*>(m_searchWidget); - found = findInTextBrowser(browser, ttf, forward, backward); } -#else - QTextBrowser *browser = qobject_cast<QTextBrowser*>(viewer); - if (tabWidget->currentWidget() == m_searchWidget) - browser = qFindChild<QTextBrowser*>(m_searchWidget); - found = findInTextBrowser(browser, ttf, forward, backward); -#endif - - if (!found) - p.setColor(QPalette::Active, QPalette::Base, QColor(255, 102, 102)); + // force highlighting of all other matches, also when empty (clear) + options = QWebPage::HighlightAllOccurrences; + viewer->findText(QLatin1String(""), options); + viewer->findText(ttf, options); + return found; } - if (!findWidget->isVisible()) - findWidget->show(); - findWidget->editFind->setPalette(p); + // this needs to stay, case for active search results page + return findInTextBrowser(ttf, forward); +#endif + return false; } -bool CentralWidget::findInTextBrowser(QTextBrowser* browser, const QString &ttf, - bool forward, bool backward) +bool CentralWidget::findInTextBrowser(const QString &ttf, bool forward) { - if (!browser) + QTextBrowser *browser = qobject_cast<QTextBrowser*>(currentHelpViewer()); + if (tabWidget->currentWidget() == m_searchWidget) + browser = qFindChild<QTextBrowser*>(m_searchWidget); + + if (!browser || ttf.isEmpty()) return false; QTextDocument *doc = browser->document(); @@ -962,7 +975,7 @@ bool CentralWidget::findInTextBrowser(QTextBrowser* browser, const QString &ttf, QTextCursor::MoveAnchor); } - if (backward) + if (!forward) options |= QTextDocument::FindBackward; if (findWidget->checkCase->isChecked()) @@ -1074,20 +1087,29 @@ void CentralWidget::setSourceFromSearch(const QUrl &url) { setSource(url); - highlightSearchTerms(); +#if defined(QT_NO_WEBKIT) + highlightSearchTerms() +#else + connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); +#endif } void CentralWidget::setSourceFromSearchInNewTab(const QUrl &url) { setSourceInNewTab(url); - highlightSearchTerms(); +#if defined(QT_NO_WEBKIT) + highlightSearchTerms() +#else + connect(currentHelpViewer(), SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); +#endif } void CentralWidget::highlightSearchTerms() { -#if defined(QT_NO_WEBKIT) HelpViewer *viewer = currentHelpViewer(); if (!viewer) return; @@ -1109,6 +1131,7 @@ CentralWidget::highlightSearchTerms() } } +#if defined(QT_NO_WEBKIT) viewer->viewport()->setUpdatesEnabled(false); QTextCharFormat marker; @@ -1140,6 +1163,14 @@ CentralWidget::highlightSearchTerms() viewer->setTextCursor(firstHit); viewer->viewport()->setUpdatesEnabled(true); +#else + viewer->findText("", QWebPage::HighlightAllOccurrences); + // clears existing selections + foreach (const QString& term, terms) + viewer->findText(term, QWebPage::HighlightAllOccurrences); + + disconnect(viewer, SIGNAL(loadFinished(bool)), this, + SLOT(highlightSearchTerms())); #endif } diff --git a/tools/assistant/tools/assistant/centralwidget.h b/tools/assistant/tools/assistant/centralwidget.h index 6c23190..9e32985 100644 --- a/tools/assistant/tools/assistant/centralwidget.h +++ b/tools/assistant/tools/assistant/centralwidget.h @@ -182,16 +182,16 @@ private slots: void printPreview(QPrinter *printer); void setSourceFromSearch(const QUrl &url); void setSourceFromSearchInNewTab(const QUrl &url); + void highlightSearchTerms(); private: void connectSignals(); bool eventFilter(QObject *object, QEvent *e); - void find(const QString &ttf, bool forward, bool backward); - bool findInTextBrowser(QTextBrowser* browser, const QString &ttf, - bool forward, bool backward); + void find(const QString &ttf, bool forward); + bool findInWebPage(const QString &ttf, bool forward); + bool findInTextBrowser(const QString &ttf, bool forward); void initPrinter(); QString quoteTabTitle(const QString &title) const; - void highlightSearchTerms(); void setLastShownPages(); void getBrowserFontFor(QWidget* viewer, QFont *font); |