From 7cfa67ecf4e003ad0267e6bc1a3b0e606fdf12fb Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 1 May 2007 23:21:29 +0000 Subject: [PATCH] improve a bit the Document::setPageSize API -- better pass the size, and not an index svn path=/trunk/KDE/kdegraphics/okular/; revision=660208 --- core/document.cpp | 14 +++++++------- core/document.h | 2 +- ui/pageview.cpp | 10 +++++++++- ui/pageview.h | 1 + 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 8afe83ad8..07feeafbd 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -2289,17 +2289,17 @@ void Document::setRotation( int r ) kDebug(OkularDebug) << "Rotated: " << r << endl; } -void Document::slotPageSizes( int newsize ) +void Document::setPageSize( const PageSize &size ) { - if ( !d->m_generator->hasFeature( Generator::PageSizes ) || newsize < 0 || newsize >= d->m_pageSizes.count() ) + int sizeid = d->m_pageSizes.indexOf( size ); + if ( !d->m_generator->hasFeature( Generator::PageSizes ) || sizeid == -1 ) return; - const PageSize& ps = d->m_pageSizes.at( newsize ); // tell the pages to change size QVector< Okular::Page * >::const_iterator pIt = d->m_pagesVector.begin(); QVector< Okular::Page * >::const_iterator pEnd = d->m_pagesVector.end(); for ( ; pIt != pEnd; ++pIt ) - (*pIt)->changeSize( ps ); + (*pIt)->changeSize( size ); // clear 'memory allocation' descriptors QLinkedList< AllocatedPixmap * >::const_iterator aIt = d->m_allocatedPixmapsFifo.begin(); QLinkedList< AllocatedPixmap * >::const_iterator aEnd = d->m_allocatedPixmapsFifo.end(); @@ -2308,13 +2308,13 @@ void Document::slotPageSizes( int newsize ) d->m_allocatedPixmapsFifo.clear(); d->m_allocatedPixmapsTotalMemory = 0; // notify the generator that the current page size has changed - d->m_generator->pageSizeChanged( ps, d->m_pageSize ); + d->m_generator->pageSizeChanged( size, d->m_pageSize ); // set the new page size - d->m_pageSize = ps; + d->m_pageSize = size; foreachObserver( notifySetup( d->m_pagesVector, true ) ); foreachObserver( notifyContentsCleared( DocumentObserver::Pixmap | DocumentObserver::Highlights ) ); - kDebug(OkularDebug) << "PageSize no: " << newsize << endl; + kDebug(OkularDebug) << "New PageSize id: " << sizeid << endl; } diff --git a/core/document.h b/core/document.h index 758b7cb01..d05a95f76 100644 --- a/core/document.h +++ b/core/document.h @@ -478,7 +478,7 @@ class OKULAR_EXPORT Document : public QObject * This slot is called whenever the user changes the page @p size * of the document. */ - void slotPageSizes( int size ); + void setPageSize( const PageSize &size ); Q_SIGNALS: /** diff --git a/ui/pageview.cpp b/ui/pageview.cpp index e860e7137..393cc26cf 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -344,7 +344,7 @@ void PageView::setupActions( KActionCollection * ac ) ac->addAction("view_pagesizes", d->aPageSizes); connect( d->aPageSizes , SIGNAL( triggered( int ) ), - d->document , SLOT( slotPageSizes( int ) ) ); + this, SLOT( slotPageSizes( int ) ) ); bool pageSizes = d->document->supportsPageSizes(); d->aPageSizes->setEnabled( pageSizes ); @@ -2948,6 +2948,14 @@ void PageView::slotRotateOriginal() d->document->setRotation( 0 ); } +void PageView::slotPageSizes( int newsize ) +{ + if ( newsize < 0 || newsize >= d->document->pageSizes().count() ) + return; + + d->document->setPageSize( d->document->pageSizes().at( newsize ) ); +} + void PageView::slotToggleForms() { toggleFormWidgets( !d->m_formsVisible ); diff --git a/ui/pageview.h b/ui/pageview.h index 88463b83b..f9fb186b5 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -187,6 +187,7 @@ Q_OBJECT void slotRotateClockwise(); void slotRotateCounterClockwise(); void slotRotateOriginal(); + void slotPageSizes( int ); void slotToggleForms(); };