2006-11-03 17:57:32 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-07-04 14:39:52 +00:00
|
|
|
#include "rotationjob_p.h"
|
2006-11-03 17:57:32 +00:00
|
|
|
|
2012-09-08 15:06:02 +00:00
|
|
|
#include <QtGui/QTransform>
|
2007-04-19 18:30:20 +00:00
|
|
|
|
2006-11-03 17:57:32 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
2013-02-24 21:58:53 +00:00
|
|
|
RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer )
|
2014-08-09 18:44:25 +00:00
|
|
|
: ThreadWeaver::QObjectDecorator( new RotationJobInternal( image, oldRotation, newRotation ) )
|
2017-09-05 21:27:18 +00:00
|
|
|
, mObserver( observer ), m_pd( nullptr )
|
2012-08-17 17:25:58 +00:00
|
|
|
, mRect( NormalizedRect() )
|
2006-11-03 17:57:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-03-24 10:47:22 +00:00
|
|
|
void RotationJob::setPage( PagePrivate * pd )
|
|
|
|
{
|
|
|
|
m_pd = pd;
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:25:58 +00:00
|
|
|
void RotationJob::setRect( const NormalizedRect &rect )
|
|
|
|
{
|
|
|
|
mRect = rect;
|
|
|
|
}
|
|
|
|
|
2013-02-24 21:58:53 +00:00
|
|
|
DocumentObserver * RotationJob::observer() const
|
2006-11-03 17:57:32 +00:00
|
|
|
{
|
2013-02-24 21:58:53 +00:00
|
|
|
return mObserver;
|
2006-11-03 17:57:32 +00:00
|
|
|
}
|
|
|
|
|
2007-03-24 10:47:22 +00:00
|
|
|
PagePrivate * RotationJob::page() const
|
|
|
|
{
|
|
|
|
return m_pd;
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:25:58 +00:00
|
|
|
NormalizedRect RotationJob::rect() const
|
|
|
|
{
|
|
|
|
return mRect;
|
|
|
|
}
|
|
|
|
|
2012-09-08 15:06:02 +00:00
|
|
|
QTransform RotationJob::rotationMatrix( Rotation from, Rotation to )
|
2007-09-03 18:16:27 +00:00
|
|
|
{
|
2012-09-08 15:06:02 +00:00
|
|
|
QTransform matrix;
|
2007-07-15 18:43:06 +00:00
|
|
|
|
2007-09-03 18:16:27 +00:00
|
|
|
if ( from == Rotation0 ) {
|
|
|
|
if ( to == Rotation90 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 90 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation180 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 180 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation270 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 270 );
|
2007-09-03 18:16:27 +00:00
|
|
|
} else if ( from == Rotation90 ) {
|
|
|
|
if ( to == Rotation180 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 90 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation270 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 180 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation0 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 270 );
|
2007-09-03 18:16:27 +00:00
|
|
|
} else if ( from == Rotation180 ) {
|
|
|
|
if ( to == Rotation270 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 90 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation0 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 180 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation90 )
|
2006-11-20 07:53:32 +00:00
|
|
|
matrix.rotate( 270 );
|
2007-09-03 18:16:27 +00:00
|
|
|
} else if ( from == Rotation270 ) {
|
|
|
|
if ( to == Rotation0 )
|
2006-11-03 17:57:32 +00:00
|
|
|
matrix.rotate( 90 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation90 )
|
2006-11-03 17:57:32 +00:00
|
|
|
matrix.rotate( 180 );
|
2007-09-03 18:16:27 +00:00
|
|
|
else if ( to == Rotation180 )
|
2006-11-03 17:57:32 +00:00
|
|
|
matrix.rotate( 270 );
|
|
|
|
}
|
|
|
|
|
2007-09-03 18:16:27 +00:00
|
|
|
return matrix;
|
2006-11-03 17:57:32 +00:00
|
|
|
}
|
2007-03-24 10:47:22 +00:00
|
|
|
|
2014-08-09 18:44:25 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-07-11 20:57:11 +00:00
|
|
|
Q_UNUSED(self);
|
|
|
|
Q_UNUSED(thread);
|
|
|
|
|
2014-08-09 18:44:25 +00:00
|
|
|
if ( mOldRotation == mNewRotation ) {
|
|
|
|
mRotatedImage = mImage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QTransform matrix = RotationJob::rotationMatrix( mOldRotation, mNewRotation );
|
|
|
|
|
|
|
|
mRotatedImage = mImage.transformed( matrix );
|
|
|
|
}
|
|
|
|
|
2014-08-08 22:00:07 +00:00
|
|
|
#include "moc_rotationjob_p.cpp"
|