Krita Source Code Documentation
Loading...
Searching...
No Matches
View.cpp
Go to the documentation of this file.
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
9#include <KoPattern.h>
10#include <KoAbstractGradient.h>
11#include <kis_paintop_preset.h>
12#include <KisView.h>
13#include <KisViewManager.h>
14#include <kis_node_manager.h>
18#include <kis_paintop_box.h>
19#include <KisMainWindow.h>
20#include <KoCanvasBase.h>
21#include <KoToolProxy.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
39
40 void reconnect(View *self)
41 {
42 // View::setDocument() can replace the wrapped KisView.
43 if (toolProxy) {
44 QObject::disconnect(toolProxy, SIGNAL(toolChanged(QString)), self, SIGNAL(currentToolChanged(QString)));
45 toolProxy.clear();
46 }
47
48 if (resourceProvider) {
49 QObject::disconnect(resourceProvider, SIGNAL(sigPaintOpPresetChanged(KisPaintOpPresetSP)), self, SIGNAL(currentBrushPresetChanged()));
50 QObject::disconnect(resourceProvider, SIGNAL(sigFGColorChanged(KoColor)), self, SIGNAL(foregroundColorChanged()));
51 QObject::disconnect(resourceProvider, SIGNAL(sigBGColorChanged(KoColor)), self, SIGNAL(backgroundColorChanged()));
52 resourceProvider.clear();
53 }
54
55 if (!view) {
56 return;
57 }
58
59 resourceProvider = view->resourceProvider();
60 if (resourceProvider) {
61 QObject::connect(resourceProvider, SIGNAL(sigPaintOpPresetChanged(KisPaintOpPresetSP)), self, SIGNAL(currentBrushPresetChanged()));
62 QObject::connect(resourceProvider, SIGNAL(sigFGColorChanged(KoColor)), self, SIGNAL(foregroundColorChanged()));
63 QObject::connect(resourceProvider, SIGNAL(sigBGColorChanged(KoColor)), self, SIGNAL(backgroundColorChanged()));
64 }
65
66 KoCanvasBase *canvasBase = view->canvasBase();
67 if (!canvasBase) {
68 return;
69 }
70
71 toolProxy = canvasBase->toolProxy();
72 if (toolProxy) {
73 QObject::connect(toolProxy, SIGNAL(toolChanged(QString)), self, SIGNAL(currentToolChanged(QString)));
74 }
75 }
76};
77
78View::View(KisView* view, QObject *parent)
79 : QObject(parent)
80 , d(new Private)
81{
82 d->view = view;
83 d->reconnect(this);
84}
85
87{
88 delete d;
89}
90
91bool View::operator==(const View &other) const
92{
93 return (d->view == other.d->view);
94}
95
96bool View::operator!=(const View &other) const
97{
98 return !(operator==(other));
99}
100
102{
103 if (!d->view) return 0;
104 KisMainWindow *mainwin = d->view->mainWindow();
105 Window *win = new Window(mainwin);
106 return win;
107}
108
109
111{
112 if (!d->view) return 0;
113 Document *doc = new Document(d->view->document(), false);
114 return doc;
115}
116
118{
119 if (!d->view || !document || !document->document()) return;
120 d->view = d->view->replaceBy(document->document());
121 d->reconnect(this);
122}
123
124bool View::visible() const
125{
126 if (!d->view) return false;
127 return d->view->isVisible();
128}
129
131{
132 if (!d->view) return;
133 KisMainWindow *mainwin = d->view->mainWindow();
134 mainwin->setActiveView(d->view);
135 mainwin->subWindowActivated();
136}
137
139{
140 if (!d->view) return 0;
141 Canvas *c = new Canvas(d->view->canvasBase());
142 return c;
143}
144
146{
147 return d->view;
148}
149
151{
152 if (!d->view) return;
153 if (!resource) return;
154
155 KoResourceSP r = resource->resource();
156 if (!r) return;
157
158 if (KoPatternSP pattern = r.dynamicCast<KoPattern>()) {
159 QVariant value = QVariant::fromValue(pattern);
160 d->view->canvasBase()->resourceManager()->setResource(KoCanvasResource::CurrentPattern, value);
161 } else if (KoAbstractGradientSP gradient = r.dynamicCast<KoAbstractGradient>()) {
162 QVariant value = QVariant::fromValue(gradient);
163 d->view->canvasBase()->resourceManager()->setResource(KoCanvasResource::CurrentGradient, value);
164 } else if (KoResourceSP preset = r.dynamicCast<KisPaintOpPreset>()) {
165 d->view->viewManager()->paintOpBox()->resourceSelected(preset);
166 }
167}
168
169
171{
172 if (!d->view) return 0;
173 return new ManagedColor(d->view->resourceProvider()->fgColor());
174}
175
177{
178 if (!d->view) return;
179 d->view->resourceProvider()->setFGColor(color->color());
180}
181
183{
184 if (!d->view) return 0;
185 return new ManagedColor(d->view->resourceProvider()->bgColor());
186}
187
189{
190 if (!d->view) return;
191 d->view->resourceProvider()->setBGColor(color->color());
192}
193
195{
196 if (!d->view) return 0;
197 KoResourceSP preset = d->view->resourceProvider()->currentPreset();
198 if (!preset) return 0;
199 return new Resource(preset, ResourceType::PaintOpPresets);
200}
201
203{
204 activateResource(resource);
205}
206
208{
209 if (!d->view) return 0;
210 return new Resource(d->view->resourceProvider()->currentPattern(), ResourceType::Patterns);
211}
212
214{
215 activateResource(resource);
216}
217
219{
220 if (!d->view) return 0;
221 return new Resource(d->view->resourceProvider()->currentGradient(), ResourceType::Gradients);
222}
223
225{
226 activateResource(resource);
227}
228
230{
231 if (!d->view) return "";
232 return d->view->resourceProvider()->currentCompositeOp();
233}
234
235void View::setCurrentBlendingMode(const QString &blendingMode)
236{
237 if (!d->view) return;
238 d->view->resourceProvider()->setCurrentCompositeOp(blendingMode);
239}
240
241float View::HDRExposure() const
242{
243 if (!d->view) return 0.0;
244 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
245 return iface->currentExposure();
246}
247
248void View::setHDRExposure(float exposure)
249{
250 if (!d->view) return;
251 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
252 iface->setCurrentExposure(exposure);
253}
254
255float View::HDRGamma() const
256{
257 if (!d->view) return 0.0;
258 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
259 return iface->currentGamma();
260}
261
262void View::setHDRGamma(float gamma)
263{
264 if (!d->view) return;
265 KisExposureGammaCorrectionInterface *iface = d->view->canvasBase()->exposureGammaCorrectionInterface();
266 return iface->setCurrentGamma(gamma);
267}
268
270{
271 if (!d->view) return 0.0;
272 return d->view->resourceProvider()->opacity();
273}
274
275void View::setPaintingOpacity(qreal opacity)
276{
277 if (!d->view) return;
278 d->view->resourceProvider()->setOpacity(opacity);
279}
280
281qreal View::brushSize() const
282{
283 if (!d->view) return 0.0;
284 return d->view->resourceProvider()->size();
285}
286
287void View::setBrushSize(qreal brushSize)
288{
289 if (!d->view) return;
290 d->view->resourceProvider()->setSize(brushSize);
291}
292
293qreal View::brushFade() const
294{
295 if (!d->view) return 0.0;
296 return d->view->resourceProvider()->fade();
297}
298
299void View::setBrushFade(qreal brushFade)
300{
301 if (!d->view) return;
302 d->view->resourceProvider()->setFade(brushFade);
303}
304
306{
307 if (!d->view) return 0.0;
308 return d->view->resourceProvider()->brushRotation();
309}
310
311void View::setBrushRotation(qreal brushRotation)
312{
313 if (!d->view) return;
314 d->view->resourceProvider()->setBrushRotation(brushRotation);
315}
316
318{
319 if (!d->view) return 0.0;
320 return d->view->resourceProvider()->flow();
321}
322
323void View::setPaintingFlow(qreal flow)
324{
325 if (!d->view) return;
326 d->view->resourceProvider()->setFlow(flow);
327}
328
329qreal View::patternSize() const
330{
331 if (!d->view) return 0.0;
332 return d->view->resourceProvider()->patternSize();
333}
334
335void View::setPatternSize(qreal size)
336{
337 if (!d->view) return;
338 d->view->resourceProvider()->setPatternSize(size);
339}
340
342{
343 if (!d->view) {
344 return false;
345 }
346 return d->view->resourceProvider()->eraserMode();
347}
348
350{
351 if (!d->view) {
352 return;
353 }
354 d->view->resourceProvider()->setEraserMode(value);
355}
356
358{
359 if (!d->view) {
360 return false;
361 }
362 return d->view->resourceProvider()->globalAlphaLock();
363}
364
366{
367 if (!d->view) {
368 return;
369 }
370 d->view->resourceProvider()->setGlobalAlphaLock(value);
371}
372
374{
375 if (!d->view) {
376 return false;
377 }
378 return d->view->resourceProvider()->disablePressure();
379}
380
382{
383 if (!d->view) {
384 return;
385 }
386 d->view->resourceProvider()->setDisablePressure(value);
387}
388
389
391{
392 if (!d->view) return QList<Node *>();
393 if (!d->view->viewManager()) return QList<Node *>();
394 if (!d->view->viewManager()->nodeManager()) return QList<Node *>();
395
396 KisNodeList selectedNodes = d->view->viewManager()->nodeManager()->selectedNodes();
398}
399
400void View::showFloatingMessage(const QString &message, const QIcon& icon, int timeout, int priority)
401{
402 if (!d->view) return;
403
405 p = static_cast<KisFloatingMessage::Priority>(priority);
406
407 d->view->showFloatingMessage(message, icon, timeout, p);
408}
409
411{
412 if (!d->view->document()) return QTransform();
413 return d->view->canvasBase()->coordinatesConverter()->documentToFlakeTransform().inverted();
414}
415
417{
418 if (!d->view->document()) return QTransform();
419 return d->view->canvasBase()->coordinatesConverter()->flakeToWidgetTransform();
420}
421
423{
424 if (!d->view->document()) return QTransform();
425
426 const KisCoordinatesConverter* coordinatesConverter(d->view->canvasBase()->coordinatesConverter());
427 QTransform imageToFlakeTransform = coordinatesConverter->imageToDocumentTransform() * coordinatesConverter->documentToFlakeTransform();
428
429 return imageToFlakeTransform.inverted();
430}
float value(const T *src, size_t ch)
const Params2D p
Main window for Krita.
void setActiveView(KisView *view)
Set the active view, this will update the undo/redo actions.
virtual KoToolProxy * toolProxy() const =0
Write API docs here.
Definition KoPattern.h:21
The ManagedColor class is a class to handle colors that are color managed. A managed color is a color...
KoColor color() const
KoResourceSP resource() const
Definition Resource.cpp:116
Definition View.h:25
~View() override
Definition View.cpp:86
void setBrushRotation(qreal brushRotation)
set the current rotation for brush tip
Definition View.cpp:311
void backgroundColorChanged()
float HDRExposure() const
Definition View.cpp:241
bool eraserMode() const
return current eraser mode status (active/inactive)
Definition View.cpp:341
void setHDRGamma(float gamma)
set the current HDR Gamma value
Definition View.cpp:262
View(KisView *view, QObject *parent=0)
Definition View.cpp:78
bool globalAlphaLock() const
return current global alpha lock mode (active/inactive)
Definition View.cpp:357
bool visible() const
Definition View.cpp:124
qreal patternSize() const
return the current pattern size for brush
Definition View.cpp:329
void setBackGroundColor(ManagedColor *color)
Definition View.cpp:188
void setBrushSize(qreal brushSize)
set the current size for brush
Definition View.cpp:287
void setCurrentBrushPreset(Resource *resource)
set the current selected preset
Definition View.cpp:202
Private *const d
Definition View.h:390
void setDisablePressure(bool value)
set current disabled pressure status
Definition View.cpp:381
void setGlobalAlphaLock(bool value)
set current global alpha lock mode active/inactive
Definition View.cpp:365
qreal paintingFlow() const
return the current flow for brush
Definition View.cpp:317
void setDocument(Document *document)
Definition View.cpp:117
void setCurrentPattern(Resource *resource)
set the current selected pattern
Definition View.cpp:213
float HDRGamma() const
Definition View.cpp:255
ManagedColor * foregroundColor() const
Definition View.cpp:170
friend class Window
Definition View.h:383
void foregroundColorChanged()
Resource * currentPattern() const
return the current selected pattern
Definition View.cpp:207
void setCurrentBlendingMode(const QString &blendingMode)
set the current blending mode for brush
Definition View.cpp:235
ManagedColor * backgroundColor() const
backgroundColor allows access to the currently active background color. This is nominally per canvas/...
Definition View.cpp:182
QTransform flakeToCanvasTransform() const
flakeToCanvasTransform The transformation of the canvas relative to the view without rotation and mir...
Definition View.cpp:416
QString currentBlendingMode() const
return the current blending mode for brush
Definition View.cpp:229
void currentToolChanged(const QString &toolId)
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:400
void setPaintingOpacity(qreal opacity)
set the current opacity for brush
Definition View.cpp:275
QTransform flakeToImageTransform() const
flakeToImageTransform The transformation of the image relative to the view without rotation and mirro...
Definition View.cpp:422
qreal paintingOpacity() const
return the current opacity for brush
Definition View.cpp:269
void activateResource(Resource *resource)
activateResource activates the given resource.
Definition View.cpp:150
Canvas * canvas() const
Definition View.cpp:138
void setHDRExposure(float exposure)
set the current HDR Exposure value
Definition View.cpp:248
qreal brushRotation() const
return the current rotation for brush tip
Definition View.cpp:305
KisView * view()
Definition View.cpp:145
void setPatternSize(qreal size)
set the current pattern size value for brush
Definition View.cpp:335
QList< Node * > selectedNodes() const
Definition View.cpp:390
qreal brushFade() const
return the current fade for brush
Definition View.cpp:293
Window * window() const
Definition View.cpp:101
Resource * currentBrushPreset() const
return the current selected preset
Definition View.cpp:194
void setPaintingFlow(qreal flow)
set the current flow value for brush
Definition View.cpp:323
bool operator==(const View &other) const
Definition View.cpp:91
QTransform flakeToDocumentTransform() const
flakeToDocumentTransform The transformation of the document relative to the view without rotation and...
Definition View.cpp:410
void setEraserMode(bool value)
set current eraser active/inactive
Definition View.cpp:349
Resource * currentGradient() const
return the current selected gradient
Definition View.cpp:218
void setVisible()
Definition View.cpp:130
bool operator!=(const View &other) const
Definition View.cpp:96
void setBrushFade(qreal brushFade)
set the current fade for brush
Definition View.cpp:299
void setForeGroundColor(ManagedColor *color)
Definition View.cpp:176
void currentBrushPresetChanged()
void setCurrentGradient(Resource *resource)
set the current selected gradient
Definition View.cpp:224
Document * document() const
Definition View.cpp:110
qreal brushSize() const
return the current size for brush
Definition View.cpp:281
bool disablePressure() const
return current disabled pressure status
Definition View.cpp:373
QList< Node * > createNodeList(KisNodeList kisnodes, KisImageWSP image)
const QString Patterns
const QString Gradients
const QString PaintOpPresets
virtual qreal currentGamma() const =0
virtual void setCurrentGamma(qreal value)=0
virtual void setCurrentExposure(qreal value)=0
virtual qreal currentExposure() const =0
QPointer< KoToolProxy > toolProxy
Definition View.cpp:37
QPointer< KisView > view
Definition View.cpp:36
QPointer< KisCanvasResourceProvider > resourceProvider
Definition View.cpp:38
void reconnect(View *self)
Definition View.cpp:40