diff --git a/core/pagecontroller.cpp b/core/pagecontroller.cpp index 44258a6a9..18848f278 100644 --- a/core/pagecontroller.cpp +++ b/core/pagecontroller.cpp @@ -11,12 +11,13 @@ // qt/kde includes #include -#include // local includes #include "page_p.h" #include "rotationjob_p.h" +#include + using namespace Okular; PageController::PageController() @@ -30,14 +31,14 @@ PageController::~PageController() void PageController::addRotationJob(RotationJob *job) { - connect( job, SIGNAL(done(ThreadWeaver::Job*)), - this, SLOT(imageRotationDone(ThreadWeaver::Job*)) ); - ThreadWeaver::Weaver::instance()->enqueue(job); + connect( job, SIGNAL(done(ThreadWeaver::JobPointer)), + this, SLOT(imageRotationDone(ThreadWeaver::JobPointer)) ); + ThreadWeaver::enqueue(&m_weaver, job); } -void PageController::imageRotationDone(ThreadWeaver::Job *j) +void PageController::imageRotationDone(const ThreadWeaver::JobPointer &j) { - RotationJob *job = static_cast< RotationJob * >( j ); + RotationJob *job = static_cast< RotationJob * >( j.data() ); if ( job->page() ) { diff --git a/core/pagecontroller_p.h b/core/pagecontroller_p.h index 55fe7bf36..56b63b23f 100644 --- a/core/pagecontroller_p.h +++ b/core/pagecontroller_p.h @@ -12,9 +12,7 @@ #include -namespace ThreadWeaver { - class Job; -} +#include namespace Okular { @@ -37,7 +35,10 @@ class PageController : public QObject void rotationFinished( int page, Okular::Page *okularPage ); private slots: - void imageRotationDone(ThreadWeaver::Job*); + void imageRotationDone(const ThreadWeaver::JobPointer &job); + + private: + ThreadWeaver::Queue m_weaver; }; } diff --git a/core/rotationjob.cpp b/core/rotationjob.cpp index 898bc922d..cf4cc0987 100644 --- a/core/rotationjob.cpp +++ b/core/rotationjob.cpp @@ -14,7 +14,8 @@ using namespace Okular; RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer ) - : mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mObserver( observer ), m_pd( 0 ) + : ThreadWeaver::QObjectDecorator( new RotationJobInternal( image, oldRotation, newRotation ) ) + , mObserver( observer ), m_pd( 0 ) , mRect( NormalizedRect() ) { } @@ -29,16 +30,6 @@ void RotationJob::setRect( const NormalizedRect &rect ) mRect = rect; } -QImage RotationJob::image() const -{ - return mRotatedImage; -} - -Rotation RotationJob::rotation() const -{ - return mNewRotation; -} - DocumentObserver * RotationJob::observer() const { return mObserver; @@ -54,18 +45,6 @@ NormalizedRect RotationJob::rect() const return mRect; } -void RotationJob::run() -{ - if ( mOldRotation == mNewRotation ) { - mRotatedImage = mImage; - return; - } - - QTransform matrix = rotationMatrix( mOldRotation, mNewRotation ); - - mRotatedImage = mImage.transformed( matrix ); -} - QTransform RotationJob::rotationMatrix( Rotation from, Rotation to ) { QTransform matrix; @@ -103,4 +82,31 @@ QTransform RotationJob::rotationMatrix( Rotation from, Rotation to ) return matrix; } +RotationJobInternal::RotationJobInternal( const QImage &image, Rotation oldRotation, Rotation newRotation ) + : mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ) +{ +} + +QImage RotationJobInternal::image() const +{ + return mRotatedImage; +} + +Rotation RotationJobInternal::rotation() const +{ + return mNewRotation; +} + +void RotationJobInternal::run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread) +{ + if ( mOldRotation == mNewRotation ) { + mRotatedImage = mImage; + return; + } + + const QTransform matrix = RotationJob::rotationMatrix( mOldRotation, mNewRotation ); + + mRotatedImage = mImage.transformed( matrix ); +} + #include "moc_rotationjob_p.cpp" diff --git a/core/rotationjob_p.h b/core/rotationjob_p.h index ee277931e..dc1712b98 100644 --- a/core/rotationjob_p.h +++ b/core/rotationjob_p.h @@ -13,7 +13,8 @@ #include #include -#include +#include +#include #include "core/global.h" #include "core/area.h" @@ -23,33 +24,46 @@ namespace Okular { class DocumentObserver; class PagePrivate; -class RotationJob : public ThreadWeaver::Job +class RotationJobInternal : public ThreadWeaver::Job { - Q_OBJECT + friend class RotationJob; + + public: + QImage image() const; + Rotation rotation() const; + NormalizedRect rect() const; + + protected: + void run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread) Q_DECL_OVERRIDE; + + private: + RotationJobInternal( const QImage &image, Rotation oldRotation, Rotation newRotation ); + + const QImage mImage; + Rotation mOldRotation; + Rotation mNewRotation; + QImage mRotatedImage; +}; +class RotationJob : public ThreadWeaver::QObjectDecorator +{ + Q_OBJECT public: RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer ); void setPage( PagePrivate * pd ); void setRect( const NormalizedRect &rect ); - QImage image() const; - Rotation rotation() const; + QImage image() const { return static_cast(job())->image(); } + Rotation rotation() const { return static_cast(job())->rotation(); } DocumentObserver *observer() const; PagePrivate * page() const; NormalizedRect rect() const; static QTransform rotationMatrix( Rotation from, Rotation to ); - protected: - virtual void run(); - private: - const QImage mImage; - Rotation mOldRotation; - Rotation mNewRotation; DocumentObserver *mObserver; - QImage mRotatedImage; PagePrivate * m_pd; NormalizedRect mRect; };