Changeset View
Changeset View
Standalone View
Standalone View
core/document.cpp
Show First 20 Lines • Show All 129 Lines • ▼ Show 20 Line(s) | 127 | { | |||
---|---|---|---|---|---|
130 | RegularAreaRect continueOnMatch; | 130 | RegularAreaRect continueOnMatch; | ||
131 | QSet< int > highlightedPages; | 131 | QSet< int > highlightedPages; | ||
132 | 132 | | |||
133 | // fields related to previous searches (used for 'continueSearch') | 133 | // fields related to previous searches (used for 'continueSearch') | ||
134 | QString cachedString; | 134 | QString cachedString; | ||
135 | Document::SearchType cachedType; | 135 | Document::SearchType cachedType; | ||
136 | Qt::CaseSensitivity cachedCaseSensitivity; | 136 | Qt::CaseSensitivity cachedCaseSensitivity; | ||
137 | bool cachedViewportMove : 1; | 137 | bool cachedViewportMove : 1; | ||
138 | bool cachedWholeWords; | ||||
138 | bool isCurrentlySearching : 1; | 139 | bool isCurrentlySearching : 1; | ||
139 | QColor cachedColor; | 140 | QColor cachedColor; | ||
140 | int pagesDone; | 141 | int pagesDone; | ||
141 | }; | 142 | }; | ||
142 | 143 | | |||
143 | #define foreachObserver( cmd ) {\ | 144 | #define foreachObserver( cmd ) {\ | ||
144 | QSet< DocumentObserver * >::const_iterator it=d->m_observers.constBegin(), end=d->m_observers.constEnd();\ | 145 | QSet< DocumentObserver * >::const_iterator it=d->m_observers.constBegin(), end=d->m_observers.constEnd();\ | ||
145 | for ( ; it != end ; ++ it ) { (*it)-> cmd ; } } | 146 | for ( ; it != end ; ++ it ) { (*it)-> cmd ; } } | ||
▲ Show 20 Lines • Show All 1518 Lines • ▼ Show 20 Line(s) | 1625 | { | |||
1664 | { | 1665 | { | ||
1665 | // get page | 1666 | // get page | ||
1666 | Page * page = m_pagesVector[ searchStruct->currentPage ]; | 1667 | Page * page = m_pagesVector[ searchStruct->currentPage ]; | ||
1667 | // request search page if needed | 1668 | // request search page if needed | ||
1668 | if ( !page->hasTextPage() ) | 1669 | if ( !page->hasTextPage() ) | ||
1669 | m_parent->requestTextPage( page->number() ); | 1670 | m_parent->requestTextPage( page->number() ); | ||
1670 | 1671 | | |||
1671 | // if found a match on the current page, end the loop | 1672 | // if found a match on the current page, end the loop | ||
1672 | searchStruct->match = page->findText( searchStruct->searchID, search->cachedString, forward ? FromTop : FromBottom, search->cachedCaseSensitivity ); | 1673 | searchStruct->match = page->findText( searchStruct->searchID, search->cachedString, forward ? FromTop : FromBottom, search->cachedCaseSensitivity, nullptr, search->cachedWholeWords ); | ||
1673 | if ( !searchStruct->match ) | 1674 | if ( !searchStruct->match ) | ||
1674 | { | 1675 | { | ||
1675 | if (forward) searchStruct->currentPage++; | 1676 | if (forward) searchStruct->currentPage++; | ||
1676 | else searchStruct->currentPage--; | 1677 | else searchStruct->currentPage--; | ||
1677 | search->pagesDone++; | 1678 | search->pagesDone++; | ||
1678 | } | 1679 | } | ||
1679 | else | 1680 | else | ||
1680 | { | 1681 | { | ||
▲ Show 20 Lines • Show All 2084 Lines • ▼ Show 20 Line(s) | |||||
3765 | } | 3766 | } | ||
3766 | 3767 | | |||
3767 | void Document::setNextDocumentDestination( const QString &namedDestination ) | 3768 | void Document::setNextDocumentDestination( const QString &namedDestination ) | ||
3768 | { | 3769 | { | ||
3769 | d->m_nextDocumentDestination = namedDestination; | 3770 | d->m_nextDocumentDestination = namedDestination; | ||
3770 | } | 3771 | } | ||
3771 | 3772 | | |||
3772 | void Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, | 3773 | void Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, | ||
3773 | SearchType type, bool moveViewport, const QColor & color ) | 3774 | SearchType type, bool moveViewport, const QColor & color, bool wholeWords ) | ||
3774 | { | 3775 | { | ||
3775 | d->m_searchCancelled = false; | 3776 | d->m_searchCancelled = false; | ||
3776 | 3777 | | |||
3777 | // safety checks: don't perform searches on empty or unsearchable docs | 3778 | // safety checks: don't perform searches on empty or unsearchable docs | ||
3778 | if ( !d->m_generator || !d->m_generator->hasFeature( Generator::TextExtraction ) || d->m_pagesVector.isEmpty() ) | 3779 | if ( !d->m_generator || !d->m_generator->hasFeature( Generator::TextExtraction ) || d->m_pagesVector.isEmpty() ) | ||
3779 | { | 3780 | { | ||
3780 | emit searchFinished( searchID, NoMatchFound ); | 3781 | emit searchFinished( searchID, NoMatchFound ); | ||
3781 | return; | 3782 | return; | ||
Show All 11 Lines | |||||
3793 | 3794 | | |||
3794 | // update search structure | 3795 | // update search structure | ||
3795 | bool newText = text != s->cachedString; | 3796 | bool newText = text != s->cachedString; | ||
3796 | s->cachedString = text; | 3797 | s->cachedString = text; | ||
3797 | s->cachedType = type; | 3798 | s->cachedType = type; | ||
3798 | s->cachedCaseSensitivity = caseSensitivity; | 3799 | s->cachedCaseSensitivity = caseSensitivity; | ||
3799 | s->cachedViewportMove = moveViewport; | 3800 | s->cachedViewportMove = moveViewport; | ||
3800 | s->cachedColor = color; | 3801 | s->cachedColor = color; | ||
3802 | s->cachedWholeWords = wholeWords; | ||||
3801 | s->isCurrentlySearching = true; | 3803 | s->isCurrentlySearching = true; | ||
3802 | 3804 | | |||
3803 | // global data for search | 3805 | // global data for search | ||
3804 | QSet< int > *pagesToNotify = new QSet< int >; | 3806 | QSet< int > *pagesToNotify = new QSet< int >; | ||
3805 | 3807 | | |||
3806 | // remove highlights from pages and queue them for notifying changes | 3808 | // remove highlights from pages and queue them for notifying changes | ||
3807 | *pagesToNotify += s->highlightedPages; | 3809 | *pagesToNotify += s->highlightedPages; | ||
3808 | foreach(int pageNumber, s->highlightedPages) | 3810 | foreach(int pageNumber, s->highlightedPages) | ||
Show All 23 Lines | 3828 | { | |||
3832 | Page * lastPage = fromStart ? 0 : d->m_pagesVector[ currentPage ]; | 3834 | Page * lastPage = fromStart ? 0 : d->m_pagesVector[ currentPage ]; | ||
3833 | int pagesDone = 0; | 3835 | int pagesDone = 0; | ||
3834 | 3836 | | |||
3835 | // continue checking last TextPage first (if it is the current page) | 3837 | // continue checking last TextPage first (if it is the current page) | ||
3836 | RegularAreaRect * match = nullptr; | 3838 | RegularAreaRect * match = nullptr; | ||
3837 | if ( lastPage && lastPage->number() == s->continueOnPage ) | 3839 | if ( lastPage && lastPage->number() == s->continueOnPage ) | ||
3838 | { | 3840 | { | ||
3839 | if ( newText ) | 3841 | if ( newText ) | ||
3840 | match = lastPage->findText( searchID, text, forward ? FromTop : FromBottom, caseSensitivity ); | 3842 | match = lastPage->findText( searchID, text, forward ? FromTop : FromBottom, caseSensitivity, nullptr, wholeWords ); | ||
3841 | else | 3843 | else | ||
3842 | match = lastPage->findText( searchID, text, forward ? NextResult : PreviousResult, caseSensitivity, &s->continueOnMatch ); | 3844 | match = lastPage->findText( searchID, text, forward ? NextResult : PreviousResult, caseSensitivity, &s->continueOnMatch, wholeWords ); | ||
3843 | if ( !match ) | 3845 | if ( !match ) | ||
3844 | { | 3846 | { | ||
3845 | if (forward) currentPage++; | 3847 | if (forward) currentPage++; | ||
3846 | else currentPage--; | 3848 | else currentPage--; | ||
3847 | pagesDone++; | 3849 | pagesDone++; | ||
3848 | } | 3850 | } | ||
3849 | } | 3851 | } | ||
3850 | 3852 | | |||
Show All 13 Lines | 3865 | { | |||
3864 | QMap< Page *, QVector< QPair<RegularAreaRect *, QColor> > > *pageMatches = new QMap< Page *, QVector<QPair<RegularAreaRect *, QColor> > >; | 3866 | QMap< Page *, QVector< QPair<RegularAreaRect *, QColor> > > *pageMatches = new QMap< Page *, QVector<QPair<RegularAreaRect *, QColor> > >; | ||
3865 | const QStringList words = text.split( QLatin1Char ( ' ' ), QString::SkipEmptyParts ); | 3867 | const QStringList words = text.split( QLatin1Char ( ' ' ), QString::SkipEmptyParts ); | ||
3866 | 3868 | | |||
3867 | // search and highlight every word in 'text' on all pages | 3869 | // search and highlight every word in 'text' on all pages | ||
3868 | QMetaObject::invokeMethod(this, "doContinueGooglesDocumentSearch", Qt::QueuedConnection, Q_ARG(void *, pagesToNotify), Q_ARG(void *, pageMatches), Q_ARG(int, 0), Q_ARG(int, searchID), Q_ARG(QStringList, words)); | 3870 | QMetaObject::invokeMethod(this, "doContinueGooglesDocumentSearch", Qt::QueuedConnection, Q_ARG(void *, pagesToNotify), Q_ARG(void *, pageMatches), Q_ARG(int, 0), Q_ARG(int, searchID), Q_ARG(QStringList, words)); | ||
3869 | } | 3871 | } | ||
3870 | } | 3872 | } | ||
3871 | 3873 | | |||
3874 | void Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, | ||||
3875 | SearchType type, bool moveViewport, const QColor & color ) | ||||
3876 | { | ||||
3877 | searchText(searchID, text, fromStart, caseSensitivity, type, moveViewport, color, false ); | ||||
3878 | } | ||||
3879 | | ||||
3872 | void Document::continueSearch( int searchID ) | 3880 | void Document::continueSearch( int searchID ) | ||
3873 | { | 3881 | { | ||
3874 | // check if searchID is present in runningSearches | 3882 | // check if searchID is present in runningSearches | ||
3875 | QMap< int, RunningSearch * >::const_iterator it = d->m_searches.constFind( searchID ); | 3883 | QMap< int, RunningSearch * >::const_iterator it = d->m_searches.constFind( searchID ); | ||
3876 | if ( it == d->m_searches.constEnd() ) | 3884 | if ( it == d->m_searches.constEnd() ) | ||
3877 | { | 3885 | { | ||
3878 | emit searchFinished( searchID, NoMatchFound ); | 3886 | emit searchFinished( searchID, NoMatchFound ); | ||
3879 | return; | 3887 | return; | ||
3880 | } | 3888 | } | ||
3881 | 3889 | | |||
3882 | // start search with cached parameters from last search by searchID | 3890 | // start search with cached parameters from last search by searchID | ||
3883 | RunningSearch * p = *it; | 3891 | RunningSearch * p = *it; | ||
3884 | if ( !p->isCurrentlySearching ) | 3892 | if ( !p->isCurrentlySearching ) | ||
3885 | searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, | 3893 | searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, | ||
3886 | p->cachedType, p->cachedViewportMove, p->cachedColor ); | 3894 | p->cachedType, p->cachedViewportMove, p->cachedColor, p->cachedWholeWords ); | ||
3887 | } | 3895 | } | ||
3888 | 3896 | | |||
3889 | void Document::continueSearch( int searchID, SearchType type ) | 3897 | void Document::continueSearch( int searchID, SearchType type ) | ||
3890 | { | 3898 | { | ||
3891 | // check if searchID is present in runningSearches | 3899 | // check if searchID is present in runningSearches | ||
3892 | QMap< int, RunningSearch * >::const_iterator it = d->m_searches.constFind( searchID ); | 3900 | QMap< int, RunningSearch * >::const_iterator it = d->m_searches.constFind( searchID ); | ||
3893 | if ( it == d->m_searches.constEnd() ) | 3901 | if ( it == d->m_searches.constEnd() ) | ||
3894 | { | 3902 | { | ||
3895 | emit searchFinished( searchID, NoMatchFound ); | 3903 | emit searchFinished( searchID, NoMatchFound ); | ||
3896 | return; | 3904 | return; | ||
3897 | } | 3905 | } | ||
3898 | 3906 | | |||
3899 | // start search with cached parameters from last search by searchID | 3907 | // start search with cached parameters from last search by searchID | ||
3900 | RunningSearch * p = *it; | 3908 | RunningSearch * p = *it; | ||
3901 | if ( !p->isCurrentlySearching ) | 3909 | if ( !p->isCurrentlySearching ) | ||
3902 | searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, | 3910 | searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, | ||
3903 | type, p->cachedViewportMove, p->cachedColor ); | 3911 | type, p->cachedViewportMove, p->cachedColor, p->cachedWholeWords ); | ||
3904 | } | 3912 | } | ||
3905 | 3913 | | |||
3906 | void Document::resetSearch( int searchID ) | 3914 | void Document::resetSearch( int searchID ) | ||
3907 | { | 3915 | { | ||
3908 | // if we are closing down, don't bother doing anything | 3916 | // if we are closing down, don't bother doing anything | ||
3909 | if ( !d->m_generator ) | 3917 | if ( !d->m_generator ) | ||
3910 | return; | 3918 | return; | ||
3911 | 3919 | | |||
▲ Show 20 Lines • Show All 1760 Lines • Show Last 20 Lines |