diff --git a/active/components/documentitem.cpp b/active/components/documentitem.cpp index 303ef28e8..e1915abee 100644 --- a/active/components/documentitem.cpp +++ b/active/components/documentitem.cpp @@ -168,7 +168,7 @@ void DocumentItem::searchText(const QString &text) m_document->cancelSearch(); m_document->resetSearch(PAGEVIEW_SEARCH_ID); m_document->searchText(PAGEVIEW_SEARCH_ID, text, 1, Qt::CaseInsensitive, - Okular::Document::AllDocument, true, QColor(100,100,200,40), true); + Okular::Document::AllDocument, true, QColor(100,100,200,40)); if (!m_searchInProgress) { m_searchInProgress = true; diff --git a/core/document.cpp b/core/document.cpp index c15cf72d0..fc29e57e4 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -124,9 +124,9 @@ struct RunningSearch Document::SearchType cachedType; Qt::CaseSensitivity cachedCaseSensitivity; bool cachedViewportMove : 1; - bool cachedNoDialogs : 1; bool isCurrentlySearching : 1; QColor cachedColor; + int pagesDone; }; #define foreachObserver( cmd ) {\ @@ -1656,16 +1656,16 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa if ( !searchStruct->match ) { const int pageCount = m_pagesVector.count(); - if (searchStruct->pagesDone < pageCount) + if (search->pagesDone < pageCount) { doContinue = true; if ( searchStruct->currentPage >= pageCount || searchStruct->currentPage < 0 ) { - const QString question = forward ? i18n("End of document reached.\nContinue from the beginning?") : i18n("Beginning of document reached.\nContinue from the bottom?"); - if ( search->cachedNoDialogs || KMessageBox::questionYesNo(m_widget, question, QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::Yes ) - searchStruct->currentPage = forward ? 0 : pageCount - 1; - else - doContinue = false; + doContinue = false; + search->isCurrentlySearching = false; + search->continueOnPage = forward ? 0 : pageCount - 1; + search->continueOnMatch = RegularAreaRect(); + emit m_parent->searchFinished ( searchStruct->searchID, Document::EndOfDocumentReached ); } } } @@ -1684,11 +1684,11 @@ void DocumentPrivate::doContinueDirectionMatchSearch(void *doContinueDirectionMa { if (forward) searchStruct->currentPage++; else searchStruct->currentPage--; - searchStruct->pagesDone++; + search->pagesDone++; } else { - searchStruct->pagesDone = 1; + search->pagesDone = 1; } // Both of the previous if branches need to call doContinueDirectionMatchSearch @@ -3276,7 +3276,7 @@ void Document::setNextDocumentDestination( const QString &namedDestination ) } void Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, - SearchType type, bool moveViewport, const QColor & color, bool noDialogs ) + SearchType type, bool moveViewport, const QColor & color ) { d->m_searchCancelled = false; @@ -3303,7 +3303,6 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q s->cachedType = type; s->cachedCaseSensitivity = caseSensitivity; s->cachedViewportMove = moveViewport; - s->cachedNoDialogs = noDialogs; s->cachedColor = color; s->isCurrentlySearching = true; @@ -3355,12 +3354,13 @@ void Document::searchText( int searchID, const QString & text, bool fromStart, Q } } + s->pagesDone = pagesDone; + DoContinueDirectionMatchSearchStruct *searchStruct = new DoContinueDirectionMatchSearchStruct(); searchStruct->pagesToNotify = pagesToNotify; searchStruct->match = match; searchStruct->currentPage = currentPage; searchStruct->searchID = searchID; - searchStruct->pagesDone = pagesDone; QMetaObject::invokeMethod(this, "doContinueDirectionMatchSearch", Qt::QueuedConnection, Q_ARG(void *, searchStruct)); } @@ -3389,8 +3389,7 @@ void Document::continueSearch( int searchID ) RunningSearch * p = *it; if ( !p->isCurrentlySearching ) searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, - p->cachedType, p->cachedViewportMove, p->cachedColor, - p->cachedNoDialogs ); + p->cachedType, p->cachedViewportMove, p->cachedColor ); } void Document::continueSearch( int searchID, SearchType type ) @@ -3407,8 +3406,7 @@ void Document::continueSearch( int searchID, SearchType type ) RunningSearch * p = *it; if ( !p->isCurrentlySearching ) searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, - type, p->cachedViewportMove, p->cachedColor, - p->cachedNoDialogs ); + type, p->cachedViewportMove, p->cachedColor ); } void Document::resetSearch( int searchID ) diff --git a/core/document.h b/core/document.h index a66da808a..b5c64f0ce 100644 --- a/core/document.h +++ b/core/document.h @@ -487,9 +487,10 @@ class OKULAR_EXPORT Document : public QObject */ enum SearchStatus { - MatchFound, ///< Any match was found - NoMatchFound, ///< No match was found - SearchCancelled ///< The search was cancelled + MatchFound, ///< Any match was found + NoMatchFound, ///< No match was found + SearchCancelled, ///< The search was cancelled + EndOfDocumentReached ///< The end of document was reached without any match @since 0.20 (KDE 4.14) }; /** @@ -501,10 +502,9 @@ class OKULAR_EXPORT Document : public QObject * @param type The type of the search. @ref SearchType * @param moveViewport Whether the viewport shall be moved to the position of the matches. * @param color The highlighting color of the matches. - * @param noDialogs Whether a search dialog shall be shown. */ void searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, - SearchType type, bool moveViewport, const QColor & color, bool noDialogs = false ); + SearchType type, bool moveViewport, const QColor & color ); /** * Continues the search for the given @p searchID. diff --git a/core/document_p.h b/core/document_p.h index e19bac581..c5b183c72 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -71,7 +71,6 @@ struct DoContinueDirectionMatchSearchStruct RegularAreaRect *match; int currentPage; int searchID; - int pagesDone; }; class DocumentPrivate diff --git a/tests/searchtest.cpp b/tests/searchtest.cpp index e24ab24e7..08648d92c 100644 --- a/tests/searchtest.cpp +++ b/tests/searchtest.cpp @@ -177,7 +177,7 @@ void SearchTest::test311232() d.openDocument(testFile, KUrl(), mime); const int searchId = 0; - d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor(), true); + d.searchText(searchId, " i ", true, Qt::CaseSensitive, Okular::Document::NextMatch, false, QColor()); QTime t; t.start(); while (spy.count() != 1 && t.elapsed() < 500) diff --git a/ui/searchlineedit.cpp b/ui/searchlineedit.cpp index f4969dada..2add7fa19 100644 --- a/ui/searchlineedit.cpp +++ b/ui/searchlineedit.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include SearchLineEdit::SearchLineEdit( QWidget * parent, Okular::Document * document ) : KLineEdit( parent ), m_document( document ), m_minLength( 0 ), @@ -250,6 +252,15 @@ void SearchLineEdit::searchFinished( int id, Okular::Document::SearchStatus endS setPalette( pal ); } + if ( endStatus == Okular::Document::EndOfDocumentReached ) { + const bool forward = m_searchType == Okular::Document::NextMatch; + const QString question = forward ? i18n("End of document reached.\nContinue from the beginning?") : i18n("Beginning of document reached.\nContinue from the bottom?"); + if ( KMessageBox::questionYesNo(window(), question, QString(), KStandardGuiItem::cont(), KStandardGuiItem::cancel()) == KMessageBox::Yes ) { + m_document->continueSearch( m_id, m_searchType ); + return; + } + } + m_searchRunning = false; emit searchStopped(); }