use kDebug
[kdegraphics.git] / okular / core / rotationjob.cpp
blob625a5d2cc97185f15793c0211831f338b44b3321
1 /***************************************************************************
2 * Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "rotationjob_p.h"
12 #include <QtGui/QMatrix>
14 using namespace Okular;
16 RotationJob::RotationJob( const QImage &image, Rotation oldRotation, Rotation newRotation, int id )
17 : mImage( image ), mOldRotation( oldRotation ), mNewRotation( newRotation ), mId( id ), m_pd( 0 )
21 void RotationJob::setPage( PagePrivate * pd )
23 m_pd = pd;
26 QImage RotationJob::image() const
28 return mRotatedImage;
31 Rotation RotationJob::rotation() const
33 return mNewRotation;
36 int RotationJob::id() const
38 return mId;
41 PagePrivate * RotationJob::page() const
43 return m_pd;
46 void RotationJob::run()
48 if ( mOldRotation == mNewRotation ) {
49 mRotatedImage = mImage;
50 return;
53 QMatrix matrix = rotationMatrix( mOldRotation, mNewRotation );
55 mRotatedImage = mImage.transformed( matrix );
58 QMatrix RotationJob::rotationMatrix( Rotation from, Rotation to )
60 QMatrix matrix;
62 if ( from == Rotation0 ) {
63 if ( to == Rotation90 )
64 matrix.rotate( 90 );
65 else if ( to == Rotation180 )
66 matrix.rotate( 180 );
67 else if ( to == Rotation270 )
68 matrix.rotate( 270 );
69 } else if ( from == Rotation90 ) {
70 if ( to == Rotation180 )
71 matrix.rotate( 90 );
72 else if ( to == Rotation270 )
73 matrix.rotate( 180 );
74 else if ( to == Rotation0 )
75 matrix.rotate( 270 );
76 } else if ( from == Rotation180 ) {
77 if ( to == Rotation270 )
78 matrix.rotate( 90 );
79 else if ( to == Rotation0 )
80 matrix.rotate( 180 );
81 else if ( to == Rotation90 )
82 matrix.rotate( 270 );
83 } else if ( from == Rotation270 ) {
84 if ( to == Rotation0 )
85 matrix.rotate( 90 );
86 else if ( to == Rotation90 )
87 matrix.rotate( 180 );
88 else if ( to == Rotation180 )
89 matrix.rotate( 270 );
92 return matrix;
95 #include "rotationjob_p.moc"