diff --git a/core/area.cpp b/core/area.cpp index 8afb9969c..5692e58eb 100644 --- a/core/area.cpp +++ b/core/area.cpp @@ -157,7 +157,7 @@ HighlightAreaRect::HighlightAreaRect( const RegularAreaRect *area ) RegularAreaRect::ConstIterator itEnd = area->end(); for ( ; it != itEnd; ++it ) { - append( new NormalizedRect( *(*it) ) ); + appendShape( NormalizedRect( *it ) ); } } } diff --git a/core/area.h b/core/area.h index 6c2fb7c4d..d46a6dd9a 100644 --- a/core/area.h +++ b/core/area.h @@ -287,6 +287,21 @@ public: { return &t; } + + static const T* givePtr( const T& t ) + { + return &t; + } + + static T& deref( T& t ) + { + return t; + } + + static const T& deref( const T& t ) + { + return t; + } }; /** @internal */ @@ -303,6 +318,21 @@ public: { return t; } + + static const T* givePtr( const T* t ) + { + return t; + } + + static T& deref( T* t ) + { + return *t; + } + + static const T& deref( const T* t ) + { + return *t; + } }; /** @@ -347,10 +377,10 @@ void RegularArea::simplify() int end = this->count() - 1, x = 0; for ( int i = 0; i < end; ++i ) { - if ( (*this)[x]->intersects( (*this)[i+1] ) ) + if ( okularPtrUtils::givePtr( (*this)[x] )->intersects( okularPtrUtils::deref( (*this)[i+1] ) ) ) { - *((*this)[x]) |= *((*this)[i+1]); - NormalizedShape tobedeleted = (*this)[i+1]; + okularPtrUtils::deref((*this)[x]) |= okularPtrUtils::deref((*this)[i+1]); + NormalizedShape& tobedeleted = (*this)[i+1]; this->removeAt( i + 1 ); okularPtrUtils::doDelete( tobedeleted ); --end; @@ -376,7 +406,7 @@ bool RegularArea::isNull() const return false; foreach ( const NormalizedShape& ns, *this ) - if ( !(ns->isNull()) ) + if ( !(okularPtrUtils::givePtr(ns)->isNull()) ) return false; return true; @@ -392,7 +422,7 @@ bool RegularArea::intersects( const NormalizedShape& rec return false; foreach ( const NormalizedShape& ns, *this ) - if ( !( ns->isNull() ) && ns->intersects( rect ) ) + if ( !okularPtrUtils::givePtr(ns)->isNull() && okularPtrUtils::givePtr(ns)->intersects( rect ) ) return true; return false; @@ -411,7 +441,7 @@ bool RegularArea::intersects( const RegularAreaisNull) && ns->intersects( shape ) ) + if ( !ns->isNull() && ns->intersects( shape ) ) return true; } } @@ -446,10 +476,10 @@ void RegularArea::appendShape( const NormalizedShape& sh { // if the new shape intersects with the last shape in the list, then // merge it with that and delete the shape - if ( (*this)[size - 1]->intersects( shape ) ) + if ( okularPtrUtils::givePtr((*this)[size - 1])->intersects( shape ) ) { - *((*this)[size - 1]) |= *okularPtrUtils::givePtr( shape ); - okularPtrUtils::doDelete( shape ); + okularPtrUtils::deref((*this)[size - 1]) |= okularPtrUtils::deref( shape ); + okularPtrUtils::doDelete( const_cast( shape ) ); } else this->append( shape ); @@ -498,7 +528,7 @@ QList * RegularArea::geometry( int xScale, int yS Shape t; foreach( const NormalizedShape& ns, *this ) { - t = ns->geometry( xScale, yScale ); + t = okularPtrUtils::givePtr(ns)->geometry( xScale, yScale ); t.translate( dx, dy ); ret->append( t ); } @@ -506,7 +536,7 @@ QList * RegularArea::geometry( int xScale, int yS return ret; } -typedef RegularArea RegularAreaRect; +typedef RegularArea RegularAreaRect; class HighlightAreaRect : public RegularAreaRect { diff --git a/core/document.cpp b/core/document.cpp index 40a06e143..2d5863408 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -1102,8 +1102,8 @@ bool Document::searchText( int searchID, const QString & text, bool fromStart, Q { DocumentViewport searchViewport( currentPage ); searchViewport.rePos.enabled = true; - searchViewport.rePos.normalizedX = (match->first()->left + match->first()->right) / 2.0; - searchViewport.rePos.normalizedY = (match->first()->top + match->first()->bottom) / 2.0; + searchViewport.rePos.normalizedX = (match->first().left + match->first().right) / 2.0; + searchViewport.rePos.normalizedY = (match->first().top + match->first().bottom) / 2.0; setViewport( searchViewport, -1, true ); } } diff --git a/core/textpage.cpp b/core/textpage.cpp index 8b0425c90..a9c8ea677 100644 --- a/core/textpage.cpp +++ b/core/textpage.cpp @@ -234,7 +234,7 @@ RegularAreaRect * TextPage::textArea ( TextSelection * sel) const { tmp=d->m_words[it]->transformedArea(); if (tmp->intersects(&first) || tmp->intersects(&second) || tmp->intersects(&third)) - ret->appendShape(new NormalizedRect(*tmp)); + ret->appendShape(*tmp); } // } @@ -390,7 +390,7 @@ RegularAreaRect* TextPage::Private::findTextInternalForward( int searchID, const kDebug(1223) << "\tmatched" << endl; #endif haveMatch=true; - ret->append( curEntity->transformedArea() ); + ret->append( *curEntity->transformedArea() ); j+=min; queryLeft-=min; } @@ -434,7 +434,7 @@ QString TextPage::text(const RegularAreaRect *area) const { for ( ; it != itEnd; ++it ) { - if ( area->intersects( (*it)->transformedArea() ) ) + if ( area->intersects( *(*it)->transformedArea() ) ) { ret += (*it)->text(); } diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 24e3a7c3d..e36d19cd8 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -104,7 +104,7 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page // vectors containing objects to draw // make this a qcolor, rect map, since we don't need // to know s_id here! we are only drawing this right? - QList< QPair > * bufferedHighlights = 0; + QList< QPair > * bufferedHighlights = 0; QList< Okular::Annotation * > * bufferedAnnotations = 0; QList< Okular::Annotation * > * unbufferedAnnotations = 0; // fill up lists with visible annotation/highlight objects/text selections @@ -119,17 +119,17 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page if ( canDrawHighlights ) { if ( !bufferedHighlights ) - bufferedHighlights = new QList< QPair >(); + bufferedHighlights = new QList< QPair >(); /* else {*/ Okular::NormalizedRect* limitRect = new Okular::NormalizedRect(nXMin, nYMin, nXMax, nYMax ); QLinkedList< Okular::HighlightAreaRect * >::const_iterator h2It = page->m_highlights.begin(), hEnd = page->m_highlights.end(); - QList< Okular::NormalizedRect * >::const_iterator hIt; + Okular::HighlightAreaRect::const_iterator hIt; for ( ; h2It != hEnd; ++h2It ) for (hIt=(*h2It)->begin(); hIt!=(*h2It)->end(); ++hIt) { - if ((*hIt)->intersects(limitRect)) + if ((*hIt).intersects(limitRect)) bufferedHighlights->append( qMakePair((*h2It)->color,*hIt) ); } delete limitRect; @@ -138,14 +138,14 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page if ( canDrawTextSelection ) { if ( !bufferedHighlights ) - bufferedHighlights = new QList< QPair >(); + bufferedHighlights = new QList< QPair >(); /* else {*/ Okular::NormalizedRect* limitRect = new Okular::NormalizedRect(nXMin, nYMin, nXMax, nYMax ); - QList< Okular::NormalizedRect * >::const_iterator hIt = page->m_textSelections->begin(), hEnd = page->m_textSelections->end(); + Okular::HighlightAreaRect::const_iterator hIt = page->m_textSelections->begin(), hEnd = page->m_textSelections->end(); for ( ; hIt != hEnd; ++hIt ) { - if ( (*hIt)->intersects( limitRect ) ) + if ( (*hIt).intersects( limitRect ) ) bufferedHighlights->append( qMakePair( page->m_textSelections->color, *hIt ) ); } delete limitRect; @@ -275,12 +275,12 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page if ( bufferedHighlights ) { // draw highlights that are inside the 'limits' paint region - QList< QPair >::const_iterator hIt = bufferedHighlights->begin(), hEnd = bufferedHighlights->end(); + QList< QPair >::const_iterator hIt = bufferedHighlights->begin(), hEnd = bufferedHighlights->end(); for ( ; hIt != hEnd; ++hIt ) { - Okular::NormalizedRect * r = (*hIt).second; + const Okular::NormalizedRect & r = (*hIt).second; // find out the rect to highlight on pixmap - QRect highlightRect = r->geometry( scaledWidth, scaledHeight ).intersect( limits ); + QRect highlightRect = r.geometry( scaledWidth, scaledHeight ).intersect( limits ); highlightRect.translate( -limits.left(), -limits.top() ); // highlight composition (product: highlight color * destcolor) diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 922910d53..e5c03da26 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -1640,7 +1640,6 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e ) if (d->document->supportsSearching()) { // grab text in selection by extracting it from all intersected pages - Okular::RegularAreaRect * rects=new Okular::RegularAreaRect; const Okular::Page * okularPage=0; QVector< PageViewItem * >::const_iterator iIt = d->items.begin(), iEnd = d->items.end(); for ( ; iIt != iEnd; ++iIt ) @@ -1657,11 +1656,11 @@ void PageView::contentsMouseReleaseEvent( QMouseEvent * e ) // grab text in the rect that intersects itemRect QRect relativeRect = selectionRect.intersect( itemRect ); relativeRect.translate( -itemRect.left(), -itemRect.top() ); - rects->append(new Okular::NormalizedRect( relativeRect, item->width(), item->height() )); + Okular::RegularAreaRect rects; + rects.append( Okular::NormalizedRect( relativeRect, item->width(), item->height() ) ); + selectedText += okularPage->text( &rects ); } } - if (okularPage) - selectedText = okularPage->text( rects ); } // popup that ask to copy:text and copy/save:image diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index 3bc2a3ac4..1f42046bd 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -468,9 +468,9 @@ class TextSelectorEngine : public AnnotatorEngine QColor col = m_engineColor; col.setAlphaF( 0.5 ); painter->setBrush( col ); - foreach( Okular::NormalizedRect * r, *selection ) + foreach( const Okular::NormalizedRect & r, *selection ) { - painter->drawRect( r->geometry( (int)xScale, (int)yScale ) ); + painter->drawRect( r.geometry( (int)xScale, (int)yScale ) ); } } } @@ -515,16 +515,16 @@ class TextSelectorEngine : public AnnotatorEngine Okular::HighlightAnnotation * ha = new Okular::HighlightAnnotation(); ha->setHighlightType( type ); ha->setBoundingRectangle( Okular::NormalizedRect( rect, (int)item()->width(), (int)item()->height() ) ); - foreach ( Okular::NormalizedRect * rect, *selection ) + foreach ( const Okular::NormalizedRect & rect, *selection ) { Okular::HighlightAnnotation::Quad q; q.setCapStart( false ); q.setCapEnd( false ); q.setFeather( 1.0 ); - q.setPoint( Okular::NormalizedPoint( rect->left, rect->bottom ), 0 ); - q.setPoint( Okular::NormalizedPoint( rect->right, rect->bottom ), 1 ); - q.setPoint( Okular::NormalizedPoint( rect->right, rect->top ), 2 ); - q.setPoint( Okular::NormalizedPoint( rect->left, rect->top ), 3 ); + q.setPoint( Okular::NormalizedPoint( rect.left, rect.bottom ), 0 ); + q.setPoint( Okular::NormalizedPoint( rect.right, rect.bottom ), 1 ); + q.setPoint( Okular::NormalizedPoint( rect.right, rect.top ), 2 ); + q.setPoint( Okular::NormalizedPoint( rect.left, rect.top ), 3 ); ha->highlightQuads().append( q ); } ann = ha;