diff --git a/src/plugins/help/helpviewer.h b/src/plugins/help/helpviewer.h index 489185d8efa8892e123589dcc5f11643e1c2ccf0..9ad9e516f0eeff654571ff86fa2d7b0653c3b3cb 100644 --- a/src/plugins/help/helpviewer.h +++ b/src/plugins/help/helpviewer.h @@ -83,7 +83,7 @@ public: bool isBackwardAvailable() const; bool findText(const QString &text, Find::IFindSupport::FindFlags flags, - bool incremental); + bool incremental, bool fromSearch); static QString AboutBlankPage; static QString PageNotFoundMessage; diff --git a/src/plugins/help/helpviewer_qtb.cpp b/src/plugins/help/helpviewer_qtb.cpp index b56a2bed5d23969cbf457d7a41402c59c3b493fe..56b6687b49eb7af8e7f45721fbbf1326d5e1f726 100644 --- a/src/plugins/help/helpviewer_qtb.cpp +++ b/src/plugins/help/helpviewer_qtb.cpp @@ -53,6 +53,13 @@ HelpViewer::HelpViewer(qreal zoom, QWidget *parent) : QTextBrowser(parent) , d(new HelpViewerPrivate(zoom)) { + QPalette p = palette(); + p.setColor(QPalette::Inactive, QPalette::Highlight, + p.color(QPalette::Active, QPalette::Highlight)); + p.setColor(QPalette::Inactive, QPalette::HighlightedText, + p.color(QPalette::Active, QPalette::HighlightedText)); + setPalette(p); + installEventFilter(this); document()->setDocumentMargin(8); @@ -173,16 +180,16 @@ bool HelpViewer::isBackwardAvailable() const } bool HelpViewer::findText(const QString &text, IFindSupport::FindFlags flags, - bool incremental) + bool incremental, bool fromSearch) { QTextDocument *doc = document(); QTextCursor cursor = textCursor(); - if (!doc || cursor.isNull()) return false; + const int position = cursor.selectionStart(); if (incremental) - cursor.setPosition(cursor.selectionStart()); + cursor.setPosition(position); QTextDocument::FindFlags f = IFindSupport::textDocumentFlagsForFindFlags(flags); QTextCursor found = doc->find(text, cursor, f); @@ -192,14 +199,33 @@ bool HelpViewer::findText(const QString &text, IFindSupport::FindFlags flags, else cursor.movePosition(QTextCursor::End); found = doc->find(text, cursor, f); - if (found.isNull()) { - return false; + } + + if (fromSearch) { + cursor.beginEditBlock(); + viewport()->setUpdatesEnabled(false); + + QTextCharFormat marker; + marker.setForeground(Qt::red); + cursor.movePosition(QTextCursor::Start); + setTextCursor(cursor); + + while (find(text)) { + QTextCursor hit = textCursor(); + hit.mergeCharFormat(marker); } + + viewport()->setUpdatesEnabled(true); + cursor.endEditBlock(); } - if (!found.isNull()) { - setTextCursor(found); + + bool cursorIsNull = found.isNull(); + if (cursorIsNull) { + found = textCursor(); + found.setPosition(position); } - return true; + setTextCursor(found); + return cursorIsNull; } // -- public slots diff --git a/src/plugins/help/helpviewer_qwv.cpp b/src/plugins/help/helpviewer_qwv.cpp index 5e463719a4122c864cc9f7c286905c29bde8c078..efe608ec4a5bc04b58773de8bab63f3917e414e8 100644 --- a/src/plugins/help/helpviewer_qwv.cpp +++ b/src/plugins/help/helpviewer_qwv.cpp @@ -140,8 +140,8 @@ QNetworkReply *HelpNetworkAccessManager::createRequest(Operation /*op*/, } const QHelpEngineCore &engine = HelpManager::helpEngineCore(); - const QByteArray &data = engine.findFile(url).isValid() - ? engine.fileData(url) : HelpViewer::PageNotFoundMessage.arg(url.toString()).toUtf8(); + const QByteArray &data = engine.findFile(url).isValid() ? engine.fileData(url) + : HelpViewer::PageNotFoundMessage.arg(url.toString()).toUtf8(); return new HelpNetworkReply(request, data, mimeType); } @@ -329,9 +329,9 @@ bool HelpViewer::isBackwardAvailable() const } bool HelpViewer::findText(const QString &text, IFindSupport::FindFlags flags, - bool incremental) + bool incremental, bool fromSearch) { - Q_UNUSED(incremental) + Q_UNUSED((incremental && fromSearch)) QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; if (flags & Find::IFindSupport::FindBackward) options |= QWebPage::FindBackward;