From 36b894c75ae0c2d14bd54dfd24c286479c6bace1 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Sat, 24 Mar 2007 10:47:22 +0000 Subject: [PATCH] Create a (private) PageController that handles the rotation jobs from all the pages. This removes the needs for Page to be a QObject (it's the PageController that connects to the jobs and emits the right signals), so it again a "cheap" object. svn path=/trunk/playground/graphics/okular/; revision=646010 --- CMakeLists.txt | 1 + core/document.cpp | 8 +++---- core/page.cpp | 19 ++++++--------- core/page.h | 9 +------ core/page_p.h | 3 ++- core/pagecontroller.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ core/pagecontroller_p.h | 43 +++++++++++++++++++++++++++++++++ core/rotationjob.cpp | 14 ++++++++++- core/rotationjob.h | 8 +++++++ 9 files changed, 132 insertions(+), 26 deletions(-) create mode 100644 core/pagecontroller.cpp create mode 100644 core/pagecontroller_p.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a20da42a..bcfe74f7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,6 +32,7 @@ set(okularcore_SRCS core/misc.cpp core/observer.cpp core/page.cpp + core/pagecontroller.cpp core/pagesize.cpp core/pagetransition.cpp core/rotationjob.cpp diff --git a/core/document.cpp b/core/document.cpp index 81c8ced96..3cfe4ae6d 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -46,6 +46,7 @@ #include "link.h" #include "observer.h" #include "page.h" +#include "pagecontroller_p.h" #include "settings.h" #include "sourcereference.h" @@ -689,6 +690,9 @@ Document::Document() : d( new Private( this ) ) { d->m_bookmarkManager = new BookmarkManager( this ); + + connect( PageController::self(), SIGNAL( rotationFinished( int ) ), + this, SLOT( rotationFinished( int ) ) ); } Document::~Document() @@ -847,10 +851,6 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi } } - for ( int i = 0; i < d->m_pagesVector.count(); ++i ) - connect( d->m_pagesVector.at(i), SIGNAL( rotationFinished( int ) ), - this, SLOT( rotationFinished( int ) ) ); - QApplication::restoreOverrideCursor(); if ( !openOk || d->m_pagesVector.size() <= 0 ) { diff --git a/core/page.cpp b/core/page.cpp index 12f32ba1c..19350a584 100644 --- a/core/page.cpp +++ b/core/page.cpp @@ -23,6 +23,7 @@ #include "link.h" #include "page.h" #include "page_p.h" +#include "pagecontroller_p.h" #include "pagesize.h" #include "pagetransition.h" #include "rotationjob.h" @@ -68,10 +69,8 @@ PagePrivate::~PagePrivate() } -void PagePrivate::imageRotationDone() +void PagePrivate::imageRotationDone( RotationJob * job ) { - RotationJob *job = static_cast( m_page->sender() ); - QMap< int, Page::PixmapObject >::iterator it = m_page->m_pixmaps.find( job->id() ); if ( it != m_page->m_pixmaps.end() ) { @@ -85,10 +84,6 @@ void PagePrivate::imageRotationDone() m_page->m_pixmaps.insert( job->id(), object ); } - - emit m_page->rotationFinished( m_number ); - - job->deleteLater(); } QMatrix PagePrivate::rotationMatrix() const @@ -116,7 +111,7 @@ QMatrix PagePrivate::rotationMatrix() const /** class Page **/ Page::Page( uint page, double w, double h, Rotation o ) - : QObject( 0 ), d( new PagePrivate( this, page, w, h, o ) ), + : d( new PagePrivate( this, page, w, h, o ) ), m_textSelections( 0 ) { } @@ -288,7 +283,8 @@ void Page::rotateAt( Rotation orientation ) const PixmapObject &object = it.value(); RotationJob *job = new RotationJob( object.m_pixmap->toImage(), object.m_rotation, d->m_rotation, it.key() ); - connect( job, SIGNAL( finished() ), this, SLOT( imageRotationDone() ) ); + job->setPage( d ); + QObject::connect( job, SIGNAL( finished() ), PageController::self(), SLOT( imageRotationDone() ) ); job->start(); } @@ -371,7 +367,8 @@ void Page::setPixmap( int id, QPixmap *pixmap ) it.value().m_rotation = d->m_rotation; } else { RotationJob *job = new RotationJob( pixmap->toImage(), Rotation0, d->m_rotation, id ); - connect( job, SIGNAL( finished() ), this, SLOT( imageRotationDone() ) ); + job->setPage( d ); + QObject::connect( job, SIGNAL( finished() ), PageController::self(), SLOT( imageRotationDone() ) ); job->start(); delete pixmap; @@ -734,5 +731,3 @@ void Page::saveLocalContents( QDomNode & parentNode, QDomDocument & document ) c if ( pageElement.hasChildNodes() ) parentNode.appendChild( pageElement ); } - -#include "page.moc" diff --git a/core/page.h b/core/page.h index 61c8e4980..af1aa4067 100644 --- a/core/page.h +++ b/core/page.h @@ -46,10 +46,8 @@ class TextSelection; * * Note: The class takes ownership of all objects. */ -class OKULAR_EXPORT Page : public QObject +class OKULAR_EXPORT Page { - Q_OBJECT - public: /** * An action to be executed when particular events happen. @@ -346,9 +344,6 @@ class OKULAR_EXPORT Page : public QObject */ void saveLocalContents( QDomNode & parentNode, QDomDocument & document ) const; - Q_SIGNALS: - void rotationFinished( int page ); - private: PagePrivate* const d; friend class PagePrivate; @@ -373,8 +368,6 @@ class OKULAR_EXPORT Page : public QObject HighlightAreaRect *m_textSelections; Q_DISABLE_COPY( Page ) - Q_PRIVATE_SLOT( d, void imageRotationDone() ) - }; } diff --git a/core/page_p.h b/core/page_p.h index 7e768ebbb..8ffe4e0b0 100644 --- a/core/page_p.h +++ b/core/page_p.h @@ -25,6 +25,7 @@ class FormField; class Link; class Page; class PageTransition; +class RotationJob; class TextPage; class PagePrivate @@ -33,7 +34,7 @@ class PagePrivate PagePrivate( Page *page, uint n, double w, double h, Rotation o ); ~PagePrivate(); - void imageRotationDone(); + void imageRotationDone( RotationJob * job ); QMatrix rotationMatrix() const; Page *m_page; diff --git a/core/pagecontroller.cpp b/core/pagecontroller.cpp new file mode 100644 index 000000000..9f1d85456 --- /dev/null +++ b/core/pagecontroller.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2007 by Pino Toscano * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +// qt/kde includes +#include + +// local includes +#include "page_p.h" +#include "pagecontroller_p.h" +#include "rotationjob.h" + +K_GLOBAL_STATIC( Okular::PageController, page_controller_self ) + +using namespace Okular; + +PageController::PageController() + : QObject() +{ +} + +PageController::~PageController() +{ +} + +PageController * PageController::self() +{ + return page_controller_self; +} + +void PageController::imageRotationDone() +{ + RotationJob *job = sender() ? qobject_cast< RotationJob * >( sender() ) : 0; + + if ( !job ) + return; + + if ( job->page() ) + { + job->page()->imageRotationDone( job ); + + emit rotationFinished( job->page()->m_number ); + } + + job->deleteLater(); +} + +#include "pagecontroller_p.moc" diff --git a/core/pagecontroller_p.h b/core/pagecontroller_p.h new file mode 100644 index 000000000..2a9d71841 --- /dev/null +++ b/core/pagecontroller_p.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2007 by Pino Toscano * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef _OKULAR_PAGECONTROLLER_P_H_ +#define _OKULAR_PAGECONTROLLER_P_H_ + +#include + +namespace Okular { + +class Page; +class PagePrivate; + +class PageController : public QObject +{ + Q_OBJECT + + public: + /** + * Constructor. No NOT use this, NEVER! Use the static self() instead. + */ + PageController(); + + ~PageController(); + + static PageController * self(); + + signals: + void rotationFinished( int page ); + + private slots: + void imageRotationDone(); +}; + +} + +#endif diff --git a/core/rotationjob.cpp b/core/rotationjob.cpp index b3f6a95cc..dc86aac05 100644 --- a/core/rotationjob.cpp +++ b/core/rotationjob.cpp @@ -14,10 +14,15 @@ using namespace Okular; RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, int id ) - : mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mId( id ) + : mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mId( id ), m_pd( 0 ) { } +void RotationJob::setPage( PagePrivate * pd ) +{ + m_pd = pd; +} + QImage RotationJob::image() const { return mRotatedImage; @@ -33,6 +38,11 @@ int RotationJob::id() const return mId; } +PagePrivate * RotationJob::page() const +{ + return m_pd; +} + void RotationJob::run() { QMatrix matrix; @@ -74,3 +84,5 @@ void RotationJob::run() mRotatedImage = mImage.transformed( matrix ); } + +#include "rotationjob.moc" diff --git a/core/rotationjob.h b/core/rotationjob.h index 2426502a1..7051447de 100644 --- a/core/rotationjob.h +++ b/core/rotationjob.h @@ -17,14 +17,21 @@ namespace Okular { +class PagePrivate; + class RotationJob : public QThread { + Q_OBJECT + public: RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, int id ); + void setPage( PagePrivate * pd ); + QImage image() const; Rotation rotation() const; int id() const; + PagePrivate * page() const; protected: virtual void run(); @@ -35,6 +42,7 @@ class RotationJob : public QThread Rotation mNewRotation; int mId; QImage mRotatedImage; + PagePrivate * m_pd; }; }