Commit 541650a4 authored by Albert Astals Cid's avatar Albert Astals Cid

Remove the concept of observer/view id

Just use the pointer as id :-)

This is BIC and SIC, increase the soversion now to makes sure we don't forget in the future

Patch based in an earlier patch by Bogdan Cristea <cristeab@gmail.com>
REVIEW: 109115
parent a579df63
......@@ -97,6 +97,7 @@ install( FILES
core/utils.h
core/version.h
core/fileprinter.h
core/observer.h
${CMAKE_CURRENT_BINARY_DIR}/settings_core.h
DESTINATION ${INCLUDE_INSTALL_DIR}/okular/core COMPONENT Devel)
......@@ -123,7 +124,7 @@ ENDIF(APPLE)
target_link_libraries(okularcore ${OKULAR_IOKIT} ${KDE4_KIO_LIBS} ${KDE4_PHONON_LIBRARY} ${KDE4_KJSAPI_LIBRARY} ${MATH_LIB} ${KDE4_THREADWEAVER_LIBRARY} )
set_target_properties(okularcore PROPERTIES VERSION 2.0.0 SOVERSION 2 )
set_target_properties(okularcore PROPERTIES VERSION 3.0.0 SOVERSION 3 )
install(TARGETS okularcore ${INSTALL_TARGETS_DEFAULT_ARGS} )
......
......@@ -21,6 +21,7 @@
#include <QtDeclarative/qdeclarative.h>
#include <core/document_p.h>
#include <core/page.h>
#include <core/bookmarkmanager.h>
......@@ -28,6 +29,8 @@
DocumentItem::DocumentItem(QObject *parent)
: QObject(parent),
m_thumbnailObserver(0),
m_pageviewObserver(0),
m_searchInProgress(false)
{
qmlRegisterUncreatableType<TOCModel>("org.kde.okular", 1, 0, "TOCModel", QLatin1String("Do not create objects of this type."));
......@@ -192,13 +195,22 @@ Okular::Document *DocumentItem::document()
return m_document;
}
Observer *DocumentItem::observerFor(int id)
Observer *DocumentItem::thumbnailObserver()
{
if (!m_observers.contains(id)) {
m_observers[id] = new Observer(this, id);
if (!m_thumbnailObserver)
m_thumbnailObserver = new Observer(this);
return m_thumbnailObserver;
}
Observer *DocumentItem::pageviewObserver()
{
if (!m_pageviewObserver) {
m_pageviewObserver = new Observer(this);
m_document->d->m_tiledObserver = m_pageviewObserver;
}
return m_observers.value(id);
return m_pageviewObserver;
}
void DocumentItem::searchFinished(int id, Okular::Document::SearchStatus endStatus)
......@@ -226,9 +238,8 @@ void DocumentItem::searchFinished(int id, Okular::Document::SearchStatus endStat
//Observer
Observer::Observer(DocumentItem *parent, int id)
Observer::Observer(DocumentItem *parent)
: QObject(parent),
m_observerId(id),
m_document(parent)
{
parent->document()->addObserver(this);
......
......@@ -137,7 +137,8 @@ public:
//Internal, not binded to qml
Okular::Document *document();
Observer *observerFor(int id);
Observer *pageviewObserver();
Observer *thumbnailObserver();
Q_SIGNALS:
void pathChanged();
......@@ -157,7 +158,8 @@ private Q_SLOTS:
private:
Okular::Document *m_document;
TOCModel *m_tocModel;
QHash <int, Observer *> m_observers;
Observer *m_thumbnailObserver;
Observer *m_pageviewObserver;
QList<int> m_matchingPages;
bool m_searchInProgress;
};
......@@ -167,18 +169,16 @@ class Observer : public QObject, public Okular::DocumentObserver
Q_OBJECT
public:
Observer(DocumentItem *parent, int observerId);
Observer(DocumentItem *parent);
~Observer();
// inherited from DocumentObserver
uint observerId() const { return m_observerId; }
void notifyPageChanged(int page, int flags);
Q_SIGNALS:
void pageChanged(int page, int flags);
private:
int m_observerId;
DocumentItem *m_document;
};
......
......@@ -30,6 +30,7 @@
#include <core/page.h>
#include "ui/pagepainter.h"
#include "ui/priorities.h"
#include "settings.h"
#define REDRAW_TIMEOUT 250
......@@ -41,9 +42,8 @@ PageItem::PageItem(QDeclarativeItem *parent)
m_smooth(false),
m_intentionalDraw(false),
m_bookmarked(false),
m_observerId(PAGEVIEW_ID)
m_isThumbnail(false)
{
m_observerId = PAGEVIEW_ID;
setFlag(QGraphicsItem::ItemHasNoContents, false);
m_viewPort.rePos.enabled = true;
......@@ -111,7 +111,7 @@ void PageItem::setDocument(DocumentItem *doc)
m_page = 0;
disconnect(doc, 0, this, 0);
m_documentItem = doc;
Observer *observer = m_documentItem.data()->observerFor(m_observerId);
Observer *observer = m_isThumbnail ? m_documentItem.data()->thumbnailObserver() : m_documentItem.data()->pageviewObserver();
connect(observer, SIGNAL(pageChanged(int, int)), this, SLOT(pageHasChanged(int, int)));
connect(doc->document()->bookmarkManager(), SIGNAL(bookmarksChanged(KUrl)),
this, SLOT(checkBookmarksChanged()));
......@@ -304,19 +304,18 @@ void PageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
painter->setRenderHint(QPainter::Antialiasing, true);
}
const int priority = m_observerId == PAGEVIEW_ID ? PAGEVIEW_PRELOAD_PRIO : THUMBNAILS_PRELOAD_PRIO;
Observer *observer = m_isThumbnail ? m_documentItem.data()->thumbnailObserver() : m_documentItem.data()->pageviewObserver();
const int priority = m_isThumbnail ? THUMBNAILS_PRIO : PAGEVIEW_PRIO;
if (m_intentionalDraw) {
QLinkedList<Okular::PixmapRequest *> requestedPixmaps;
requestedPixmaps.push_back(new Okular::PixmapRequest(m_observerId, m_viewPort.pageNumber, width(), height(), priority, true));
const Okular::Document::PixmapRequestFlag prf = (m_observerId == PAGEVIEW_ID) ?
Okular::Document::RemoveAllPrevious :
Okular::Document::NoOption;
requestedPixmaps.push_back(new Okular::PixmapRequest(observer, m_viewPort.pageNumber, width(), height(), priority, Okular::PixmapRequest::Asynchronous));
const Okular::Document::PixmapRequestFlag prf = m_isThumbnail ? Okular::Document::NoOption : Okular::Document::RemoveAllPrevious;
m_documentItem.data()->document()->requestPixmaps(requestedPixmaps, prf);
m_intentionalDraw = false;
}
const int flags = PagePainter::Accessibility | PagePainter::Highlights | PagePainter::Annotations;
PagePainter::paintPageOnPainter(painter, m_page, m_observerId, flags, width(), height(), option->exposedRect.toRect());
PagePainter::paintPageOnPainter(painter, m_page, observer, flags, width(), height(), option->exposedRect.toRect());
if (setAA) {
painter->restore();
......@@ -383,11 +382,11 @@ void PageItem::contentYChanged()
void PageItem::setIsThumbnail(bool thumbnail)
{
if (thumbnail == (m_observerId == THUMBNAILS_ID)) {
if (thumbnail == m_isThumbnail) {
return;
}
m_observerId = thumbnail ? THUMBNAILS_ID : PAGEVIEW_ID;
m_isThumbnail = thumbnail;
if (thumbnail) {
m_smooth = false;
......
......@@ -136,9 +136,6 @@ public:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
// inherited from View
uint viewId() const { return m_observerId; }
void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry);
......@@ -166,9 +163,9 @@ private:
bool m_smooth;
bool m_intentionalDraw;
bool m_bookmarked;
bool m_isThumbnail;
QWeakPointer<DocumentItem> m_documentItem;
QTimer *m_redrawTimer;
int m_observerId;
QWeakPointer <QDeclarativeItem> m_flickable;
Okular::DocumentViewport m_viewPort;
};
......
......@@ -25,11 +25,11 @@
using namespace Okular;
#define foreachObserver( cmd ) {\
QMap< int, DocumentObserver * >::const_iterator it = d->document->m_observers.constBegin(), end = d->document->m_observers.constEnd();\
QSet< DocumentObserver * >::const_iterator it = d->document->m_observers.constBegin(), end = d->document->m_observers.constEnd();\
for ( ; it != end ; ++ it ) { (*it)-> cmd ; } }
#define foreachObserverD( cmd ) {\
QMap< int, DocumentObserver * >::const_iterator it = document->m_observers.constBegin(), end = document->m_observers.constEnd();\
QSet< DocumentObserver * >::const_iterator it = document->m_observers.constBegin(), end = document->m_observers.constEnd();\
for ( ; it != end ; ++ it ) { (*it)-> cmd ; } }
class OkularBookmarkAction : public KBookmarkAction
......
This diff is collapsed.
......@@ -30,6 +30,7 @@ class KBookmark;
class KConfigDialog;
class KXMLGUIClient;
class KUrl;
class DocumentItem;
namespace Okular {
......@@ -181,7 +182,7 @@ class OKULAR_EXPORT Document : public QObject
* Sets the list of visible page rectangles.
* @see VisiblePageRect
*/
void setVisiblePageRects( const QVector< VisiblePageRect * > & visiblePageRects, int excludeId = -1 );
void setVisiblePageRects( const QVector< VisiblePageRect * > & visiblePageRects, DocumentObserver *excludeObserver = 0 );
/**
* Returns the list of visible page rectangles.
......@@ -295,18 +296,18 @@ class OKULAR_EXPORT Document : public QObject
/**
* Sets the current document viewport to the given @p page.
*
* @param excludeId The observer ids which shouldn't be effected by this change.
* @param excludeObserver The observer ids which shouldn't be effected by this change.
* @param smoothMove Whether the move shall be animated smoothly.
*/
void setViewportPage( int page, int excludeId = -1, bool smoothMove = false );
void setViewportPage( int page, DocumentObserver *excludeObserver = 0, bool smoothMove = false );
/**
* Sets the current document viewport to the given @p viewport.
*
* @param excludeId The observer ids which shouldn't be effected by this change.
* @param excludeObserver The observer which shouldn't be effected by this change.
* @param smoothMove Whether the move shall be animated smoothly.
*/
void setViewport( const DocumentViewport &viewport, int excludeId = -1, bool smoothMove = false );
void setViewport( const DocumentViewport &viewport, DocumentObserver *excludeObserver = 0, bool smoothMove = false );
/**
* Sets the current document viewport to the next viewport in the
......@@ -334,10 +335,8 @@ class OKULAR_EXPORT Document : public QObject
/**
* Sets the zoom for the current document.
*
* @param excludeId The observer ids which shouldn't be effected by this change.
*/
void setZoom( int factor, int excludeId = -1 );
void setZoom( int factor, DocumentObserver *excludeObserver = 0 );
/**
* Describes the possible options for the pixmap requests.
......@@ -819,6 +818,8 @@ class OKULAR_EXPORT Document : public QObject
private:
/// @cond PRIVATE
friend class DocumentPrivate;
friend class Part;
friend class ::DocumentItem;
/// @endcond
DocumentPrivate *const d;
......
......@@ -114,7 +114,7 @@ class DocumentPrivate
qulonglong calculateMemoryToFree();
void cleanupPixmapMemory();
void cleanupPixmapMemory( qulonglong memoryToFree );
AllocatedPixmap * searchLowestPriorityPixmap( bool unloadableOnly = false, bool thenRemoveIt = false, int observerId = -1 /* any */ );
AllocatedPixmap * searchLowestPriorityPixmap( bool unloadableOnly = false, bool thenRemoveIt = false, DocumentObserver *observer = 0 /* any */ );
void calculateMaxTextPages();
qulonglong getTotalMemory();
qulonglong getFreeMemory( qulonglong *freeSwap = 0 );
......@@ -200,7 +200,10 @@ class DocumentPrivate
QString m_nextDocumentDestination;
// observers / requests / allocator stuff
QMap< int, DocumentObserver * > m_observers;
QSet< DocumentObserver * > m_observers;
// FIXME This is a hack, we need to support
// multiple tiled observers, but for the moment we only support one
DocumentObserver *m_tiledObserver;
QLinkedList< PixmapRequest * > m_pixmapRequestsStack;
QLinkedList< PixmapRequest * > m_executingPixmapRequests;
QMutex m_pixmapRequestsMutex;
......
......@@ -100,7 +100,7 @@ void GeneratorPrivate::pixmapGenerationFinished()
}
const QImage& img = mPixmapGenerationThread->image();
request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( img ) ), request->normalizedRect() );
request->page()->setPixmap( request->observer(), new QPixmap( QPixmap::fromImage( img ) ), request->normalizedRect() );
const int pageNumber = request->page()->number();
if ( mPixmapGenerationThread->calcBoundingBox() )
......@@ -238,7 +238,7 @@ void Generator::generatePixmap( PixmapRequest *request )
}
const QImage& img = image( request );
request->page()->setPixmap( request->id(), new QPixmap( QPixmap::fromImage( img ) ), request->normalizedRect() );
request->page()->setPixmap( request->observer(), new QPixmap( QPixmap::fromImage( img ) ), request->normalizedRect() );
const int pageNumber = request->page()->number();
d->mPixmapReady = true;
......@@ -422,15 +422,15 @@ const SourceReference * Generator::dynamicSourceReference( int /*pageNr*/, doubl
return 0;
}
PixmapRequest::PixmapRequest( int id, int pageNumber, int width, int height, int priority, bool asynchronous )
PixmapRequest::PixmapRequest( DocumentObserver *observer, int pageNumber, int width, int height, int priority, PixmapRequestFeatures features )
: d( new PixmapRequestPrivate )
{
d->mId = id;
d->mObserver = observer;
d->mPageNumber = pageNumber;
d->mWidth = width;
d->mHeight = height;
d->mPriority = priority;
d->mAsynchronous = asynchronous;
d->mFeatures = features;
d->mForce = false;
d->mTile = false;
d->mNormalizedRect = NormalizedRect();
......@@ -441,9 +441,9 @@ PixmapRequest::~PixmapRequest()
delete d;
}
int PixmapRequest::id() const
DocumentObserver *PixmapRequest::observer() const
{
return d->mId;
return d->mObserver;
}
int PixmapRequest::pageNumber() const
......@@ -468,7 +468,12 @@ int PixmapRequest::priority() const
bool PixmapRequest::asynchronous() const
{
return d->mAsynchronous;
return d->mFeatures & Asynchronous;
}
bool PixmapRequest::preload() const
{
return d->mFeatures & Preload;
}
Page* PixmapRequest::page() const
......@@ -504,19 +509,6 @@ void PixmapRequestPrivate::swap()
qSwap( mWidth, mHeight );
}
bool PixmapRequestPrivate::isPreload() const
{
switch ( mPriority )
{
case PAGEVIEW_PRELOAD_PRIO:
case THUMBNAILS_PRELOAD_PRIO:
case PRESENTATION_PRELOAD_PRIO:
return true;
default:
return false;
}
}
class Okular::ExportFormatPrivate : public QSharedData
{
public:
......@@ -624,7 +616,7 @@ QDebug operator<<( QDebug str, const Okular::PixmapRequest &req )
{
QString s = QString( "PixmapRequest(#%2, %1, %3x%4, page %6, prio %5)" )
.arg( QString( req.asynchronous() ? "async" : "sync" ) )
.arg( req.id() )
.arg( (qulonglong)req.observer() )
.arg( req.width() )
.arg( req.height() )
.arg( req.priority() )
......
......@@ -42,6 +42,7 @@ namespace Okular {
class Document;
class DocumentFonts;
class DocumentInfo;
class DocumentObserver;
class DocumentSynopsis;
class EmbeddedFile;
class ExportFormatPrivate;
......@@ -523,17 +524,25 @@ class OKULAR_EXPORT PixmapRequest
friend class DocumentPrivate;
public:
enum PixmapRequestFeature
{
NoFeature = 0,
Asynchronous = 1,
Preload = 2
};
Q_DECLARE_FLAGS( PixmapRequestFeatures, PixmapRequestFeature )
/**
* Creates a new pixmap request.
*
* @param id The observer id.
* @param observer The observer.
* @param pageNumber The page number.
* @param width The width of the page.
* @param height The height of the page.
* @param priority The priority of the request.
* @param asynchronous The mode of generation.
* @param features The features of generation.
*/
PixmapRequest( int id, int pageNumber, int width, int height, int priority, bool asynchronous );
PixmapRequest( DocumentObserver *observer, int pageNumber, int width, int height, int priority, PixmapRequestFeatures features );
/**
* Destroys the pixmap request.
......@@ -541,9 +550,9 @@ class OKULAR_EXPORT PixmapRequest
~PixmapRequest();
/**
* Returns the observer id of the request.
* Returns the observer of the request.
*/
int id() const;
DocumentObserver *observer() const;
/**
* Returns the page number of the request.
......@@ -575,6 +584,12 @@ class OKULAR_EXPORT PixmapRequest
*/
bool asynchronous() const;
/**
* Returns whether the generation request is for a page that is not important
* i.e. it's just for speeding up future rendering
*/
bool preload() const;
/**
* Returns a pointer to the page where the pixmap shall be generated for.
*/
......
......@@ -21,6 +21,7 @@ class QMutex;
namespace Okular {
class DocumentObserver;
class DocumentPrivate;
class FontInfo;
class Generator;
......@@ -70,14 +71,13 @@ class PixmapRequestPrivate
{
public:
void swap();
bool isPreload() const;
int mId;
DocumentObserver *mObserver;
int mPageNumber;
int mWidth;
int mHeight;
int mPriority;
bool mAsynchronous : 1;
int mFeatures;
bool mForce : 1;
bool mTile : 1;
Page *mPage;
......
......@@ -17,30 +17,6 @@
namespace Okular {
/** IDs for observers. Globally defined here. **/
#define PRESENTATION_ID 1
#define PART_ID 2
#define PAGEVIEW_ID 3
#define THUMBNAILS_ID 4
#define TOC_ID 5
#define MINIBAR_ID 6
#define REVIEWS_ID 7
#define PROGRESSWIDGET_ID 8
#define PAGESIZELABEL_ID 9
#define BOOKMARKLIST_ID 10
#define ANNOTATIONMODEL_ID 11
// the biggest id, useful for ignoring wrong id request
#define MAX_OBSERVER_ID 12
/** PRIORITIES for requests. Globally defined here. **/
#define PAGEVIEW_PRIO 1
#define PAGEVIEW_PRELOAD_PRIO 4
#define THUMBNAILS_PRIO 2
#define THUMBNAILS_PRELOAD_PRIO 5
#define PRESENTATION_PRIO 0
#define PRESENTATION_PRELOAD_PRIO 3
class Page;
/**
......@@ -58,11 +34,6 @@ class OKULAR_EXPORT DocumentObserver
*/
virtual ~DocumentObserver();
/**
* Must return an unique ID for each observer (used for notifications).
*/
virtual uint observerId() const = 0;
/**
* Flags that can be sent from the document to all observers to
* inform them about the type of object that has been changed.
......
......@@ -90,7 +90,7 @@ PagePrivate::~PagePrivate()
void PagePrivate::imageRotationDone( RotationJob * job )
{
TilesManager *tm = ( job->id() == PAGEVIEW_ID ) ? m_tilesManager : 0;
TilesManager *tm = ( job->observer() == m_doc->m_tiledObserver ) ? m_tilesManager : 0;
if ( tm )
{
QPixmap *pixmap = new QPixmap( QPixmap::fromImage( job->image() ) );
......@@ -99,7 +99,7 @@ void PagePrivate::imageRotationDone( RotationJob * job )
return;
}
QMap< int, PixmapObject >::iterator it = m_pixmaps.find( job->id() );
QMap< DocumentObserver*, PixmapObject >::iterator it = m_pixmaps.find( job->observer() );
if ( it != m_pixmaps.end() )
{
PixmapObject &object = it.value();
......@@ -110,7 +110,7 @@ void PagePrivate::imageRotationDone( RotationJob * job )
object.m_pixmap = new QPixmap( QPixmap::fromImage( job->image() ) );
object.m_rotation = job->rotation();
m_pixmaps.insert( job->id(), object );
m_pixmaps.insert( job->observer(), object );
}
}
......@@ -213,9 +213,9 @@ void Page::setBoundingBox( const NormalizedRect& bbox )
d->m_isBoundingBoxKnown = true;
}
bool Page::hasPixmap( int id, int width, int height, const NormalizedRect &rect ) const
bool Page::hasPixmap( DocumentObserver *observer, int width, int height, const NormalizedRect &rect ) const
{
TilesManager *tm = ( id == PAGEVIEW_ID ) ? d->m_tilesManager : 0;
TilesManager *tm = ( observer == d->m_doc->m_tiledObserver ) ? d->m_tilesManager : 0;
if ( tm )
{
if ( width != tm->width() || height != tm->height() )
......@@ -227,7 +227,7 @@ bool Page::hasPixmap( int id, int width, int height, const NormalizedRect &rect
return tm->hasPixmap( rect );
}
QMap< int, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.constFind( id );
QMap< DocumentObserver*, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.constFind( observer );
if ( it == d->m_pixmaps.constEnd() )
return false;
......@@ -379,7 +379,7 @@ void PagePrivate::rotateAt( Rotation orientation )
/**
* Rotate the images of the page.
*/
QMapIterator< int, PagePrivate::PixmapObject > it( m_pixmaps );
QMapIterator< DocumentObserver*, PagePrivate::PixmapObject > it( m_pixmaps );
while ( it.hasNext() ) {
it.next();
......@@ -502,10 +502,10 @@ QLinkedList< FormField * > Page::formFields() const
return d->formfields;
}
void Page::setPixmap( int id, QPixmap *pixmap, const NormalizedRect &rect )
void Page::setPixmap( DocumentObserver *observer, QPixmap *pixmap, const NormalizedRect &rect )
{
if ( d->m_rotation == Rotation0 ) {
TilesManager *tm = ( id == PAGEVIEW_ID ) ? d->m_tilesManager : 0;
TilesManager *tm = ( observer == d->m_doc->m_tiledObserver ) ? d->m_tilesManager : 0;
if ( tm )
{
tm->setPixmap( pixmap, rect );
......@@ -513,19 +513,19 @@ void Page::setPixmap( int id, QPixmap *pixmap, const NormalizedRect &rect )
return;
}
QMap< int, PagePrivate::PixmapObject >::iterator it = d->m_pixmaps.find( id );
QMap< DocumentObserver*, PagePrivate::PixmapObject >::iterator it = d->m_pixmaps.find( observer );
if ( it != d->m_pixmaps.end() )
{
delete it.value().m_pixmap;
}
else
{
it = d->m_pixmaps.insert( id, PagePrivate::PixmapObject() );
it = d->m_pixmaps.insert( observer, PagePrivate::PixmapObject() );
}
it.value().m_pixmap = pixmap;
it.value().m_rotation = d->m_rotation;
} else {
RotationJob *job = new RotationJob( pixmap->toImage(), Rotation0, d->m_rotation, id );
RotationJob *job = new RotationJob( pixmap->toImage(), Rotation0, d->m_rotation, observer );
job->setPage( d );
job->setRect( TilesManager::toRotatedRect( rect, d->m_rotation ) );
PageController::self()->addRotationJob(job);
......@@ -708,23 +708,23 @@ void Page::setFormFields( const QLinkedList< FormField * >& fields )
}
}
void Page::deletePixmap( int id )
void Page::deletePixmap( DocumentObserver *observer )
{
if ( id == PAGEVIEW_ID && d->m_tilesManager )
if ( observer == d->m_doc->m_tiledObserver && d->m_tilesManager )
{
delete d->m_tilesManager;
d->m_tilesManager = 0;
}
else
{
PagePrivate::PixmapObject object = d->m_pixmaps.take( id );
PagePrivate::PixmapObject object = d->m_pixmaps.take( observer );
delete object.m_pixmap;
}
}
void Page::deletePixmaps()
{
QMapIterator< int, PagePrivate::PixmapObject > it( d->m_pixmaps );
QMapIterator< DocumentObserver*, PagePrivate::PixmapObject > it( d->m_pixmaps );
while ( it.hasNext() ) {
it.next();
delete it.value().m_pixmap;
......@@ -957,21 +957,21 @@ void PagePrivate::saveLocalContents( QDomNode & parentNode, QDomDocument & docum
parentNode.appendChild( pageElement );
}
const QPixmap * Page::_o_nearestPixmap( int pixID, int w, int h ) const
const QPixmap * Page::_o_nearestPixmap( DocumentObserver *observer, 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.constFind( pixID );
QMap< DocumentObserver*, PagePrivate::PixmapObject >::const_iterator itPixmap = d->m_pixmaps.constFind( observer );
if ( itPixmap != d->m_pixmaps.constEnd() )
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.constBegin(), end = d->m_pixmaps.constEnd();
QMap< DocumentObserver*, PagePrivate::PixmapObject >::const_iterator it = d->m_pixmaps.constBegin(), end = d->m_pixmaps.constEnd();
for ( ; it != end; ++it )
{
int pixWidth = (*it).m_pixmap->width(),
......
......@@ -25,6 +25,7 @@ namespace Okular {
class Annotation;
class Document;
class DocumentObserver;
class DocumentPrivate;
class FormField;
class PagePrivate;
......@@ -138,9 +139,9 @@ class OKULAR_EXPORT Page
/**
* Returns whether the page of size @p width x @p height has a @p pixmap
* in the region given by @rect for the observer with given @p id.
* in the region given by @p rect for the given @p observer
*/
bool hasPixmap( int id, int width = -1, int height = -1, const NormalizedRect &rect = NormalizedRect() ) const;
bool hasPixmap( DocumentObserver *observer, int width = -1, int height = -1, const NormalizedRect &rect = NormalizedRect() ) const;
/**
* Returns whether the page provides a text page (@ref TextPage).
......@@ -260,12 +261,12 @@ class OKULAR_EXPORT Page
QLinkedList< FormField * > formFields() const;
/**
* Sets the region described by @p rect with @p pixmap for the observer
* with the given @p id.
* Sets the region described by @p rect with @p pixmap for the
* given @p observer.
* If @p rect is not set (default) the @p pixmap is set to the entire
* page.
*/
void setPixmap( int id, QPixmap *pixmap, const NormalizedRect &rect = NormalizedRect() );
void setPixmap( DocumentObserver *observer, QPixmap *pixmap, const NormalizedRect &rect = NormalizedRect() );
/**
* Sets the @p text page.
......@@ -343,9 +344,9 @@ class OKULAR_EXPORT Page
void setFormFields( const QLinkedList< FormField * >& fields );
/**
* Deletes the pixmap for the observer with the given @p id.
* Deletes the pixmap for the given @p observer
*/
void deletePixmap( int id );
void deletePixmap( DocumentObserver *observer );
/**
* Deletes all pixmaps of the page.
......@@ -368,7 +369,7 @@ class OKULAR_EXPORT Page
void deleteAnnotations();
/**
* Returns whether pixmaps for the PAGEVIEW_ID observer are handled by a
* Returns whether pixmaps for the tiled observer are handled by a
* tile manager.
*
* @since 0.16 (KDE 4.10)
......@@ -398,7 +399,7 @@ class OKULAR_EXPORT Page
friend class ::PagePainter;
/// @endcond
const QPixmap * _o_nearestPixmap( int, int, int ) const;
const QPixmap * _o_nearestPixmap( DocumentObserver *, int, int ) const;
QLinkedList< ObjectRect* > m_rects;