From 7db10b6664fba8a5ba2e648d0181f67b202fcb3f Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Sat, 2 Jul 2022 16:36:19 +0300 Subject: [PATCH] Show current match and match count during FTS result navigation This information is going to be especially useful in the upcoming Qt WebEngine version of GoldenDict. In the Qt WebEngine version only the words equal to the last found result can be highlighted, not all FTS matches as in the Qt WebKit version. --- articleview.cc | 22 +++++++++++++++++++++- articleview.ui | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/articleview.cc b/articleview.cc index a43f9ac6..5d48d196 100644 --- a/articleview.cc +++ b/articleview.cc @@ -217,6 +217,19 @@ QString dictionaryIdFromScrollTo( QString const & scrollTo ) return scrollTo.mid( scrollToPrefixLength ); } +QString searchStatusMessageNoMatches() +{ + return ArticleView::tr( "Phrase not found" ); +} + +QString searchStatusMessage( int activeMatch, int matchCount ) +{ + Q_ASSERT( matchCount > 0 ); + Q_ASSERT( activeMatch > 0 ); + Q_ASSERT( activeMatch <= matchCount ); + return ArticleView::tr( "%1 of %2 matches" ).arg( activeMatch ).arg( matchCount ); +} + } // unnamed namespace QString ArticleView::scrollToFromDictionaryId( QString const & dictionaryId ) @@ -2668,7 +2681,9 @@ void ArticleView::highlightFTSResults() if( ftsSearchMatchCase ) flags |= QWebPage::FindCaseSensitively; - if( !allMatches.isEmpty() ) + if( allMatches.isEmpty() ) + ui.ftsSearchStatusLabel->setText( searchStatusMessageNoMatches() ); + else { highlightAllFtsOccurences( flags ); if( ui.definition->findText( allMatches.at( 0 ), flags ) ) @@ -2677,6 +2692,8 @@ void ArticleView::highlightFTSResults() evaluateJavaScript( QString( "%1=window.getSelection().getRangeAt(0);_=0;" ) .arg( rangeVarName ) ); } + Q_ASSERT( ftsPosition == 0 ); + ui.ftsSearchStatusLabel->setText( searchStatusMessage( 1, allMatches.size() ) ); } ui.ftsSearchFrame->show(); @@ -2714,6 +2731,7 @@ void ArticleView::performFtsFindOperation( bool backwards ) if( allMatches.isEmpty() ) { + ui.ftsSearchStatusLabel->setText( searchStatusMessageNoMatches() ); ui.ftsSearchNext->setEnabled( false ); ui.ftsSearchPrevious->setEnabled( false ); return; @@ -2762,6 +2780,8 @@ void ArticleView::performFtsFindOperation( bool backwards ) ui.ftsSearchPrevious->setEnabled( res ); } + ui.ftsSearchStatusLabel->setText( searchStatusMessage( ftsPosition + 1, allMatches.size() ) ); + // Store new highlighted selection ui.definition->page()->currentFrame()-> evaluateJavaScript( QString( "%1=window.getSelection().getRangeAt(0);_=0;" ) diff --git a/articleview.ui b/articleview.ui index bfb8b988..25f55e89 100644 --- a/articleview.ui +++ b/articleview.ui @@ -93,6 +93,9 @@ + + +