diff --git a/core/document.cpp b/core/document.cpp index 3103dd20f..c70db8a1b 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -108,7 +108,7 @@ struct RunningSearch // fields related to previous searches (used for 'continueSearch') QString cachedString; Document::SearchType cachedType; - bool cachedCaseSensitive; + Qt::CaseSensitivity cachedCaseSensitivity; bool cachedViewportMove; bool cachedNoDialogs; QColor cachedColor; @@ -964,7 +964,7 @@ void Document::setNextDocumentViewport( const DocumentViewport & viewport ) d->nextDocumentViewport = viewport; } -bool Document::searchText( int searchID, const QString & text, bool fromStart, bool caseSensitive, +bool Document::searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, SearchType type, bool moveViewport, const QColor & color, bool noDialogs ) { // safety checks: don't perform searches on empty or unsearchable docs @@ -989,7 +989,7 @@ bool Document::searchText( int searchID, const QString & text, bool fromStart, b bool newText = text != s->cachedString; s->cachedString = text; s->cachedType = type; - s->cachedCaseSensitive = caseSensitive; + s->cachedCaseSensitivity = caseSensitivity; s->cachedViewportMove = moveViewport; s->cachedNoDialogs = noDialogs; s->cachedColor = color; @@ -1029,9 +1029,9 @@ bool Document::searchText( int searchID, const QString & text, bool fromStart, b while ( 1 ) { if ( lastMatch ) - lastMatch = page->findText( searchID, text, NextRes, caseSensitive, lastMatch ); + lastMatch = page->findText( searchID, text, NextResult, caseSensitivity, lastMatch ); else - lastMatch = page->findText( searchID, text, FromTop, caseSensitive ); + lastMatch = page->findText( searchID, text, FromTop, caseSensitivity ); if ( !lastMatch ) break; @@ -1071,9 +1071,9 @@ bool Document::searchText( int searchID, const QString & text, bool fromStart, b if ( lastPage && lastPage->number() == s->continueOnPage ) { if ( newText ) - match = lastPage->findText( searchID, text, FromTop, caseSensitive ); + match = lastPage->findText( searchID, text, FromTop, caseSensitivity ); else - match = lastPage->findText( searchID, text, NextRes, caseSensitive, &s->continueOnMatch ); + match = lastPage->findText( searchID, text, NextResult, caseSensitivity, &s->continueOnMatch ); if ( !match ) currentPage++; } @@ -1097,7 +1097,7 @@ bool Document::searchText( int searchID, const QString & text, bool fromStart, b if ( !page->hasTextPage() ) requestTextPage( page->number() ); // if found a match on the current page, end the loop - if ( ( match = page->findText( searchID, text, FromTop, caseSensitive ) ) ) + if ( ( match = page->findText( searchID, text, FromTop, caseSensitivity ) ) ) break; currentPage++; } @@ -1175,9 +1175,9 @@ bool Document::searchText( int searchID, const QString & text, bool fromStart, b while ( 1 ) { if ( lastMatch ) - lastMatch = page->findText( searchID, word, NextRes, caseSensitive, lastMatch ); + lastMatch = page->findText( searchID, word, NextResult, caseSensitivity, lastMatch ); else - lastMatch = page->findText( searchID, word, FromTop, caseSensitive); + lastMatch = page->findText( searchID, word, FromTop, caseSensitivity); if ( !lastMatch ) break; @@ -1228,7 +1228,7 @@ bool Document::continueSearch( int searchID ) // start search with cached parameters from last search by searchID RunningSearch * p = d->searches[ searchID ]; - return searchText( searchID, p->cachedString, false, p->cachedCaseSensitive, + return searchText( searchID, p->cachedString, false, p->cachedCaseSensitivity, p->cachedType, p->cachedViewportMove, p->cachedColor, p->cachedNoDialogs ); } diff --git a/core/document.h b/core/document.h index 3f9a668a0..ee7f2c9b4 100644 --- a/core/document.h +++ b/core/document.h @@ -141,7 +141,7 @@ class OKULAR_EXPORT Document : public QObject void setPageTextSelection( int page, RegularAreaRect * rect, const QColor & color ); enum SearchType { NextMatch, PrevMatch, AllDoc, GoogleAll, GoogleAny }; - bool searchText( int searchID, const QString & text, bool fromStart, bool caseSensitive, + bool searchText( int searchID, const QString & text, bool fromStart, Qt::CaseSensitivity caseSensitivity, SearchType type, bool moveViewport, const QColor & color, bool noDialogs = false ); bool continueSearch( int searchID ); void resetSearch( int searchID ); diff --git a/core/page.cpp b/core/page.cpp index be1a17eda..0e05e34c1 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -137,33 +137,27 @@ bool Page::hasTransition() const } -RegularAreaRect * Page::findText( int searchID, const QString & text, SearchDir dir, bool strictCase, - const RegularAreaRect * lastRect/*, const Generator &generator */) const +RegularAreaRect * Page::findText( int id, const QString & text, SearchDirection direction, + Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *lastRect ) const { - RegularAreaRect* ret=0; - if ( text.isEmpty() ) - return ret; -/* - if (generator->preferInternalSearch()) - return generator->;*/ - - ret=m_text->findText(searchID, text, dir, strictCase,lastRect); - return ret; -/* + RegularAreaRect* rect = 0; + if ( text.isEmpty() ) + return rect; - */ + rect = m_text->findText( id, text, direction, caseSensitivity, lastRect ); + return rect; } QString Page::getText( const RegularAreaRect * area ) const { - QString ret; + QString ret; - if ( !m_text ) - return ret; + if ( !m_text ) + return ret; - ret = m_text->getText( area ); + ret = m_text->getText( area ); - return ret; + return ret; } void Page::rotateAt( int orientation ) diff --git a/core/page.h b/core/page.h index 359c50e11..940b56d95 100644 --- a/core/page.h +++ b/core/page.h @@ -92,13 +92,44 @@ class OKULAR_EXPORT Page : public QObject * Returns whether the page provides a text page (@see TextPage). */ bool hasTextPage() const; + + /** + * Returns whether the page provides bookmarks. + */ bool hasBookmark() const; + + /** + * Returns whether the page has an object rect which includes the point (@p x, @p y) + * at scale (@p xScale, @p yScale). + */ bool hasObjectRect( double x, double y, double xScale, double yScale ) const; - bool hasHighlights( int s_id = -1 ) const; - //bool hasAnnotation( double x, double y ) const; + + /** + * Returns whether the page provides highlighting for the observer with the + * given @p id. + */ + bool hasHighlights( int id = -1 ) const; + + /** + * Returns whether the page provides a transition effect. + */ bool hasTransition() const; - RegularAreaRect * findText( int searchID, const QString & text, SearchDir dir, bool strictCase, const RegularAreaRect * lastRect=0) const; + /** + * Returns the bounding rect of the text which matches the following criteria + * or 0 if the search is not successful. + * + * @param id An unique id for this search. + * @param text The search text. + * @param direction The direction of the search (@see SearchDirection) + * @param caseSensitivity If Qt::CaseSensitive, the search is case sensitive; otherwise + * the search is case insensitive. + * @param lastRect If 0 (default) the search starts at the beginning of the page, otherwise + * right/below the coordinates of the the given rect. + */ + RegularAreaRect* findText( int id, const QString & text, SearchDirection direction, + Qt::CaseSensitivity caseSensitivity, const RegularAreaRect * lastRect=0) const; + QString getText( const RegularAreaRect * rect ) const; RegularAreaRect * getTextArea ( TextSelection * ) const; //const ObjectRect * getObjectRect( double x, double y ) const; diff --git a/core/textpage.cpp b/core/textpage.cpp index 013afc6f9..65ed30bae 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -165,10 +165,10 @@ RegularAreaRect * TextPage::getTextArea ( TextSelection * sel) const } -RegularAreaRect* TextPage::findText(int searchID, const QString &query, SearchDir & direct, - bool strictCase, const RegularAreaRect *area) +RegularAreaRect* TextPage::findText( int searchID, const QString &query, SearchDirection & direct, + Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *area ) { - SearchDir dir=direct; + SearchDirection dir=direct; // invalid search request if ( query.isEmpty() || area->isNull() ) return 0; @@ -178,9 +178,9 @@ RegularAreaRect* TextPage::findText(int searchID, const QString &query, SearchDi { // if no previous run of this search is found, then set it to start // from the beginning (respecting the search direction) - if ( dir == NextRes ) + if ( dir == NextResult ) dir = FromTop; - else if ( dir == PrevRes ) + else if ( dir == PreviousResult ) dir = FromBottom; } bool forward = true; @@ -199,11 +199,11 @@ RegularAreaRect* TextPage::findText(int searchID, const QString &query, SearchDi } forward = false; break; - case NextRes: + case NextResult: start = m_searchPoints[ searchID ]->theIt; end = m_words.end(); break; - case PrevRes: + case PreviousResult: start = m_searchPoints[ searchID ]->theIt; end = m_words.begin(); forward = false; @@ -212,26 +212,27 @@ RegularAreaRect* TextPage::findText(int searchID, const QString &query, SearchDi RegularAreaRect* ret = 0; if ( forward ) { - ret = findTextInternalForward( searchID, query, strictCase, start, end ); + ret = findTextInternalForward( searchID, query, caseSensitivity, start, end ); } // TODO implement backward search #if 0 else { - ret = findTextInternalBackward( searchID, query, strictCase, start, end ); + ret = findTextInternalBackward( searchID, query, caseSensitivity, start, end ); } #endif return ret; } -RegularAreaRect* TextPage::findTextInternalForward(int searchID, const QString &_query, - bool strictCase, const QList::ConstIterator &start, - const QList::ConstIterator &end) +RegularAreaRect* TextPage::findTextInternalForward( int searchID, const QString &_query, + Qt::CaseSensitivity caseSensitivity, + const QList::ConstIterator &start, + const QList::ConstIterator &end ) { RegularAreaRect* ret=new RegularAreaRect; - QString query = strictCase ? _query : _query.toLower(); + QString query = (caseSensitivity == Qt::CaseSensitive) ? _query : _query.toLower(); // j is the current position in our query // len is the length of the string in TextEntity @@ -280,7 +281,7 @@ RegularAreaRect* TextPage::findTextInternalForward(int searchID, const QString & // we have equal (or less then) area of the query left as the lengt of the current // entity - if ((strictCase) + if ((caseSensitivity == Qt::CaseSensitive) ? (str.mid(offset,min) != query.mid(j,min)) : (str.mid(offset,min).toLower() != query.mid(j,min)) ) diff --git a/core/textpage.h b/core/textpage.h index 42605919c..fddd8c474 100644 --- a/core/textpage.h +++ b/core/textpage.h @@ -20,24 +20,24 @@ namespace Okular { class TextSelection; -/*! @enum SearchDir +/*! @enum SearchDirection * The enum holding the direction of searching. - *! @enum SearchDir FromTop + *! @enum SearchDirection FromTop * Searching from top of the page, next result is to be found, * there was no earlier search result. - *! @enum SearchDir FromBottom + *! @enum SearchDirection FromBottom * Searching from bottom of the page, next result is to be found, * there was no earlier search result. - *! @enum SearchDir NextRes + *! @enum SearchDirection NextResult * Searching for the next result on the page, earlier result should be * located so we search from the last result not from the beginning of the * page. - *! @enum SearchDir PrevRes + *! @enum SearchDirection PreviousResult * Searching for the previous result on the page, earlier result should be * located so we search from the last result not from the beginning of the * page. */ -typedef enum SearchDir{ FromTop, FromBottom, NextRes, PrevRes }; +typedef enum SearchDirection{ FromTop, FromBottom, NextResult, PreviousResult }; /*! @struct TextEntity * @short Abstract textentity of Okular @@ -70,8 +70,8 @@ struct SearchPoint; class TextPage { public: - RegularAreaRect* findText(int searchID, const QString &query, SearchDir & direct, - bool strictCase, const RegularAreaRect *area); + RegularAreaRect* findText( int id, const QString &query, SearchDirection & direct, + Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *area); QString getText(const RegularAreaRect *rect) const; RegularAreaRect * getTextArea ( TextSelection* ) const; TextPage(QList words) : m_words(words) {}; @@ -81,7 +81,7 @@ class TextPage ~TextPage(); private: RegularAreaRect * findTextInternalForward(int searchID, const QString &query, - bool strictCase, const QList::ConstIterator &start, + Qt::CaseSensitivity caseSensitivity, const QList::ConstIterator &start, const QList::ConstIterator &end); QList m_words; QMap m_searchPoints; diff --git a/part.cpp b/part.cpp index 9a7f822c6..a999f3ede 100644 --- a/part.cpp +++ b/part.cpp @@ -949,7 +949,8 @@ void Part::slotFind() m_searchHistory = dlg.findHistory(); m_searchStarted = true; m_document->resetSearch( PART_SEARCH_ID ); - m_document->searchText( PART_SEARCH_ID, dlg.pattern(), false, dlg.options() & KFind::CaseSensitive, + m_document->searchText( PART_SEARCH_ID, dlg.pattern(), false, + dlg.options() & KFind::CaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive, Okular::Document::NextMatch, true, qRgb( 255, 255, 64 ) ); } } diff --git a/ui/pageview.cpp b/ui/pageview.cpp index bce072f1a..cdeaf7756 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -911,8 +911,9 @@ void PageView::keyPressEvent( QKeyEvent * e ) if( d->typeAheadString.length() > 1 ) { d->typeAheadString = d->typeAheadString.left( d->typeAheadString.length() - 1 ); - bool found = d->document->searchText( PAGEVIEW_SEARCH_ID, d->typeAheadString, true, false, - Okular::Document::NextMatch, true, qRgb( 128, 255, 128 ), true ); + bool found = d->document->searchText( PAGEVIEW_SEARCH_ID, d->typeAheadString, + true, Qt::CaseInsensitive, + Okular::Document::NextMatch, true, qRgb( 128, 255, 128 ), true ); KLocalizedString status = found ? ki18n("Text found: \"%1\".") : ki18n("Text not found: \"%1\"."); d->messageWindow->display( status.subs(d->typeAheadString.toLower()).toString(), found ? PageViewMessage::Find : PageViewMessage::Warning, 4000 ); @@ -2286,7 +2287,8 @@ void PageView::center(int cx, int cy) void PageView::doTypeAheadSearch() { - bool found = d->document->searchText( PAGEVIEW_SEARCH_ID, d->typeAheadString, false, false, + bool found = d->document->searchText( PAGEVIEW_SEARCH_ID, d->typeAheadString, + false, Qt::CaseInsensitive, Okular::Document::NextMatch, true, qRgb( 128, 255, 128 ), true ); KLocalizedString status = found ? ki18n("Text found: \"%1\".") : ki18n("Text not found: \"%1\"."); d->messageWindow->display( status.subs(d->typeAheadString.toLower()).toString(), diff --git a/ui/searchwidget.cpp b/ui/searchwidget.cpp index d861875a1..84d1696a9 100644 --- a/ui/searchwidget.cpp +++ b/ui/searchwidget.cpp @@ -129,11 +129,13 @@ void SearchWidget::startSearch() bool ok = true; if ( text.length() >= 3 ) { - bool caseSensitive = m_caseSensitiveAction->isChecked(); + Qt::CaseSensitivity caseSensitivity = m_caseSensitiveAction->isChecked() ? Qt::CaseSensitive : Qt::CaseInsensitive; + Okular::Document::SearchType type = !m_searchType ? Okular::Document::AllDoc : ( (m_searchType > 1) ? Okular::Document::GoogleAny : Okular::Document::GoogleAll ); - ok = m_document->searchText( SW_SEARCH_ID, text, true, caseSensitive, + + ok = m_document->searchText( SW_SEARCH_ID, text, true, caseSensitivity, type, false, qRgb( 0, 183, 255 ) ); } else