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.
This commit is contained in:
Igor Kushnir 2022-07-02 16:36:19 +03:00
parent 440380a763
commit 7db10b6664
2 changed files with 24 additions and 1 deletions

View file

@ -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;" )

View file

@ -93,6 +93,9 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="ftsSearchStatusLabel"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">