Krita

View.cpp
1 /*
2  * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 #include "View.h"
7 #include <QPointer>
8 #include <QScopedPointer>
9 
10 #include <KoPattern.h>
11 #include <KoAbstractGradient.h>
12 #include <kis_paintop_preset.h>
13 #include <KisView.h>
14 #include <KisViewManager.h>
15 #include <kis_node_manager.h>
16 #include <kis_selection_manager.h>
17 #include <kis_canvas_resource_provider.h>
18 #include <kis_exposure_gamma_correction_interface.h>
19 #include <kis_paintop_box.h>
20 #include <KisMainWindow.h>
21 #include <KoCanvasBase.h>
22 #include <kis_canvas2.h>
23 #include <KisResourceTypes.h>
24 #include <KisDocument.h>
25 #include "Document.h"
26 #include "Canvas.h"
27 #include "Window.h"
28 #include "Resource.h"
29 #include "ManagedColor.h"
30 
31 #include "LibKisUtils.h"
32 
33 
34 struct View::Private {
35  Private() {}
36  QPointer<KisView> view;
37 };
38 
39 View::View(KisView* view, QObject *parent)
40  : QObject(parent)
41  , d(new Private)
42 {
43  d->view = view;
44 }
45 
46 View::~View()
47 {
48  delete d;
49 }
50 
51 bool View::operator==(const View &other) const
52 {
53  return (d->view == other.d->view);
54 }
55 
56 bool View::operator!=(const View &other) const
57 {
58  return !(operator==(other));
59 }
60 
62 {
63  if (!d->view) return 0;
64  KisMainWindow *mainwin = d->view->mainWindow();
65  Window *win = new Window(mainwin);
66  return win;
67 }
68 
69 
71 {
72  if (!d->view) return 0;
73  Document *doc = new Document(d->view->document(), false);
74  return doc;
75 }
76 
77 void View::setDocument(Document *document)
78 {
79  if (!d->view || !document || !document->document()) return;
80  d->view = d->view->replaceBy(document->document());
81 }
82 
83 bool View::visible() const
84 {
85  if (!d->view) return false;
86  return d->view->isVisible();
87 }
88 
90 {
91  if (!d->view) return;
92  KisMainWindow *mainwin = d->view->mainWindow();
93  mainwin->setActiveView(d->view);
94  mainwin->subWindowActivated();
95 }
96 
98 {
99  if (!d->view) return 0;
100  Canvas *c = new Canvas(d->view->canvasBase());
101  return c;
102 }
103 
104 KisView *View::view()
105 {
106  return d->view;
107 }
108 
110 {
111  if (!d->view) return;
112  if (!resource) return;
113 
114  KoResourceSP r = resource->resource();
115  if (!r) return;
116 
117  if (r.dynamicCast<KoPattern>()) {
118  QVariant v;
119  v.setValue<KoResourceSP>(r);
120  d->view->canvasBase()->resourceManager()->setResource(KoCanvasResource::CurrentPattern, v);
121  }
122  else if (r.dynamicCast<KoAbstractGradient>()) {
123  QVariant v;
124  v.setValue<KoResourceSP>(r);
125  d->view->canvasBase()->resourceManager()->setResource(KoCanvasResource::CurrentGradient, v);
126  }
127  else if (r.dynamicCast<KisPaintOpPreset>()) {
128  d->view->viewManager()->paintOpBox()->resourceSelected(r);
129  }
130 
131 }
132 
133 
135 {
136  if (!d->view) return 0;
137  return new ManagedColor(d->view->resourceProvider()->fgColor());
138 }
139 
140 void View::setForeGroundColor(ManagedColor *color)
141 {
142  if (!d->view) return;
143  d->view->resourceProvider()->setFGColor(color->color());
144 }
145 
146 ManagedColor *View::backgroundColor() const
147 {
148  if (!d->view) return 0;
149  return new ManagedColor(d->view->resourceProvider()->bgColor());
150 }
151 
152 void View::setBackGroundColor(ManagedColor *color)
153 {
154  if (!d->view) return;
155  d->view->resourceProvider()->setBGColor(color->color());
156 }
157 
158 Resource *View::currentBrushPreset() const
159 {
160  if (!d->view) return 0;
161  return new Resource(d->view->resourceProvider()->currentPreset(), ResourceType::PaintOpPresets);
162 }
163 
164 void View::setCurrentBrushPreset(Resource *resource)
165 {
166  activateResource(resource);
167 }
168 
169 Resource *View::currentPattern() const
170 {
171  if (!d->view) return 0;
172  return new Resource(d->view->resourceProvider()->currentPattern(), ResourceType::Patterns);
173 }
174 
175 void View::setCurrentPattern(Resource *resource)
176 {
177  activateResource(resource);
178 }
179 
180 Resource *View::currentGradient() const
181 {
182  if (!d->view) return 0;
183  return new Resource(d->view->resourceProvider()->currentGradient(), ResourceType::Gradients);
184 }
185 
186 void View::setCurrentGradient(Resource *resource)
187 {
188  activateResource(resource);
189 }
190 
191 QString View::currentBlendingMode() const
192 {
193  if (!d->view) return "";
194  return d->view->resourceProvider()->currentCompositeOp();
195 }
196 
197 void View::setCurrentBlendingMode(const QString &blendingMode)
198 {
199  if (!d->view) return;
200  d->view->resourceProvider()->setCurrentCompositeOp(blendingMode);
201 }
202 
203 float View::HDRExposure() const
204 {
205  if (!d->view) return 0.0;
206  KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
207  return iface->currentExposure();
208 }
209 
210 void View::setHDRExposure(float exposure)
211 {
212  if (!d->view) return;
213  KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
214  iface->setCurrentExposure(exposure);
215 }
216 
217 float View::HDRGamma() const
218 {
219  if (!d->view) return 0.0;
220  KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
221  return iface->currentGamma();
222 }
223 
224 void View::setHDRGamma(float gamma)
225 {
226  if (!d->view) return;
227  KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
228  return iface->setCurrentGamma(gamma);
229 }
230 
231 qreal View::paintingOpacity() const
232 {
233  if (!d->view) return 0.0;
234  return d->view->resourceProvider()->opacity();
235 }
236 
237 void View::setPaintingOpacity(qreal opacity)
238 {
239  if (!d->view) return;
240  d->view->resourceProvider()->setOpacity(opacity);
241 }
242 
243 qreal View::brushSize() const
244 {
245  if (!d->view) return 0.0;
246  return d->view->resourceProvider()->size();
247 }
248 
249 void View::setBrushSize(qreal brushSize)
250 {
251  if (!d->view) return;
252  d->view->resourceProvider()->setSize(brushSize);
253 }
254 
255 qreal View::paintingFlow() const
256 {
257  if (!d->view) return 0.0;
258  return d->view->resourceProvider()->flow();
259 }
260 
261 void View::setPaintingFlow(qreal flow)
262 {
263  if (!d->view) return;
264  d->view->resourceProvider()->setFlow(flow);
265 }
266 
268 {
269  if (!d->view) return QList<Node *>();
270  if (!d->view->viewManager()) return QList<Node *>();
271  if (!d->view->viewManager()->nodeManager()) return QList<Node *>();
272 
273  KisNodeList selectedNodes = d->view->viewManager()->nodeManager()->selectedNodes();
274  return LibKisUtils::createNodeList(selectedNodes, d->view->image());
275 }
276 
277 void View::showFloatingMessage(const QString &message, const QIcon& icon, int timeout, int priority)
278 {
279  if (!d->view) return;
280 
281  KisFloatingMessage::Priority p;
282  p = static_cast<KisFloatingMessage::Priority>(priority);
283 
284  d->view->showFloatingMessage(message, icon, timeout, p);
285 }
286 
288 {
289  if (!d->view->document()) return QTransform();
290  return d->view->canvasBase()->coordinatesConverter()->documentToFlakeTransform().inverted();
291 }
292 
294 {
295  if (!d->view->document()) return QTransform();
296  return d->view->canvasBase()->coordinatesConverter()->flakeToWidgetTransform();
297 }
298 
300 {
301  if (!d->view->document()) return QTransform();
302 
303  const KisCoordinatesConverter* coordinatesConverter(d->view->canvasBase()->coordinatesConverter());
304  QTransform imageToFlakeTransform = coordinatesConverter->imageToDocumentTransform() * coordinatesConverter->documentToFlakeTransform();
305 
306  return imageToFlakeTransform.inverted();
307 }
void activateResource(Resource *resource)
activateResource activates the given resource.
Definition: View.cpp:109
A Resource represents a gradient, pattern, brush tip, brush preset, palette or workspace definition.
Definition: Resource.h:30
Window represents one Krita mainwindow.
Definition: Window.h:22
bool visible() const
Definition: View.cpp:83
ManagedColor * foregroundColor() const
Definition: View.cpp:134
Document * document() const
Definition: View.cpp:70
QTransform flakeToImageTransform() const
flakeToImageTransform The tranformation of the image relative to the view without rotation and mirror...
Definition: View.cpp:299
The Document class encapsulates a Krita Document/Image.
Definition: Document.h:33
void setValue(const T &value)
View represents one view on a document.
Definition: View.h:24
QTransform flakeToDocumentTransform() const
flakeToDocumentTransform The tranformation of the document relative to the view without rotation and ...
Definition: View.cpp:287
Canvas * canvas() const
Definition: View.cpp:97
QList< Node * > selectedNodes() const
Definition: View.cpp:267
void setDocument(Document *document)
Reset the view to show document.
Definition: View.cpp:77
Window * window() const
Definition: View.cpp:61
void showFloatingMessage(const QString &message, const QIcon &icon, int timeout, int priority)
showFloatingMessage displays a floating message box on the top-left corner of the canvas
Definition: View.cpp:277
The ManagedColor class is a class to handle colors that are color managed.
Definition: ManagedColor.h:45
QTransform flakeToCanvasTransform() const
flakeToCanvasTransform The tranformation of the canvas relative to the view without rotation and mirr...
Definition: View.cpp:293
Canvas wraps the canvas inside a view on an image/document.
Definition: Canvas.h:22
void setVisible()
Make the current view visible.
Definition: View.cpp:89
QTransform inverted(bool *invertible) const const
QString message
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Dec 4 2022 04:12:55 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.