Krita

View.cpp
1/*
2 * SPDX-FileCopyrightText: 2016 Boudewijn Rempt <boud@valdyas.org>
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
34struct View::Private {
35 Private() {}
37};
38
39View::View(KisView* view, QObject *parent)
40 : QObject(parent)
41 , d(new Private)
42{
43 d->view = view;
44}
45
46View::~View()
47{
48 delete d;
49}
50
51bool View::operator==(const View &other) const
52{
53 return (d->view == other.d->view);
54}
55
56bool 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
78{
79 if (!d->view || !document || !document->document()) return;
80 d->view = d->view->replaceBy(document->document());
81}
82
83bool 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
104KisView *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 (KoPatternSP pattern = r.dynamicCast<KoPattern>()) {
118 QVariant value = QVariant::fromValue(pattern);
119 d->view->canvasBase()->resourceManager()->setResource(KoCanvasResource::CurrentPattern, value);
120 } else if (KoAbstractGradientSP gradient = r.dynamicCast<KoAbstractGradient>()) {
121 QVariant value = QVariant::fromValue(gradient);
122 d->view->canvasBase()->resourceManager()->setResource(KoCanvasResource::CurrentGradient, value);
123 } else if (KoResourceSP preset = r.dynamicCast<KisPaintOpPreset>()) {
124 d->view->viewManager()->paintOpBox()->resourceSelected(preset);
125 }
126}
127
128
130{
131 if (!d->view) return 0;
132 return new ManagedColor(d->view->resourceProvider()->fgColor());
133}
134
135void View::setForeGroundColor(ManagedColor *color)
136{
137 if (!d->view) return;
138 d->view->resourceProvider()->setFGColor(color->color());
139}
140
142{
143 if (!d->view) return 0;
144 return new ManagedColor(d->view->resourceProvider()->bgColor());
145}
146
147void View::setBackGroundColor(ManagedColor *color)
148{
149 if (!d->view) return;
150 d->view->resourceProvider()->setBGColor(color->color());
151}
152
154{
155 if (!d->view) return 0;
156 return new Resource(d->view->resourceProvider()->currentPreset(), ResourceType::PaintOpPresets);
157}
158
160{
161 activateResource(resource);
162}
163
165{
166 if (!d->view) return 0;
167 return new Resource(d->view->resourceProvider()->currentPattern(), ResourceType::Patterns);
168}
169
171{
172 activateResource(resource);
173}
174
176{
177 if (!d->view) return 0;
178 return new Resource(d->view->resourceProvider()->currentGradient(), ResourceType::Gradients);
179}
180
182{
183 activateResource(resource);
184}
185
187{
188 if (!d->view) return "";
189 return d->view->resourceProvider()->currentCompositeOp();
190}
191
192void View::setCurrentBlendingMode(const QString &blendingMode)
193{
194 if (!d->view) return;
195 d->view->resourceProvider()->setCurrentCompositeOp(blendingMode);
196}
197
198float View::HDRExposure() const
199{
200 if (!d->view) return 0.0;
201 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
202 return iface->currentExposure();
203}
204
205void View::setHDRExposure(float exposure)
206{
207 if (!d->view) return;
208 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
209 iface->setCurrentExposure(exposure);
210}
211
212float View::HDRGamma() const
213{
214 if (!d->view) return 0.0;
215 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
216 return iface->currentGamma();
217}
218
219void View::setHDRGamma(float gamma)
220{
221 if (!d->view) return;
222 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
223 return iface->setCurrentGamma(gamma);
224}
225
227{
228 if (!d->view) return 0.0;
229 return d->view->resourceProvider()->opacity();
230}
231
232void View::setPaintingOpacity(qreal opacity)
233{
234 if (!d->view) return;
235 d->view->resourceProvider()->setOpacity(opacity);
236}
237
238qreal View::brushSize() const
239{
240 if (!d->view) return 0.0;
241 return d->view->resourceProvider()->size();
242}
243
244void View::setBrushSize(qreal brushSize)
245{
246 if (!d->view) return;
247 d->view->resourceProvider()->setSize(brushSize);
248}
249
251{
252 if (!d->view) return 0.0;
253 return d->view->resourceProvider()->brushRotation();
254}
255
256void View::setBrushRotation(qreal brushRotation)
257{
258 if (!d->view) return;
259 d->view->resourceProvider()->setBrushRotation(brushRotation);
260}
261
263{
264 if (!d->view) return 0.0;
265 return d->view->resourceProvider()->flow();
266}
267
268void View::setPaintingFlow(qreal flow)
269{
270 if (!d->view) return;
271 d->view->resourceProvider()->setFlow(flow);
272}
273
274qreal View::patternSize() const
275{
276 if (!d->view) return 0.0;
277 return d->view->resourceProvider()->patternSize();
278}
279
280void View::setPatternSize(qreal size)
281{
282 if (!d->view) return;
283 d->view->resourceProvider()->setPatternSize(size);
284}
285
287{
288 if (!d->view) {
289 return false;
290 }
291 return d->view->resourceProvider()->eraserMode();
292}
293
294void View::setEraserMode(bool value)
295{
296 if (!d->view) {
297 return;
298 }
299 d->view->resourceProvider()->setEraserMode(value);
300}
301
303{
304 if (!d->view) {
305 return false;
306 }
307 return d->view->resourceProvider()->globalAlphaLock();
308}
309
311{
312 if (!d->view) {
313 return;
314 }
315 d->view->resourceProvider()->setGlobalAlphaLock(value);
316}
317
319{
320 if (!d->view) {
321 return false;
322 }
323 return d->view->resourceProvider()->disablePressure();
324}
325
327{
328 if (!d->view) {
329 return;
330 }
331 d->view->resourceProvider()->setDisablePressure(value);
332}
333
334
336{
337 if (!d->view) return QList<Node *>();
338 if (!d->view->viewManager()) return QList<Node *>();
339 if (!d->view->viewManager()->nodeManager()) return QList<Node *>();
340
341 KisNodeList selectedNodes = d->view->viewManager()->nodeManager()->selectedNodes();
342 return LibKisUtils::createNodeList(selectedNodes, d->view->image());
343}
344
345void View::showFloatingMessage(const QString &message, const QIcon& icon, int timeout, int priority)
346{
347 if (!d->view) return;
348
349 KisFloatingMessage::Priority p;
350 p = static_cast<KisFloatingMessage::Priority>(priority);
351
352 d->view->showFloatingMessage(message, icon, timeout, p);
353}
354
356{
357 if (!d->view->document()) return QTransform();
358 return d->view->canvasBase()->coordinatesConverter()->documentToFlakeTransform().inverted();
359}
360
362{
363 if (!d->view->document()) return QTransform();
364 return d->view->canvasBase()->coordinatesConverter()->flakeToWidgetTransform();
365}
366
368{
369 if (!d->view->document()) return QTransform();
370
371 const KisCoordinatesConverter* coordinatesConverter(d->view->canvasBase()->coordinatesConverter());
372 QTransform imageToFlakeTransform = coordinatesConverter->imageToDocumentTransform() * coordinatesConverter->documentToFlakeTransform();
373
374 return imageToFlakeTransform.inverted();
375}
Canvas wraps the canvas inside a view on an image/document.
Definition Canvas.h:23
The Document class encapsulates a Krita Document/Image.
Definition Document.h:37
The ManagedColor class is a class to handle colors that are color managed.
A Resource represents a gradient, pattern, brush tip, brush preset, palette or workspace definition.
Definition Resource.h:31
View represents one view on a document.
Definition View.h:25
void setBrushRotation(qreal brushRotation)
set the current rotation for brush tip
Definition View.cpp:256
float HDRExposure() const
Definition View.cpp:198
bool eraserMode() const
return current eraser mode status (active/inactive)
Definition View.cpp:286
void setHDRGamma(float gamma)
set the current HDR Gamma value
Definition View.cpp:219
bool globalAlphaLock() const
return current global alpha lock mode (active/inactive)
Definition View.cpp:302
bool visible() const
Definition View.cpp:83
qreal patternSize() const
return the current pattern size for brush
Definition View.cpp:274
void setBrushSize(qreal brushSize)
set the current size for brush
Definition View.cpp:244
void setCurrentBrushPreset(Resource *resource)
set the current selected preset
Definition View.cpp:159
void setDisablePressure(bool value)
set current disabled pressure status
Definition View.cpp:326
void setGlobalAlphaLock(bool value)
set current global alpha lock mode active/inactive
Definition View.cpp:310
qreal paintingFlow() const
return the current flow for brush
Definition View.cpp:262
void setDocument(Document *document)
Reset the view to show document.
Definition View.cpp:77
void setCurrentPattern(Resource *resource)
set the current selected pattern
Definition View.cpp:170
float HDRGamma() const
Definition View.cpp:212
ManagedColor * foregroundColor() const
foregroundColor allows access to the currently active foreground color.
Definition View.cpp:129
Resource * currentPattern() const
return the current selected pattern
Definition View.cpp:164
void setCurrentBlendingMode(const QString &blendingMode)
set the current blending mode for brush
Definition View.cpp:192
ManagedColor * backgroundColor() const
backgroundColor allows access to the currently active background color.
Definition View.cpp:141
QTransform flakeToCanvasTransform() const
flakeToCanvasTransform The transformation of the canvas relative to the view without rotation and mir...
Definition View.cpp:361
QString currentBlendingMode() const
return the current blending mode for brush
Definition View.cpp:186
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:345
void setPaintingOpacity(qreal opacity)
set the current opacity for brush
Definition View.cpp:232
QTransform flakeToImageTransform() const
flakeToImageTransform The transformation of the image relative to the view without rotation and mirro...
Definition View.cpp:367
qreal paintingOpacity() const
return the current opacity for brush
Definition View.cpp:226
void activateResource(Resource *resource)
activateResource activates the given resource.
Definition View.cpp:109
Canvas * canvas() const
Definition View.cpp:97
void setHDRExposure(float exposure)
set the current HDR Exposure value
Definition View.cpp:205
qreal brushRotation() const
return the current rotation for brush tip
Definition View.cpp:250
void setPatternSize(qreal size)
set the current pattern size value for brush
Definition View.cpp:280
QList< Node * > selectedNodes() const
Definition View.cpp:335
Window * window() const
Definition View.cpp:61
Resource * currentBrushPreset() const
return the current selected preset
Definition View.cpp:153
void setPaintingFlow(qreal flow)
set the current flow value for brush
Definition View.cpp:268
QTransform flakeToDocumentTransform() const
flakeToDocumentTransform The transformation of the document relative to the view without rotation and...
Definition View.cpp:355
void setEraserMode(bool value)
set current eraser active/inactive
Definition View.cpp:294
Resource * currentGradient() const
return the current selected gradient
Definition View.cpp:175
void setVisible()
Make the current view visible.
Definition View.cpp:89
void setCurrentGradient(Resource *resource)
set the current selected gradient
Definition View.cpp:181
Document * document() const
Definition View.cpp:70
qreal brushSize() const
return the current size for brush
Definition View.cpp:238
bool disablePressure() const
return current disabled pressure status
Definition View.cpp:318
Window represents one Krita mainwindow.
Definition Window.h:23
QTransform inverted(bool *invertible) const const
QVariant fromValue(T &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:51:16 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.