Change the DocumentObserver::notifySetup() to allow a better tuning of the different setup options (different layout for the pages, or different document).

svn path=/trunk/KDE/kdegraphics/okular/; revision=710227
This commit is contained in:
Pino Toscano 2007-09-09 10:50:36 +00:00
parent 928a7be1e9
commit b56ad8c3ae
22 changed files with 51 additions and 41 deletions

View file

@ -973,7 +973,7 @@ void DocumentPrivate::doContinueAllDocumentSearch(void *pagesToNotifySet, void *
}
foreach(DocumentObserver *observer, m_observers)
observer->notifySetup( m_pagesVector, false );
observer->notifySetup( m_pagesVector, 0 );
// notify observers about highlights changes
foreach(int pageNumber, *pagesToNotify)
@ -1091,7 +1091,7 @@ void DocumentPrivate::doContinueGooglesDocumentSearch(void *pagesToNotifySet, vo
// send page lists to update observers (since some filter on bookmarks)
foreach(DocumentObserver *observer, m_observers)
observer->notifySetup( m_pagesVector, false );
observer->notifySetup( m_pagesVector, 0 );
// notify observers about highlights changes
foreach(int pageNumber, *pagesToNotify)
@ -1304,7 +1304,7 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi
d->m_bookmarkManager->setUrl( d->m_url );
// 3. setup observers inernal lists and data
foreachObserver( notifySetup( d->m_pagesVector, true ) );
foreachObserver( notifySetup( d->m_pagesVector, DocumentObserver::DocumentChanged ) );
// 4. set initial page (restoring the page saved in xml if loaded)
DocumentViewport loadedViewport = (*d->m_viewportIterator);
@ -1417,7 +1417,7 @@ void Document::closeDocument()
d->m_pixmapRequestsMutex.unlock();
// send an empty list to observers (to free their data)
foreachObserver( notifySetup( QVector< Page * >(), true ) );
foreachObserver( notifySetup( QVector< Page * >(), DocumentObserver::DocumentChanged ) );
// delete pages and clear 'd->m_pagesVector' container
QVector< Page * >::const_iterator pIt = d->m_pagesVector.begin();
@ -1467,7 +1467,7 @@ void Document::addObserver( DocumentObserver * pObserver )
// if the observer is added while a document is already opened, tell it
if ( !d->m_pagesVector.isEmpty() )
{
pObserver->notifySetup( d->m_pagesVector, true );
pObserver->notifySetup( d->m_pagesVector, DocumentObserver::DocumentChanged );
pObserver->notifyViewportChanged( false /*disables smoothMove*/ );
}
}
@ -2235,7 +2235,7 @@ void Document::resetSearch( int searchID )
}
// send the setup signal too (to update views that filter on matches)
foreachObserver( notifySetup( d->m_pagesVector, false ) );
foreachObserver( notifySetup( d->m_pagesVector, 0 ) );
// remove serch from the runningSearches list and delete it
d->m_searches.erase( searchIt );
@ -2651,7 +2651,7 @@ void Document::setRotation( int r )
// set the new rotation
d->m_rotation = rotation;
foreachObserver( notifySetup( d->m_pagesVector, true ) );
foreachObserver( notifySetup( d->m_pagesVector, DocumentObserver::NewLayoutForPages ) );
foreachObserver( notifyContentsCleared (DocumentObserver::Pixmap | DocumentObserver::Highlights | DocumentObserver::Annotations));
kDebug(OkularDebug) << "Rotated:" << r;
}
@ -2684,7 +2684,7 @@ void Document::setPageSize( const PageSize &size )
// set the new page size
d->m_pageSize = size;
foreachObserver( notifySetup( d->m_pagesVector, true ) );
foreachObserver( notifySetup( d->m_pagesVector, DocumentObserver::NewLayoutForPages ) );
foreachObserver( notifyContentsCleared( DocumentObserver::Pixmap | DocumentObserver::Highlights ) );
kDebug(OkularDebug) << "New PageSize id:" << sizeid;
}

View file

@ -20,7 +20,7 @@ DocumentObserver::~DocumentObserver()
{
}
void DocumentObserver::notifySetup( const QVector< Okular::Page * >&, bool )
void DocumentObserver::notifySetup( const QVector< Okular::Page * >&, int )
{
}

View file

@ -75,13 +75,21 @@ class OKULAR_EXPORT DocumentObserver
Annotations = 16 ///< Annotations has been changed
};
/**
* ...
*/
enum SetupFlags {
DocumentChanged = 1, ///< The document is a new document.
NewLayoutForPages = 2 ///< All the pages have
};
/**
* This method is called whenever the document is initialized or reconstructed.
*
* @param pages The vector of pages of the document.
* @param documentChanged If true, the document is reconstructed.
* @param setupFlags the flags with the information about the setup
*/
virtual void notifySetup( const QVector< Okular::Page * > &pages, bool documentChanged );
virtual void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
/**
* This method is called whenever the viewport has been changed.

View file

@ -606,9 +606,9 @@ void Part::slotGeneratorPreferences( )
}
void Part::notifySetup( const QVector< Okular::Page * > & /*pages*/, bool documentChanged )
void Part::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFlags )
{
if ( !documentChanged )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
rebuildBookmarkMenu();

2
part.h
View file

@ -83,7 +83,7 @@ class Part : public KParts::ReadOnlyPart, public Okular::DocumentObserver, publi
// inherited from DocumentObserver
uint observerId() const { return PART_ID; }
void notifySetup( const QVector< Okular::Page * > &pages, bool documentChanged );
void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
void notifyPageChanged( int page, int flags );

View file

@ -42,7 +42,7 @@ public:
virtual ~AnnotationModelPrivate();
virtual uint observerId() const;
virtual void notifySetup( const QVector< Okular::Page * > &pages, bool documentChanged );
virtual void notifySetup( const QVector< Okular::Page * > &pages, int setupFlags );
virtual void notifyPageChanged( int page, int flags );
QModelIndex indexForItem( AnnItem *item ) const;
@ -95,9 +95,9 @@ uint AnnotationModelPrivate::observerId() const
return ANNOTATIONMODEL_ID;
}
void AnnotationModelPrivate::notifySetup( const QVector< Okular::Page * > &pages, bool documentChanged )
void AnnotationModelPrivate::notifySetup( const QVector< Okular::Page * > &pages, int setupFlags )
{
if ( !documentChanged )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
qDeleteAll( root->children );

View file

@ -121,9 +121,9 @@ uint BookmarkList::observerId() const
return BOOKMARKLIST_ID;
}
void BookmarkList::notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged )
void BookmarkList::notifySetup( const QVector< Okular::Page * > & pages, int setupFlags )
{
if ( !documentChanged )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
// clear contents

View file

@ -34,7 +34,7 @@ class BookmarkList : public QWidget, public Okular::DocumentObserver
// inherited from DocumentObserver
uint observerId() const;
void notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyPageChanged( int pageNumber, int changedFlags );
private slots:

View file

@ -133,10 +133,10 @@ MiniBar::~MiniBar()
m_document->removeObserver( this );
}
void MiniBar::notifySetup( const QVector< Okular::Page * > & pageVector, bool changed )
void MiniBar::notifySetup( const QVector< Okular::Page * > & pageVector, int setupFlags )
{
// only process data when document changes
if ( !changed )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
// if document is closed or has no pages, hide widget

View file

@ -33,7 +33,7 @@ class MiniBar : public QWidget, public Okular::DocumentObserver
// [INHERITED] from DocumentObserver
uint observerId() const { return MINIBAR_ID; }
void notifySetup( const QVector< Okular::Page * > & pages, bool );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
signals:

View file

@ -32,10 +32,10 @@ QWidget *PageSizeLabel::antiWidget()
return m_antiWidget;
}
void PageSizeLabel::notifySetup( const QVector< Okular::Page * > & pageVector, bool changed )
void PageSizeLabel::notifySetup( const QVector< Okular::Page * > & pageVector, int setupFlags )
{
// only process data when document changes
if ( !changed )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
// if document is closed or all pages have size hide widget

View file

@ -33,7 +33,7 @@ class PageSizeLabel : public QLabel, public Okular::DocumentObserver
// [INHERITED] from DocumentObserver
uint observerId() const { return PAGESIZELABEL_ID; }
void notifySetup( const QVector< Okular::Page * > & pages, bool );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
private:

View file

@ -631,10 +631,11 @@ void PageView::selectAll()
}
//BEGIN DocumentObserver inherited methods
void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, bool documentChanged )
void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, int setupFlags )
{
bool documentChanged = setupFlags & Okular::DocumentObserver::DocumentChanged;
// reuse current pages if nothing new
if ( ( pageSet.count() == d->items.count() ) && !documentChanged )
if ( ( pageSet.count() == d->items.count() ) && !documentChanged && !( setupFlags & Okular::DocumentObserver::NewLayoutForPages ) )
{
int count = pageSet.count();
for ( int i = 0; (i < count) && !documentChanged; i++ )

View file

@ -70,7 +70,7 @@ Q_OBJECT
// inherited from DocumentObserver
uint observerId() const { return PAGEVIEW_ID; }
void notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
void notifyPageChanged( int pageNumber, int changedFlags );
void notifyContentsCleared( int changedFlags );

View file

@ -157,11 +157,11 @@ PresentationWidget::~PresentationWidget()
}
void PresentationWidget::notifySetup( const QVector< Okular::Page * > & pageSet, bool documentChanged )
void PresentationWidget::notifySetup( const QVector< Okular::Page * > & pageSet, int setupFlags )
{
// same document, nothing to change - here we assume the document sets up
// us with the whole document set as first notifySetup()
if ( !documentChanged )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
// delete previous frames (if any (shouldn't be))

View file

@ -46,7 +46,7 @@ class PresentationWidget : public QDialog, public Okular::DocumentObserver
// inherited from DocumentObserver
uint observerId() const { return PRESENTATION_ID; }
void notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
void notifyPageChanged( int pageNumber, int changedFlags );
bool canUnloadPixmap( int pageNumber ) const;

View file

@ -30,6 +30,7 @@
#include "settings.h"
#include "annotationguiutils.h"
#include "annotationpopup.h"
#include <kdebug.h>
static const int AuthorRole = Qt::UserRole + 100;
@ -98,10 +99,10 @@ Reviews::Reviews( QWidget * parent, Okular::Document * document )
}
//BEGIN DocumentObserver Notifies -> requestListViewUpdate
void Reviews::notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged )
void Reviews::notifySetup( const QVector< Okular::Page * > & pages, int setupFlags )
{
// grab the page array when document changes
if ( documentChanged )
if ( setupFlags & Okular::DocumentObserver::DocumentChanged )
{
m_currentPage = -1;
m_pages = pages;

View file

@ -37,7 +37,7 @@ class Reviews : public QWidget, public Okular::DocumentObserver
// [INHERITED] from DocumentObserver
uint observerId() const { return REVIEWS_ID; }
void notifySetup( const QVector< Okular::Page * > & pages, bool );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
void notifyPageChanged( int pageNumber, int changedFlags );

View file

@ -118,12 +118,12 @@ ThumbnailList::~ThumbnailList()
}
//BEGIN DocumentObserver inherited methods
void ThumbnailList::notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged )
void ThumbnailList::notifySetup( const QVector< Okular::Page * > & pages, int setupFlags )
{
// if there was a widget selected, save its pagenumber to restore
// its selection (if available in the new set of pages)
int prevPage = -1;
if ( !documentChanged && m_selected )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) && m_selected )
{
prevPage = m_selected->page()->number();
}

View file

@ -41,7 +41,7 @@ Q_OBJECT
// inherited: return thumbnails observer id
uint observerId() const { return THUMBNAILS_ID; }
// inherited: create thumbnails ( inherited as a DocumentObserver )
void notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
// inherited: hilihght current thumbnail ( inherited as DocumentObserver )
void notifyViewportChanged( bool smoothMove );
// inherited: redraw thumbnail ( inherited as DocumentObserver )

View file

@ -124,9 +124,9 @@ uint TOC::observerId() const
return TOC_ID;
}
void TOC::notifySetup( const QVector< Okular::Page * > & /*pages*/, bool documentChanged )
void TOC::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFlags )
{
if ( !documentChanged )
if ( !( setupFlags & Okular::DocumentObserver::DocumentChanged ) )
return;
// clear contents

View file

@ -32,7 +32,7 @@ Q_OBJECT
// inherited from DocumentObserver
uint observerId() const;
void notifySetup( const QVector< Okular::Page * > & pages, bool documentChanged );
void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags );
void notifyViewportChanged( bool smoothMove );
void reparseConfig();