From 503650d6176972d66b710f1123a56b66b4091d66 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Tue, 22 Apr 2014 22:45:42 +0400 Subject: [PATCH] Full-text search: Set group for ArticleView::showDefinition() when view article --- articleview.cc | 44 ++++++++++++++++++++++++++------------------ articleview.hh | 2 +- mainwindow.cc | 3 ++- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/articleview.cc b/articleview.cc index eb5c38a4..e25867f6 100644 --- a/articleview.cc +++ b/articleview.cc @@ -279,7 +279,7 @@ void ArticleView::showDefinition( QString const & word, unsigned group, } void ArticleView::showDefinition( QString const & word, QStringList const & dictIDs, - QRegExp const & searchRegExp ) + QRegExp const & searchRegExp, unsigned group ) { if( dictIDs.isEmpty() ) return; @@ -301,6 +301,7 @@ void ArticleView::showDefinition( QString const & word, QStringList const & dict req.addQueryItem( "matchcase", "1" ); if( searchRegExp.patternSyntax() == QRegExp::WildcardUnix ) req.addQueryItem( "wildcards", "1" ); + req.addQueryItem( "group", QString::number( group ) ); // Update both histories (pages history and headwords history) saveHistoryUserData(); @@ -925,11 +926,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QStringList dictsList = ref.queryItemValue( "dictionaries" ) .split( ",", QString::SkipEmptyParts ); - QRegExp regexp( ref.queryItemValue( "regexp" ), - ref.hasQueryItem( "matchcase" ) ? Qt::CaseSensitive : Qt::CaseInsensitive, - ref.hasQueryItem( "wildcards" ) ? QRegExp::WildcardUnix : QRegExp::RegExp2 ); - - showDefinition( url.path(), dictsList, regexp ); + showDefinition( url.path(), dictsList, QRegExp(), getGroup( ref ) ); } else showDefinition( url.path(), @@ -951,11 +948,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QStringList dictsList = ref.queryItemValue( "dictionaries" ) .split( ",", QString::SkipEmptyParts ); - QRegExp regexp( ref.queryItemValue( "regexp" ), - ref.hasQueryItem( "matchcase" ) ? Qt::CaseSensitive : Qt::CaseInsensitive, - ref.hasQueryItem( "wildcards" ) ? QRegExp::WildcardUnix : QRegExp::RegExp2 ); - - showDefinition( url.path().mid( 1 ), dictsList, regexp ); + showDefinition( url.path().mid( 1 ), dictsList, QRegExp(), getGroup( ref ) ); return; } @@ -1955,7 +1948,18 @@ void ArticleView::doubleClicked() getCurrentArticle(), Contexts() ); } else - showDefinition( selectedText, getGroup( ui.definition->url() ), getCurrentArticle() ); + { + QUrl const & ref = ui.definition->url(); + + if( ref.hasQueryItem( "dictionaries" ) ) + { + QStringList dictsList = ref.queryItemValue( "dictionaries" ) + .split( ",", QString::SkipEmptyParts ); + showDefinition( selectedText, dictsList, QRegExp(), getGroup( ref ) ); + } + else + showDefinition( selectedText, getGroup( ref ), getCurrentArticle() ); + } } } } @@ -2119,6 +2123,16 @@ void ArticleView::highlightFTSResults() { closeSearch(); + const QUrl & url = ui.definition->url(); + QRegExp regexp( url.queryItemValue( "regexp" ), + url.hasQueryItem( "matchcase" ) ? Qt::CaseSensitive : Qt::CaseInsensitive, + url.hasQueryItem( "wildcards" ) ? QRegExp::WildcardUnix : QRegExp::RegExp2 ); + + if( regexp.pattern().isEmpty() ) + return; + + regexp.setMinimal( true ); + // Clear any current selection if ( ui.definition->selectedText().size() ) { @@ -2126,12 +2140,6 @@ void ArticleView::highlightFTSResults() evaluateJavaScript( "window.getSelection().removeAllRanges();_=0;" ); } - const QUrl & url = ui.definition->url(); - QRegExp regexp( url.queryItemValue( "regexp" ), - url.hasQueryItem( "matchcase" ) ? Qt::CaseSensitive : Qt::CaseInsensitive, - url.hasQueryItem( "wildcards" ) ? QRegExp::WildcardUnix : QRegExp::RegExp2 ); - regexp.setMinimal( true ); - QString pageText = ui.definition->page()->currentFrame()->toPlainText(); int pos = 0; diff --git a/articleview.hh b/articleview.hh index 673f6a4f..ac1b76a2 100644 --- a/articleview.hh +++ b/articleview.hh @@ -97,7 +97,7 @@ public: Contexts const & contexts = Contexts() ); void showDefinition( QString const & word, QStringList const & dictIDs, - QRegExp const & searchRegExp ); + QRegExp const & searchRegExp, unsigned group ); /// Clears the view and sets the application-global waiting cursor, /// which will be restored when some article loads eventually. diff --git a/mainwindow.cc b/mainwindow.cc index 43b4d164..a36ce2b1 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -2638,7 +2638,8 @@ void MainWindow::showTranslationFor( QString const & inWord, navPronounce->setEnabled( false ); - view->showDefinition( inWord, dictIDs, searchRegExp ); + view->showDefinition( inWord, dictIDs, searchRegExp, + groupInstances[ groupList->currentIndex() ].id ); updatePronounceAvailability(); updateFoundInDictsList();