add a private function for the nearest Page pixmap, for the PagePainter usage;

this way, the pixmap structure can be finally hidden in the private class

svn path=/trunk/playground/graphics/okular/; revision=646502
remotes/origin/KDE/4.0
Pino Toscano 19 years ago
parent 37235743bf
commit 229f3cf1de
  1. 60
      core/page.cpp
  2. 10
      core/page.h
  3. 9
      core/page_p.h
  4. 24
      ui/pagepainter.cpp

@ -71,18 +71,18 @@ PagePrivate::~PagePrivate()
void PagePrivate::imageRotationDone( RotationJob * job )
{
QMap< int, Page::PixmapObject >::iterator it = m_page->m_pixmaps.find( job->id() );
if ( it != m_page->m_pixmaps.end() )
QMap< int, PixmapObject >::iterator it = m_pixmaps.find( job->id() );
if ( it != m_pixmaps.end() )
{
Page::PixmapObject &object = it.value();
PixmapObject &object = it.value();
(*object.m_pixmap) = QPixmap::fromImage( job->image() );
object.m_rotation = job->rotation();
} else {
Page::PixmapObject object;
PixmapObject object;
object.m_pixmap = new QPixmap( QPixmap::fromImage( job->image() ) );
object.m_rotation = job->rotation();
m_page->m_pixmaps.insert( job->id(), object );
m_pixmaps.insert( job->id(), object );
}
}
@ -165,8 +165,8 @@ double Page::ratio() const
bool Page::hasPixmap( int id, int width, int height ) const
{
QMap< int, PixmapObject >::const_iterator it = m_pixmaps.find( id );
if ( it == m_pixmaps.end() )
QMap< int, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.find( id );
if ( it == d->m_pixmaps.end() )
return false;
if ( width == -1 || height == -1 )
@ -276,11 +276,11 @@ void Page::rotateAt( Rotation orientation )
/**
* Rotate the images of the page.
*/
QMapIterator< int, PixmapObject > it( m_pixmaps );
QMapIterator< int, PagePrivate::PixmapObject > it( d->m_pixmaps );
while ( it.hasNext() ) {
it.next();
const PixmapObject &object = it.value();
const PagePrivate::PixmapObject &object = it.value();
RotationJob *job = new RotationJob( object.m_pixmap->toImage(), object.m_rotation, d->m_rotation, it.key() );
job->setPage( d );
@ -354,14 +354,14 @@ const QLinkedList< FormField * > Page::formFields() const
void Page::setPixmap( int id, QPixmap *pixmap )
{
if ( d->m_rotation == Rotation0 ) {
QMap< int, PixmapObject >::iterator it = m_pixmaps.find( id );
if ( it != m_pixmaps.end() )
QMap< int, PagePrivate::PixmapObject >::iterator it = d->m_pixmaps.find( id );
if ( it != d->m_pixmaps.end() )
{
delete it.value().m_pixmap;
}
else
{
it = m_pixmaps.insert( id, PixmapObject() );
it = d->m_pixmaps.insert( id, PagePrivate::PixmapObject() );
}
it.value().m_pixmap = pixmap;
it.value().m_rotation = d->m_rotation;
@ -565,19 +565,19 @@ void Page::setFormFields( const QLinkedList< FormField * >& fields )
void Page::deletePixmap( int id )
{
PixmapObject object = m_pixmaps.take( id );
PagePrivate::PixmapObject object = d->m_pixmaps.take( id );
delete object.m_pixmap;
}
void Page::deletePixmaps()
{
QMapIterator< int, PixmapObject > it( m_pixmaps );
QMapIterator< int, PagePrivate::PixmapObject > it( d->m_pixmaps );
while ( it.hasNext() ) {
it.next();
delete it.value().m_pixmap;
}
m_pixmaps.clear();
d->m_pixmaps.clear();
}
void Page::deleteRects()
@ -731,3 +731,33 @@ void Page::saveLocalContents( QDomNode & parentNode, QDomDocument & document ) c
if ( pageElement.hasChildNodes() )
parentNode.appendChild( pageElement );
}
const QPixmap * Page::_o_nearestPixmap( int pixID, int w, int h ) const
{
Q_UNUSED( h )
const QPixmap * pixmap = 0;
// if a pixmap is present for given id, use it
QMap< int, PagePrivate::PixmapObject >::const_iterator itPixmap = d->m_pixmaps.find( pixID );
if ( itPixmap != d->m_pixmaps.end() )
pixmap = itPixmap.value().m_pixmap;
// else find the closest match using pixmaps of other IDs (great optim!)
else if ( !d->m_pixmaps.isEmpty() )
{
int minDistance = -1;
QMap< int, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.begin(), end = d->m_pixmaps.end();
for ( ; it != end; ++it )
{
int pixWidth = (*it).m_pixmap->width(),
distance = pixWidth > w ? pixWidth - w : w - pixWidth;
if ( minDistance == -1 || distance < minDistance )
{
pixmap = (*it).m_pixmap;
minDistance = distance;
}
}
}
return pixmap;
}

@ -11,7 +11,6 @@
#define _OKULAR_PAGE_H_
#include <QtCore/QLinkedList>
#include <QtCore/QMap>
#include <okular/core/okular_export.h>
#include <okular/core/area.h>
@ -19,6 +18,7 @@
class QDomDocument;
class QDomNode;
class QPixmap;
class QRect;
class PagePainter;
@ -354,13 +354,7 @@ class OKULAR_EXPORT Page
*/
friend class ::PagePainter;
class PixmapObject
{
public:
QPixmap *m_pixmap;
Rotation m_rotation;
};
QMap< int, PixmapObject > m_pixmaps;
const QPixmap * _o_nearestPixmap( int, int, int ) const;
QLinkedList< ObjectRect* > m_rects;
QLinkedList< HighlightAreaRect* > m_highlights;

@ -13,6 +13,7 @@
// qt/kde includes
#include <qlinkedlist.h>
#include <qmap.h>
#include <qmatrix.h>
#include <qstring.h>
@ -37,6 +38,14 @@ class PagePrivate
void imageRotationDone( RotationJob * job );
QMatrix rotationMatrix() const;
class PixmapObject
{
public:
QPixmap *m_pixmap;
Rotation m_rotation;
};
QMap< int, PixmapObject > m_pixmaps;
Page *m_page;
int m_number;
Rotation m_orientation;

@ -39,29 +39,7 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page
int pixID, int flags, int scaledWidth, int scaledHeight, const QRect &limits )
{
/** 1 - RETRIEVE THE 'PAGE+ID' PIXMAP OR A SIMILAR 'PAGE' ONE **/
const QPixmap * pixmap = 0;
// if a pixmap is present for given id, use it
QMap< int, Okular::Page::PixmapObject >::const_iterator itPixmap = page->m_pixmaps.find( pixID );
if ( itPixmap != page->m_pixmaps.end() )
pixmap = itPixmap.value().m_pixmap;
// else find the closest match using pixmaps of other IDs (great optim!)
else if ( !page->m_pixmaps.isEmpty() )
{
int minDistance = -1;
QMap< int, Okular::Page::PixmapObject >::const_iterator it = page->m_pixmaps.begin(), end = page->m_pixmaps.end();
for ( ; it != end; ++it )
{
int pixWidth = (*it).m_pixmap->width(),
distance = pixWidth > scaledWidth ? pixWidth - scaledWidth : scaledWidth - pixWidth;
if ( minDistance == -1 || distance < minDistance )
{
pixmap = (*it).m_pixmap;
minDistance = distance;
}
}
}
const QPixmap * pixmap = page->_o_nearestPixmap( pixID, scaledWidth, scaledHeight );
/** 1B - IF NO PIXMAP, DRAW EMPTY PAGE **/
double pixmapRescaleRatio = pixmap ? scaledWidth / (double)pixmap->width() : -1;

Loading…
Cancel
Save