Okular

rotationjob.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "rotationjob_p.h"
8
9#include <QTransform>
10
11using namespace Okular;
12
13RotationJob::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
22void RotationJob::setPage(PagePrivate *pd)
23{
24 m_pd = pd;
25}
26
27void RotationJob::setRect(const NormalizedRect &rect)
28{
29 mRect = rect;
30}
31
32void RotationJob::setIsPartialUpdate(bool partialUpdate)
33{
34 mIsPartialUpdate = partialUpdate;
35}
36
37DocumentObserver *RotationJob::observer() const
38{
39 return mObserver;
40}
41
42PagePrivate *RotationJob::page() const
43{
44 return m_pd;
45}
46
47NormalizedRect RotationJob::rect() const
48{
49 return mRect;
50}
51
52bool RotationJob::isPartialUpdate() const
53{
54 return mIsPartialUpdate;
55}
56
57QTransform 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
98RotationJobInternal::RotationJobInternal(const QImage &image, Rotation oldRotation, Rotation newRotation)
99 : mImage(image)
100 , mOldRotation(oldRotation)
101 , mNewRotation(newRotation)
102{
103}
104
105QImage RotationJobInternal::image() const
106{
107 return mRotatedImage;
108}
109
110Rotation RotationJobInternal::rotation() const
111{
112 return mNewRotation;
113}
114
115void 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"
Base class for objects being notified when something changes.
Definition observer.h:29
A NormalizedRect is a rectangle which can be defined by two NormalizedPoints.
Definition area.h:189
global.h
Definition action.h:17
Rotation
A rotation.
Definition global.h:46
@ Rotation270
Rotated 2700 degrees clockwise.
Definition global.h:50
@ Rotation90
Rotated 90 degrees clockwise.
Definition global.h:48
@ Rotation180
Rotated 180 degrees clockwise.
Definition global.h:49
@ Rotation0
Not rotated.
Definition global.h:47
QTransform & rotate(qreal a, Qt::Axis axis)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.