From 4913076ee996e6b2eab29ad79aee8682955cdcaa Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 3 Sep 2007 18:16:27 +0000 Subject: [PATCH] extract in an own static function te calculation of a rotation matrix from both source and destination rotations svn path=/trunk/KDE/kdegraphics/okular/; revision=708049 --- core/rotationjob.cpp | 41 ++++++++++++++++++++++++----------------- core/rotationjob_p.h | 3 +++ 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/core/rotationjob.cpp b/core/rotationjob.cpp index 3e8a443b7..625a5d2cc 100644 --- a/core/rotationjob.cpp +++ b/core/rotationjob.cpp @@ -50,39 +50,46 @@ void RotationJob::run() return; } + QMatrix matrix = rotationMatrix( mOldRotation, mNewRotation ); + + mRotatedImage = mImage.transformed( matrix ); +} + +QMatrix RotationJob::rotationMatrix( Rotation from, Rotation to ) +{ QMatrix matrix; - if ( mOldRotation == Rotation0 ) { - if ( mNewRotation == Rotation90 ) + if ( from == Rotation0 ) { + if ( to == Rotation90 ) matrix.rotate( 90 ); - else if ( mNewRotation == Rotation180 ) + else if ( to == Rotation180 ) matrix.rotate( 180 ); - else if ( mNewRotation == Rotation270 ) + else if ( to == Rotation270 ) matrix.rotate( 270 ); - } else if ( mOldRotation == Rotation90 ) { - if ( mNewRotation == Rotation180 ) + } else if ( from == Rotation90 ) { + if ( to == Rotation180 ) matrix.rotate( 90 ); - else if ( mNewRotation == Rotation270 ) + else if ( to == Rotation270 ) matrix.rotate( 180 ); - else if ( mNewRotation == Rotation0 ) + else if ( to == Rotation0 ) matrix.rotate( 270 ); - } else if ( mOldRotation == Rotation180 ) { - if ( mNewRotation == Rotation270 ) + } else if ( from == Rotation180 ) { + if ( to == Rotation270 ) matrix.rotate( 90 ); - else if ( mNewRotation == Rotation0 ) + else if ( to == Rotation0 ) matrix.rotate( 180 ); - else if ( mNewRotation == Rotation90 ) + else if ( to == Rotation90 ) matrix.rotate( 270 ); - } else if ( mOldRotation == Rotation270 ) { - if ( mNewRotation == Rotation0 ) + } else if ( from == Rotation270 ) { + if ( to == Rotation0 ) matrix.rotate( 90 ); - else if ( mNewRotation == Rotation90 ) + else if ( to == Rotation90 ) matrix.rotate( 180 ); - else if ( mNewRotation == Rotation180 ) + else if ( to == Rotation180 ) matrix.rotate( 270 ); } - mRotatedImage = mImage.transformed( matrix ); + return matrix; } #include "rotationjob_p.moc" diff --git a/core/rotationjob_p.h b/core/rotationjob_p.h index 5aaff0182..9790b64b5 100644 --- a/core/rotationjob_p.h +++ b/core/rotationjob_p.h @@ -11,6 +11,7 @@ #define _OKULAR_ROTATIONJOB_P_H_ #include +#include #include @@ -34,6 +35,8 @@ class RotationJob : public ThreadWeaver::Job int id() const; PagePrivate * page() const; + static QMatrix rotationMatrix( Rotation from, Rotation to ); + protected: virtual void run();