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
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include <QtGui/QMatrix>
|
|
|
|
|
2006-11-03 17:57:32 +00:00
|
|
|
using namespace Okular;
|
|
|
|
|
2006-11-20 07:53:32 +00:00
|
|
|
RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, int id )
|
2007-03-24 10:47:22 +00:00
|
|
|
: mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mId( id ), m_pd( 0 )
|
2006-11-03 17:57:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-03-24 10:47:22 +00:00
|
|
|
void RotationJob::setPage( PagePrivate * pd )
|
|
|
|
{
|
|
|
|
m_pd = pd;
|
|
|
|
}
|
|
|
|
|
2006-11-03 17:57:32 +00:00
|
|
|
QImage RotationJob::image() const
|
|
|
|
{
|
|
|
|
return mRotatedImage;
|
|
|
|
}
|
|
|
|
|
2007-01-05 17:09:47 +00:00
|
|
|
Rotation RotationJob::rotation() const
|
2006-11-20 07:53:32 +00:00
|
|
|
{
|
|
|
|
return mNewRotation;
|
|
|
|
}
|
|
|
|
|
2006-11-03 17:57:32 +00:00
|
|
|
int RotationJob::id() const
|
|
|
|
{
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2007-03-24 10:47:22 +00:00
|
|
|
PagePrivate * RotationJob::page() const
|
|
|
|
{
|
|
|
|
return m_pd;
|
|
|
|
}
|
|
|
|
|
2006-11-03 17:57:32 +00:00
|
|
|
void RotationJob::run()
|
|
|
|
{
|
2006-11-20 07:53:32 +00:00
|
|
|
if ( mOldRotation == mNewRotation ) {
|
|
|
|
mRotatedImage = mImage;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-09-03 18:16:27 +00:00
|
|
|
QMatrix matrix = rotationMatrix( mOldRotation, mNewRotation );
|
|
|
|
|
|
|
|
mRotatedImage = mImage.transformed( matrix );
|
|
|
|
}
|
|
|
|
|
|
|
|
QMatrix RotationJob::rotationMatrix( Rotation from, Rotation to )
|
|
|
|
{
|
2007-07-15 18:43:06 +00:00
|
|
|
QMatrix matrix;
|
|
|
|
|
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
|
|
|
|
2007-07-04 14:39:52 +00:00
|
|
|
#include "rotationjob_p.moc"
|