Port to new threadweaver

Not sure it works at all, but at least it compiles ^_^
frameworks
Albert Astals Cid 12 years ago
parent 20d687cac5
commit efbde66009
  1. 13
      core/pagecontroller.cpp
  2. 9
      core/pagecontroller_p.h
  3. 52
      core/rotationjob.cpp
  4. 38
      core/rotationjob_p.h

@ -11,12 +11,13 @@
// qt/kde includes // qt/kde includes
#include <kglobal.h> #include <kglobal.h>
#include <threadweaver/threadweaver.h>
// local includes // local includes
#include "page_p.h" #include "page_p.h"
#include "rotationjob_p.h" #include "rotationjob_p.h"
#include <threadweaver/queueing.h>
using namespace Okular; using namespace Okular;
PageController::PageController() PageController::PageController()
@ -30,14 +31,14 @@ PageController::~PageController()
void PageController::addRotationJob(RotationJob *job) void PageController::addRotationJob(RotationJob *job)
{ {
connect( job, SIGNAL(done(ThreadWeaver::Job*)), connect( job, SIGNAL(done(ThreadWeaver::JobPointer)),
this, SLOT(imageRotationDone(ThreadWeaver::Job*)) ); this, SLOT(imageRotationDone(ThreadWeaver::JobPointer)) );
ThreadWeaver::Weaver::instance()->enqueue(job); 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() ) if ( job->page() )
{ {

@ -12,9 +12,7 @@
#include <QtCore/QObject> #include <QtCore/QObject>
namespace ThreadWeaver { #include <threadweaver/queue.h>
class Job;
}
namespace Okular { namespace Okular {
@ -37,7 +35,10 @@ class PageController : public QObject
void rotationFinished( int page, Okular::Page *okularPage ); void rotationFinished( int page, Okular::Page *okularPage );
private slots: private slots:
void imageRotationDone(ThreadWeaver::Job*); void imageRotationDone(const ThreadWeaver::JobPointer &job);
private:
ThreadWeaver::Queue m_weaver;
}; };
} }

@ -14,7 +14,8 @@
using namespace Okular; using namespace Okular;
RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer ) 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() ) , mRect( NormalizedRect() )
{ {
} }
@ -29,16 +30,6 @@ void RotationJob::setRect( const NormalizedRect &rect )
mRect = rect; mRect = rect;
} }
QImage RotationJob::image() const
{
return mRotatedImage;
}
Rotation RotationJob::rotation() const
{
return mNewRotation;
}
DocumentObserver * RotationJob::observer() const DocumentObserver * RotationJob::observer() const
{ {
return mObserver; return mObserver;
@ -54,18 +45,6 @@ NormalizedRect RotationJob::rect() const
return mRect; 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 RotationJob::rotationMatrix( Rotation from, Rotation to )
{ {
QTransform matrix; QTransform matrix;
@ -103,4 +82,31 @@ QTransform RotationJob::rotationMatrix( Rotation from, Rotation to )
return matrix; 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" #include "moc_rotationjob_p.cpp"

@ -13,7 +13,8 @@
#include <QtGui/QImage> #include <QtGui/QImage>
#include <QtGui/QTransform> #include <QtGui/QTransform>
#include <threadweaver/Job.h> #include <threadweaver/qobjectdecorator.h>
#include <threadweaver/job.h>
#include "core/global.h" #include "core/global.h"
#include "core/area.h" #include "core/area.h"
@ -23,33 +24,46 @@ namespace Okular {
class DocumentObserver; class DocumentObserver;
class PagePrivate; 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: public:
RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer ); RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer );
void setPage( PagePrivate * pd ); void setPage( PagePrivate * pd );
void setRect( const NormalizedRect &rect ); void setRect( const NormalizedRect &rect );
QImage image() const; QImage image() const { return static_cast<const RotationJobInternal*>(job())->image(); }
Rotation rotation() const; Rotation rotation() const { return static_cast<const RotationJobInternal*>(job())->rotation(); }
DocumentObserver *observer() const; DocumentObserver *observer() const;
PagePrivate * page() const; PagePrivate * page() const;
NormalizedRect rect() const; NormalizedRect rect() const;
static QTransform rotationMatrix( Rotation from, Rotation to ); static QTransform rotationMatrix( Rotation from, Rotation to );
protected:
virtual void run();
private: private:
const QImage mImage;
Rotation mOldRotation;
Rotation mNewRotation;
DocumentObserver *mObserver; DocumentObserver *mObserver;
QImage mRotatedImage;
PagePrivate * m_pd; PagePrivate * m_pd;
NormalizedRect mRect; NormalizedRect mRect;
}; };

Loading…
Cancel
Save