Krita Source Code Documentation
Loading...
Searching...
No Matches
rotateimage.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2004 Michael Thaler <michael.thaler@physik.tu-muenchen.de>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "rotateimage.h"
8
9#include <math.h>
10
11#include <klocalizedstring.h>
12#include <kis_debug.h>
13#include <kpluginfactory.h>
14#include <kis_icon.h>
15#include <kundo2magicstring.h>
16#include <kis_image.h>
17#include <kis_types.h>
18#include <KisViewManager.h>
19#include <kis_image_manager.h>
20#include <kis_node_manager.h>
22#include <kis_group_layer.h>
23#include <kis_action.h>
24#include <kis_selection.h>
25
26#include "dlg_rotateimage.h"
27
28K_PLUGIN_FACTORY_WITH_JSON(RotateImageFactory, "kritarotateimage.json", registerPlugin<RotateImage>();)
29
30RotateImage::RotateImage(QObject *parent, const QVariantList &)
31 : KisActionPlugin(parent)
32{
33
34 KisAction *action = createAction("rotateimage");
35 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateImage()));
36
37 action = createAction("rotateImageCW90");
38 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateImage90()));
39
40 action = createAction("rotateImage180");
41 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateImage180()));
42
43 action = createAction("rotateImageCCW90");
44 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateImage270()));
45
46 action = createAction("mirrorImageHorizontal");
47 connect(action, SIGNAL(triggered()), this, SLOT(slotMirrorImageHorizontal()));
48
49 action = createAction("mirrorImageVertical");
50 connect(action, SIGNAL(triggered()), this, SLOT(slotMirrorImageVertical()));
51
52 action = createAction("rotatelayer");
53 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateLayer()));
54
55 action = createAction("rotateLayer180");
56 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateLayer180()));
57
58 action = createAction("rotateLayerCW90");
59 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateLayerCW90()));
60
61 action = createAction("rotateLayerCCW90");
62 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateLayerCCW90()));
63
64 action = createAction("rotateAllLayers");
65 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateAllLayers()));
66
67 action = createAction("rotateAllLayersCW90");
68 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateAllLayersCW90()));
69
70 action = createAction("rotateAllLayersCCW90");
71 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateAllLayersCCW90()));
72
73 action = createAction("rotateAllLayers180");
74 connect(action, SIGNAL(triggered()), this, SLOT(slotRotateAllLayers180()));
75}
76
80
82{
83 KisImageWSP image = viewManager()->image();
84 if (!image) return;
85
86 if (!viewManager()->blockUntilOperationsFinished(image)) return;
87
88 DlgRotateImage * dlgRotateImage = new DlgRotateImage(viewManager()->mainWindowAsQWidget(), "RotateImage");
89 Q_CHECK_PTR(dlgRotateImage);
90
91 dlgRotateImage->setCaption(i18n("Rotate Image"));
92
93 if (dlgRotateImage->exec() == QDialog::Accepted) {
94 double angle = dlgRotateImage->angle() * M_PI / 180;
95 viewManager()->imageManager()->rotateCurrentImage(angle);
96 }
97 delete dlgRotateImage;
98}
99
101{
102 viewManager()->imageManager()->rotateCurrentImage(M_PI / 2);
103}
104
106{
107 viewManager()->imageManager()->rotateCurrentImage(M_PI);
108}
109
111{
112 viewManager()->imageManager()->rotateCurrentImage(- M_PI / 2 + M_PI*2);
113}
114
116{
117 KisImageWSP image = viewManager()->image();
118 if (!image) return;
119 viewManager()->nodeManager()->mirrorNode(image->rootLayer(),
120 kundo2_i18n("Mirror Image Vertically"),
121 Qt::Vertical, 0);
122}
123
125{
126 KisImageWSP image = viewManager()->image();
127 if (!image) return;
128 viewManager()->nodeManager()->mirrorNode(image->rootLayer(),
129 kundo2_i18n("Mirror Image Horizontally"),
130 Qt::Horizontal, 0);
131}
132
133
139{
140 KisImageWSP image = viewManager()->image();
141 if (!image) return;
142
143 if (!viewManager()->blockUntilOperationsFinished(image)) return;
144
145 DlgRotateImage * dlgRotateImage = new DlgRotateImage(viewManager()->mainWindowAsQWidget(), "RotateLayer");
146 Q_CHECK_PTR(dlgRotateImage);
147
148 dlgRotateImage->setCaption(i18np("Rotate Layer", "Rotate %1 Layers", nodes.size()));
149
150 if (dlgRotateImage->exec() == QDialog::Accepted) {
151 double angle = dlgRotateImage->angle() * M_PI / 180;
152 image->rotateNodes(nodes, angle, viewManager()->selection());
153 }
154 delete dlgRotateImage;
155}
156
157void RotateImage::rotateLayerImpl(KisNodeSP rootNode, qreal radians)
158{
159 rotateLayersImpl(KisNodeList{rootNode}, radians);
160}
162{
163 KisImageWSP image = viewManager()->image();
164 if (!image) return;
165
166 if (!viewManager()->blockUntilOperationsFinished(image)) return;
167
168 image->rotateNodes(nodes, radians, viewManager()->selection());
169}
170
172{
173 rotateLayersCustomImpl(viewManager()->nodeManager()->selectedNodes());
174}
175
177{
178 KisImageWSP image = viewManager()->image();
179 if (!image) return;
180
181 rotateLayerCustomImpl(image->root());
182}
183
185{
186 rotateLayersImpl(viewManager()->nodeManager()->selectedNodes(), M_PI / 2);
187}
188
190{
191 rotateLayersImpl(viewManager()->nodeManager()->selectedNodes(), -M_PI / 2);
192}
193
195{
196 rotateLayersImpl(viewManager()->nodeManager()->selectedNodes(), M_PI);
197}
198
200{
201 KisImageWSP image = viewManager()->image();
202 if (!image) return;
203
204 rotateLayerImpl(image->root(), M_PI / 2);
205}
206
208{
209 KisImageWSP image = viewManager()->image();
210 if (!image) return;
211
212 rotateLayerImpl(image->root(), -M_PI / 2);
213}
214
216{
217 KisImageWSP image = viewManager()->image();
218 if (!image) return;
219
220 rotateLayerImpl(image->root(), M_PI);
221}
222
223#include "rotateimage.moc"
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QPointer< KisViewManager > viewManager() const
KisGroupLayerSP rootLayer() const
void rotateNodes(KisNodeList nodes, double radians, KisSelectionSP selection)
virtual void setCaption(const QString &caption)
Definition KoDialog.cpp:498
void slotRotateAllLayers()
void slotRotateImage90()
void rotateLayersCustomImpl(KisNodeList nodes)
RotateImage(QObject *parent, const QVariantList &)
void rotateLayersImpl(KisNodeList nodes, qreal radians)
void slotRotateLayer180()
void slotRotateLayer()
void slotRotateLayerCCW90()
void slotRotateAllLayersCW90()
void slotRotateAllLayersCCW90()
void rotateLayerCustomImpl(KisNodeSP rootNode)
void slotRotateAllLayers180()
void rotateLayerImpl(KisNodeSP rootNode, qreal radians)
void slotRotateImage270()
void slotRotateImage()
void slotMirrorImageHorizontal()
void slotMirrorImageVertical()
void slotRotateImage180()
void slotRotateLayerCW90()
~RotateImage() override
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
#define M_PI
Definition kis_global.h:111
KUndo2MagicString kundo2_i18n(const char *text)