From d3e0dadcacd3f11bb536968b5ebccf8377513f27 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Thu, 16 Aug 2012 17:37:39 +0200 Subject: [PATCH] Introduce notifyCurrentPageChanged callback DocumentObserver interface --- CMakeLists.txt | 2 +- core/document.cpp | 11 ++++ core/observer.cpp | 4 ++ core/observer.h | 10 +++ ui/minibar.cpp | 36 +++++------ ui/minibar.h | 6 +- ui/pagesizelabel.cpp | 19 +++--- ui/pagesizelabel.h | 3 +- ui/presentationwidget.cpp | 126 +++++++++++++++++++++----------------- ui/presentationwidget.h | 2 + ui/side_reviews.cpp | 6 +- ui/side_reviews.h | 2 +- ui/thumbnaillist.cpp | 9 +-- ui/thumbnaillist.h | 2 +- ui/toc.cpp | 11 +--- ui/toc.h | 3 +- 16 files changed, 139 insertions(+), 113 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31d0da594..e75f76832 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,7 +120,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 1.9.0 SOVERSION 1 ) +set_target_properties(okularcore PROPERTIES VERSION 2.0.0 SOVERSION 1 ) install(TARGETS okularcore ${INSTALL_TARGETS_DEFAULT_ARGS} ) diff --git a/core/document.cpp b/core/document.cpp index f6bf699a7..9d6b25c64 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -2788,6 +2788,8 @@ void Document::setViewport( const DocumentViewport & viewport, int excludeId, bo //if ( viewport == oldViewport ) // kDebug(OkularDebug) << "setViewport with the same viewport."; + const int oldPageNumber = oldViewport.pageNumber; + // set internal viewport taking care of history if ( oldViewport.pageNumber == viewport.pageNumber || !oldViewport.isValid() ) { @@ -2807,11 +2809,20 @@ void Document::setViewport( const DocumentViewport & viewport, int excludeId, bo d->m_viewportIterator = d->m_viewportHistory.insert( d->m_viewportHistory.end(), viewport ); } + const int currentViewportPage = (*d->m_viewportIterator).pageNumber; + + const bool currentPageChanged = (oldPageNumber != currentViewportPage); + // notify change to all other (different from id) observers QMap< int, DocumentObserver * >::const_iterator it = d->m_observers.constBegin(), end = d->m_observers.constEnd(); for ( ; it != end ; ++ it ) + { if ( it.key() != excludeId ) (*it)->notifyViewportChanged( smoothMove ); + + if ( currentPageChanged ) + (*it)->notifyCurrentPageChanged( oldPageNumber, currentViewportPage ); + } } void Document::setZoom(int factor, int excludeId) diff --git a/core/observer.cpp b/core/observer.cpp index 0201a1d8c..59bbb1163 100644 --- a/core/observer.cpp +++ b/core/observer.cpp @@ -48,3 +48,7 @@ bool DocumentObserver::canUnloadPixmap( int ) const { return true; } + +void DocumentObserver::notifyCurrentPageChanged( int, int ) +{ +} diff --git a/core/observer.h b/core/observer.h index 76c096c2a..f7189beac 100644 --- a/core/observer.h +++ b/core/observer.h @@ -130,6 +130,16 @@ class OKULAR_EXPORT DocumentObserver */ virtual bool canUnloadPixmap( int page ) const; + /** + * This method is called after the current page of the document has been entered. + * + * @param previous The number of the previous page (is @c -1 for the initial page change). + * @param current The number of the current page. + * + * @since 0.16 (KDE 4.10) + */ + virtual void notifyCurrentPageChanged( int previous, int current ); + private: class Private; const Private* d; diff --git a/ui/minibar.cpp b/ui/minibar.cpp index 051df720e..b9e12916d 100644 --- a/ui/minibar.cpp +++ b/ui/minibar.cpp @@ -42,7 +42,6 @@ class HoverButton : public QToolButton MiniBarLogic::MiniBarLogic( QObject * parent, Okular::Document * document ) : QObject(parent) , m_document( document ) - , m_currentPage( -1 ) { } @@ -68,7 +67,7 @@ Okular::Document *MiniBarLogic::document() const int MiniBarLogic::currentPage() const { - return m_currentPage; + return m_document->currentPage(); } void MiniBarLogic::notifySetup( const QVector< Okular::Page * > & pageVector, int setupFlags ) @@ -81,7 +80,6 @@ void MiniBarLogic::notifySetup( const QVector< Okular::Page * > & pageVector, in const int pages = pageVector.count(); if ( pages < 1 ) { - m_currentPage = -1; foreach ( MiniBar *miniBar, m_miniBars ) { miniBar->setEnabled( false ); @@ -124,24 +122,24 @@ void MiniBarLogic::notifySetup( const QVector< Okular::Page * > & pageVector, in } } -void MiniBarLogic::notifyViewportChanged( bool /*smoothMove*/ ) +void MiniBarLogic::notifyCurrentPageChanged( int previousPage, int currentPage ) { + Q_UNUSED( previousPage ) + // get current page number - const int page = m_document->viewport().pageNumber; const int pages = m_document->pages(); // if the document is opened and page is changed - if ( page != m_currentPage && pages > 0 ) + if ( pages > 0 ) { - m_currentPage = page; - const QString pageNumber = QString::number( page + 1 ); - const QString pageLabel = m_document->page(page)->label(); - + const QString pageNumber = QString::number( currentPage + 1 ); + const QString pageLabel = m_document->page( currentPage )->label(); + foreach ( MiniBar *miniBar, m_miniBars ) { // update prev/next button state - miniBar->m_prevButton->setEnabled( page > 0 ); - miniBar->m_nextButton->setEnabled( page < ( pages - 1 ) ); + miniBar->m_prevButton->setEnabled( currentPage > 0 ); + miniBar->m_nextButton->setEnabled( currentPage < ( pages - 1 ) ); // update text on widgets miniBar->m_pageNumberEdit->setText( pageNumber ); miniBar->m_pageNumberLabel->setText( pageNumber ); @@ -292,7 +290,7 @@ void MiniBar::resizeForPage( int pages ) ProgressWidget::ProgressWidget( QWidget * parent, Okular::Document * document ) : QWidget( parent ), m_document( document ), - m_currentPage( -1 ), m_progressPercentage( -1 ) + m_progressPercentage( -1 ) { setObjectName( QLatin1String( "progress" ) ); setAttribute( Qt::WA_OpaquePaintEvent, true ); @@ -305,18 +303,18 @@ ProgressWidget::~ProgressWidget() m_document->removeObserver( this ); } -void ProgressWidget::notifyViewportChanged( bool /*smoothMove*/ ) +void ProgressWidget::notifyCurrentPageChanged( int previousPage, int currentPage ) { + Q_UNUSED( previousPage ) + // get current page number - int page = m_document->viewport().pageNumber; int pages = m_document->pages(); // if the document is opened and page is changed - if ( page != m_currentPage && pages > 0 ) + if ( pages > 0 ) { // update percentage - m_currentPage = page; - float percentage = pages < 2 ? 1.0 : (float)page / (float)(pages - 1); + const float percentage = pages < 2 ? 1.0 : (float)currentPage / (float)(pages - 1); setProgress( percentage ); } } @@ -332,7 +330,7 @@ void ProgressWidget::slotGotoNormalizedPage( float index ) // figure out page number and go to that page int number = (int)( index * (float)m_document->pages() ); if ( number >= 0 && number < (int)m_document->pages() && - number != m_currentPage ) + number != (int)m_document->currentPage() ) m_document->setViewportPage( number ); } diff --git a/ui/minibar.h b/ui/minibar.h index acb1163be..a0c0514d0 100644 --- a/ui/minibar.h +++ b/ui/minibar.h @@ -90,12 +90,11 @@ class MiniBarLogic : public QObject, public Okular::DocumentObserver // [INHERITED] from DocumentObserver uint observerId() const { return MINIBAR_ID; } void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags ); - void notifyViewportChanged( bool smoothMove ); + void notifyCurrentPageChanged( int previous, int current ); private: QSet m_miniBars; Okular::Document * m_document; - int m_currentPage; }; /** @@ -147,7 +146,7 @@ class ProgressWidget : public QWidget, public Okular::DocumentObserver // [INHERITED] from DocumentObserver uint observerId() const { return PROGRESSWIDGET_ID; } - void notifyViewportChanged( bool smoothMove ); + void notifyCurrentPageChanged( int previous, int current ); void slotGotoNormalizedPage( float index ); @@ -165,7 +164,6 @@ class ProgressWidget : public QWidget, public Okular::DocumentObserver private: Okular::Document * m_document; - int m_currentPage; float m_progressPercentage; }; diff --git a/ui/pagesizelabel.cpp b/ui/pagesizelabel.cpp index 4a8077924..aa4a043b8 100644 --- a/ui/pagesizelabel.cpp +++ b/ui/pagesizelabel.cpp @@ -13,7 +13,7 @@ PageSizeLabel::PageSizeLabel( QWidget * parent, Okular::Document * document ) : QLabel( parent ), m_document( document ), - m_currentPage( -1 ), m_antiWidget( NULL ) + m_antiWidget( NULL ) { } @@ -55,20 +55,17 @@ void PageSizeLabel::notifySetup( const QVector< Okular::Page * > & pageVector, i } } -void PageSizeLabel::notifyViewportChanged( bool /*smoothMove*/ ) +void PageSizeLabel::notifyCurrentPageChanged( int previousPage, int currentPage ) { + Q_UNUSED( previousPage ) + if (isVisible()) { - // get current page number - int page = m_document->viewport().pageNumber; - int pages = m_document->pages(); - - // if the document is opened and page is changed - if ( page != m_currentPage && pages > 0 ) + // if the document is opened + if ( m_document->pages() > 0 ) { - m_currentPage = page; - setText( m_document->pageSizeString(page) ); - m_antiWidget->setFixedSize(sizeHint()); + setText( m_document->pageSizeString( currentPage ) ); + m_antiWidget->setFixedSize( sizeHint() ); } } } diff --git a/ui/pagesizelabel.h b/ui/pagesizelabel.h index ea508b87c..7c4a1e2fc 100644 --- a/ui/pagesizelabel.h +++ b/ui/pagesizelabel.h @@ -34,11 +34,10 @@ class PageSizeLabel : public QLabel, public Okular::DocumentObserver // [INHERITED] from DocumentObserver uint observerId() const { return PAGESIZELABEL_ID; } void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags ); - void notifyViewportChanged( bool smoothMove ); + void notifyCurrentPageChanged( int previous, int current ); private: Okular::Document * m_document; - int m_currentPage; QWidget *m_antiWidget; }; diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp index 37523e8cd..6eca796f9 100644 --- a/ui/presentationwidget.cpp +++ b/ui/presentationwidget.cpp @@ -132,7 +132,8 @@ PresentationWidget::PresentationWidget( QWidget * parent, Okular::Document * doc m_pressedLink( 0 ), m_handCursor( false ), m_drawingEngine( 0 ), m_parentWidget( parent ), m_document( doc ), m_frameIndex( -1 ), m_topBar( 0 ), m_pagesEdit( 0 ), m_searchBar( 0 ), - m_screenSelect( 0 ), m_isSetup( false ), m_blockNotifications( false ), m_inBlackScreenMode( false ) + m_screenSelect( 0 ), m_isSetup( false ), m_blockNotifications( false ), m_inBlackScreenMode( false ), + m_showSummaryView( Okular::Settings::slidesShowSummary() ) { Q_UNUSED( parent ) setAttribute( Qt::WA_DeleteOnClose ); @@ -342,10 +343,6 @@ void PresentationWidget::notifySetup( const QVector< Okular::Page * > & pageSet, void PresentationWidget::notifyViewportChanged( bool /*smoothMove*/ ) { - // discard notifications if displaying the summary - if ( m_frameIndex == -1 && Okular::Settings::slidesShowSummary() ) - return; - // display the current page changePage( m_document->viewport().pageNumber ); @@ -364,6 +361,64 @@ void PresentationWidget::notifyPageChanged( int pageNumber, int changedFlags ) generatePage( changedFlags & ( DocumentObserver::Annotations | DocumentObserver::Highlights ) ); } +void PresentationWidget::notifyCurrentPageChanged( int previousPage, int currentPage ) +{ + if ( previousPage != -1 ) + { + // remove the drawings on the old page before switching + clearDrawings(); + + // stop video playback + Q_FOREACH ( VideoWidget *vw, m_frames[ previousPage ]->videoWidgets ) + { + vw->stop(); + vw->pageLeft(); + } + + // stop audio playback, if any + Okular::AudioPlayer::instance()->stopPlaybacks(); + + // perform the page closing action, if any + if ( m_document->page( previousPage )->pageAction( Okular::Page::Closing ) ) + m_document->processAction( m_document->page( previousPage )->pageAction( Okular::Page::Closing ) ); + } + + if ( currentPage != -1 ) + { + m_frameIndex = currentPage; + + // check if pixmap exists or else request it + PresentationFrame * frame = m_frames[ m_frameIndex ]; + int pixW = frame->geometry.width(); + int pixH = frame->geometry.height(); + + bool signalsBlocked = m_pagesEdit->signalsBlocked(); + m_pagesEdit->blockSignals( true ); + m_pagesEdit->setText( QString::number( m_frameIndex + 1 ) ); + m_pagesEdit->blockSignals( signalsBlocked ); + + // if pixmap not inside the Okular::Page we request it and wait for + // notifyPixmapChanged call or else we can proceed to pixmap generation + if ( !frame->page->hasPixmap( PRESENTATION_ID, pixW, pixH ) ) + { + requestPixmaps(); + } + else + { + // make the background pixmap + generatePage(); + } + + // perform the page opening action, if any + if ( m_document->page( m_frameIndex )->pageAction( Okular::Page::Opening ) ) + m_document->processAction( m_document->page( m_frameIndex )->pageAction( Okular::Page::Opening ) ); + + // start autoplay video playback + Q_FOREACH ( VideoWidget *vw, m_frames[ m_frameIndex ]->videoWidgets ) + vw->pageEntered(); + } +} + bool PresentationWidget::canUnloadPixmap( int pageNumber ) const { if ( Okular::Settings::memoryLevel() == Okular::Settings::EnumMemoryLevel::Low || @@ -796,63 +851,20 @@ void PresentationWidget::overlayClick( const QPoint & position ) void PresentationWidget::changePage( int newPage ) { - if ( m_frameIndex == newPage ) + if ( m_showSummaryView ) { + m_showSummaryView = false; + m_frameIndex = -1; return; - - // prepare to leave the current page - if ( m_frameIndex != -1 ) - { - // remove the drawings on the old page before switching - clearDrawings(); - - // stop video playback - Q_FOREACH ( VideoWidget *vw, m_frames[ m_frameIndex ]->videoWidgets ) - { - vw->stop(); - vw->pageLeft(); - } - - // stop audio playback, if any - Okular::AudioPlayer::instance()->stopPlaybacks(); - - // perform the page closing action, if any - if ( m_document->page( m_frameIndex )->pageAction( Okular::Page::Closing ) ) - m_document->processAction( m_document->page( m_frameIndex )->pageAction( Okular::Page::Closing ) ); } - // switch to newPage - m_frameIndex = newPage; - m_document->setViewportPage( m_frameIndex, PRESENTATION_ID ); - - // check if pixmap exists or else request it - PresentationFrame * frame = m_frames[ m_frameIndex ]; - int pixW = frame->geometry.width(); - int pixH = frame->geometry.height(); - - bool signalsBlocked = m_pagesEdit->signalsBlocked(); - m_pagesEdit->blockSignals( true ); - m_pagesEdit->setText( QString::number( m_frameIndex + 1 ) ); - m_pagesEdit->blockSignals( signalsBlocked ); - - // if pixmap not inside the Okular::Page we request it and wait for - // notifyPixmapChanged call or else we can proceed to pixmap generation - if ( !frame->page->hasPixmap( PRESENTATION_ID, pixW, pixH ) ) - { - requestPixmaps(); - } - else - { - // make the background pixmap - generatePage(); - } + if ( m_frameIndex == newPage ) + return; - // perform the page opening action, if any - if ( m_document->page( m_frameIndex )->pageAction( Okular::Page::Opening ) ) - m_document->processAction( m_document->page( m_frameIndex )->pageAction( Okular::Page::Opening ) ); + // switch to newPage + m_document->setViewportPage( newPage, PRESENTATION_ID ); - // start autoplay video playback - Q_FOREACH ( VideoWidget *vw, m_frames[ m_frameIndex ]->videoWidgets ) - vw->pageEntered(); + if ( (Okular::Settings::slidesShowSummary() && !m_showSummaryView) || m_frameIndex == -1 ) + notifyCurrentPageChanged( -1, newPage ); } void PresentationWidget::generatePage( bool disableTransition ) diff --git a/ui/presentationwidget.h b/ui/presentationwidget.h index 20dbcbb8a..f37e6e22b 100644 --- a/ui/presentationwidget.h +++ b/ui/presentationwidget.h @@ -53,6 +53,7 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver void notifyViewportChanged( bool smoothMove ); void notifyPageChanged( int pageNumber, int changedFlags ); bool canUnloadPixmap( int pageNumber ) const; + void notifyCurrentPageChanged( int previous, int current ); public slots: void slotFind(); @@ -133,6 +134,7 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver bool m_isSetup; bool m_blockNotifications; bool m_inBlackScreenMode; + bool m_showSummaryView; private slots: void slotNextPage(); diff --git a/ui/side_reviews.cpp b/ui/side_reviews.cpp index a036c48be..a35f9ed56 100644 --- a/ui/side_reviews.cpp +++ b/ui/side_reviews.cpp @@ -158,9 +158,11 @@ Reviews::~Reviews() } //BEGIN DocumentObserver Notifies -void Reviews::notifyViewportChanged( bool ) +void Reviews::notifyCurrentPageChanged( int previousPage, int currentPage ) { - m_filterProxy->setCurrentPage( m_document->currentPage() ); + Q_UNUSED( previousPage ) + + m_filterProxy->setCurrentPage( currentPage ); } //END DocumentObserver Notifies diff --git a/ui/side_reviews.h b/ui/side_reviews.h index d063b7b7a..bbd8324ae 100644 --- a/ui/side_reviews.h +++ b/ui/side_reviews.h @@ -42,7 +42,7 @@ class Reviews : public QWidget, public Okular::DocumentObserver // [INHERITED] from DocumentObserver uint observerId() const { return REVIEWS_ID; } - void notifyViewportChanged( bool smoothMove ); + void notifyCurrentPageChanged( int previous, int current ); void reparseConfig(); diff --git a/ui/thumbnaillist.cpp b/ui/thumbnaillist.cpp index 8b2302586..60288cb53 100644 --- a/ui/thumbnaillist.cpp +++ b/ui/thumbnaillist.cpp @@ -310,11 +310,12 @@ void ThumbnailList::notifySetup( const QVector< Okular::Page * > & pages, int se d->delayedRequestVisiblePixmaps( 200 ); } -void ThumbnailList::notifyViewportChanged( bool /*smoothMove*/ ) +void ThumbnailList::notifyCurrentPageChanged( int previousPage, int currentPage ) { + Q_UNUSED( previousPage ) + // skip notifies for the current page (already selected) - const int newPage = d->m_document->viewport().pageNumber; - if ( d->m_selected && d->m_selected->pageNumber() == newPage ) + if ( d->m_selected && d->m_selected->pageNumber() == currentPage ) return; // deselect previous thumbnail @@ -327,7 +328,7 @@ void ThumbnailList::notifyViewportChanged( bool /*smoothMove*/ ) QVector::const_iterator tIt = d->m_thumbnails.constBegin(), tEnd = d->m_thumbnails.constEnd(); for ( ; tIt != tEnd; ++tIt ) { - if ( (*tIt)->pageNumber() == newPage ) + if ( (*tIt)->pageNumber() == currentPage ) { d->m_selected = *tIt; d->m_selected->setSelected( true ); diff --git a/ui/thumbnaillist.h b/ui/thumbnaillist.h index 0d7136ba0..20c434fa0 100644 --- a/ui/thumbnaillist.h +++ b/ui/thumbnaillist.h @@ -41,7 +41,7 @@ Q_OBJECT // inherited: create thumbnails ( inherited as a DocumentObserver ) void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags ); // inherited: hilihght current thumbnail ( inherited as DocumentObserver ) - void notifyViewportChanged( bool smoothMove ); + void notifyCurrentPageChanged( int previous, int current ); // inherited: redraw thumbnail ( inherited as DocumentObserver ) void notifyPageChanged( int pageNumber, int changedFlags ); // inherited: request all visible pixmap (due to a global shange or so..) diff --git a/ui/toc.cpp b/ui/toc.cpp index 3203c79f8..4c84b62c3 100644 --- a/ui/toc.cpp +++ b/ui/toc.cpp @@ -25,7 +25,7 @@ #include "core/document.h" #include "settings.h" -TOC::TOC(QWidget *parent, Okular::Document *document) : QWidget(parent), m_document(document), m_currentPage(-1) +TOC::TOC(QWidget *parent, Okular::Document *document) : QWidget(parent), m_document(document) { QVBoxLayout *mainlay = new QVBoxLayout( this ); mainlay->setMargin( 0 ); @@ -69,7 +69,6 @@ void TOC::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFla // clear contents m_model->clear(); - m_currentPage = -1; // request synopsis description (is a dom tree) const Okular::DocumentSynopsis * syn = m_document->documentSynopsis(); @@ -86,14 +85,8 @@ void TOC::notifySetup( const QVector< Okular::Page * > & /*pages*/, int setupFla emit hasTOC( !m_model->isEmpty() ); } -void TOC::notifyViewportChanged( bool /*smoothMove*/ ) +void TOC::notifyCurrentPageChanged( int, int ) { - int newpage = m_document->viewport().pageNumber; - if ( m_currentPage == newpage ) - return; - - m_currentPage = newpage; - m_model->setCurrentViewport( m_document->viewport() ); } diff --git a/ui/toc.h b/ui/toc.h index 4e63ef65d..eeeff9800 100644 --- a/ui/toc.h +++ b/ui/toc.h @@ -33,7 +33,7 @@ Q_OBJECT // inherited from DocumentObserver uint observerId() const; void notifySetup( const QVector< Okular::Page * > & pages, int setupFlags ); - void notifyViewportChanged( bool smoothMove ); + void notifyCurrentPageChanged( int previous, int current ); void reparseConfig(); @@ -49,7 +49,6 @@ Q_OBJECT QTreeView *m_treeView; KTreeViewSearchLine *m_searchLine; TOCModel *m_model; - int m_currentPage; }; #endif