Okular

rotationjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2006 Tobias Koenig <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "rotationjob_p.h"
8 
9 #include <QTransform>
10 
11 using namespace Okular;
12 
13 RotationJob::RotationJob(const QImage &image, Rotation oldRotation, Rotation newRotation, DocumentObserver *observer)
14  : ThreadWeaver::QObjectDecorator(new RotationJobInternal(image, oldRotation, newRotation))
15  , mObserver(observer)
16  , m_pd(nullptr)
17  , mRect(NormalizedRect())
18  , mIsPartialUpdate(false)
19 {
20 }
21 
22 void RotationJob::setPage(PagePrivate *pd)
23 {
24  m_pd = pd;
25 }
26 
27 void RotationJob::setRect(const NormalizedRect &rect)
28 {
29  mRect = rect;
30 }
31 
32 void RotationJob::setIsPartialUpdate(bool partialUpdate)
33 {
34  mIsPartialUpdate = partialUpdate;
35 }
36 
37 DocumentObserver *RotationJob::observer() const
38 {
39  return mObserver;
40 }
41 
42 PagePrivate *RotationJob::page() const
43 {
44  return m_pd;
45 }
46 
47 NormalizedRect RotationJob::rect() const
48 {
49  return mRect;
50 }
51 
52 bool RotationJob::isPartialUpdate() const
53 {
54  return mIsPartialUpdate;
55 }
56 
57 QTransform RotationJob::rotationMatrix(Rotation from, Rotation to)
58 {
59  QTransform matrix;
60 
61  if (from == Rotation0) {
62  if (to == Rotation90) {
63  matrix.rotate(90);
64  } else if (to == Rotation180) {
65  matrix.rotate(180);
66  } else if (to == Rotation270) {
67  matrix.rotate(270);
68  }
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  }
77  } else if (from == Rotation180) {
78  if (to == Rotation270) {
79  matrix.rotate(90);
80  } else if (to == Rotation0) {
81  matrix.rotate(180);
82  } else if (to == Rotation90) {
83  matrix.rotate(270);
84  }
85  } else if (from == Rotation270) {
86  if (to == Rotation0) {
87  matrix.rotate(90);
88  } else if (to == Rotation90) {
89  matrix.rotate(180);
90  } else if (to == Rotation180) {
91  matrix.rotate(270);
92  }
93  }
94 
95  return matrix;
96 }
97 
98 RotationJobInternal::RotationJobInternal(const QImage &image, Rotation oldRotation, Rotation newRotation)
99  : mImage(image)
100  , mOldRotation(oldRotation)
101  , mNewRotation(newRotation)
102 {
103 }
104 
105 QImage RotationJobInternal::image() const
106 {
107  return mRotatedImage;
108 }
109 
110 Rotation RotationJobInternal::rotation() const
111 {
112  return mNewRotation;
113 }
114 
115 void RotationJobInternal::run(ThreadWeaver::JobPointer self, ThreadWeaver::Thread *thread)
116 {
117  Q_UNUSED(self);
118  Q_UNUSED(thread);
119 
120  if (mOldRotation == mNewRotation) {
121  mRotatedImage = mImage;
122  return;
123  }
124 
125  const QTransform matrix = RotationJob::rotationMatrix(mOldRotation, mNewRotation);
126 
127  mRotatedImage = mImage.transformed(matrix);
128 }
129 
130 #include "moc_rotationjob_p.cpp"
The documentation to the global Okular namespace.
Definition: action.h:16
QTransform & rotate(qreal angle, Qt::Axis axis)
Base class for objects being notified when something changes.
Definition: observer.h:28
@ Rotation180
Rotated 180 degrees clockwise.
Definition: global.h:48
@ Rotation0
Not rotated.
Definition: global.h:46
A NormalizedRect is a rectangle which can be defined by two NormalizedPoints.
Definition: area.h:188
@ Rotation90
Rotated 90 degrees clockwise.
Definition: global.h:47
@ Rotation270
Rotated 2700 degrees clockwise.
Definition: global.h:49
Rotation
A rotation.
Definition: global.h:45
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Mar 23 2023 04:04:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.