Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_canvas_resource_provider.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006 Boudewijn Rempt <boud@valdyas.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
7
8#include <QPainter>
9
10#include <KoCanvasBase.h>
11#include <KoID.h>
13#include <KoColorProfile.h>
19#include <KoResource.h>
21
22#include <resources/KoPattern.h>
23#include <kis_paint_device.h>
25#include <kis_image.h>
26#include <kis_group_layer.h>
30
31#include "kis_config.h"
32#include "KisViewManager.h"
33#include "canvas/kis_canvas2.h"
34#include <KoUnit.h>
35
36
38 : m_view(view),
39 m_presetShadowUpdater(view)
40{
41}
42
44{
45 disconnect(); // in case Qt gets confused
46}
47
52
82
83
88
90{
92 if (c.isValid()) {
93 return c.value<KoColor>();
94 }
95 else {
96 return KoColor();
97 }
98}
99
101{
103 if (c.isValid()) {
104 return c.value<KoColor>();
105 }
106 else {
107 return KoColor();
108 }
109}
110
112{
114 if (c.isValid()) {
115 return c.value<QList<KoColor>>();
116 }
117 else {
118 return QList<KoColor>();
119 }
120}
121
123{
124 QVariant v;
125 v.setValue(colors);
127}
128
130{
131 return static_cast<float>(m_resourceManager->resource(KoCanvasResource::HdrExposure).toDouble());
132}
133
135{
136 m_resourceManager->setResource(KoCanvasResource::HdrExposure, static_cast<double>(exposure));
137}
138
140{
141 return static_cast<float>(m_resourceManager->resource(KoCanvasResource::HdrGamma).toDouble());
142}
143
145{
146 m_resourceManager->setResource(KoCanvasResource::HdrGamma, static_cast<double>(gamma));
147}
148
149
159
169
174
179
189
194
200
202{
203 if (!preset) return;
204 QVariant v;
205 v.setValue(preset);
207
208 Q_EMIT sigPaintOpPresetChanged(preset);
209}
210
216
218{
219 if (!preset) return;
220
221 dbgUI << "setPreviousPaintOpPreset" << preset->paintOp();
222
223 QVariant v;
224 v.setValue(preset);
226}
227
229{
230 KoPatternSP pattern = res.dynamicCast<KoPattern>();
231 QVariant v;
232 v.setValue(pattern);
234 Q_EMIT sigPatternChanged(pattern);
235}
236
238{
239
240 KoAbstractGradientSP gradient = res.dynamicCast<KoAbstractGradient>();
241 QVariant v;
242 v.setValue(gradient);
244 Q_EMIT sigGradientChanged(gradient);
245}
246
247
249{
250 QVariant v;
251 v.setValue(c);
253 Q_EMIT sigBGColorChanged(c);
254}
255
257{
258 m_fGChanged = true;
259
260 QVariant v;
261 v.setValue(c);
263 Q_EMIT sigFGColorChanged(c);
264}
265
270
275
283
284
286{
287 if (KisImageWSP image = m_view->image()) {
288 float fw = image->width() / image->xRes();
289 float fh = image->height() / image->yRes();
290
291 QSizeF postscriptSize(fw, fh);
293 }
294}
295
297{
298 KisImageWSP image = m_view->image();
300
301 if(!image || !canvas) return;
302
303 // update KoUnit value for the document
305 setResource(KoCanvasResource::Unit, canvas->unit());
306
307 qreal scaleX, scaleY;
308 canvas->coordinatesConverter()->imageScale(&scaleX, &scaleY);
309
310 Q_EMIT sigOnScreenResolutionChanged(scaleX, scaleY);
311}
312
314{
315 switch (key) {
317 m_fGChanged = true;
318 Q_EMIT sigFGColorChanged(res.value<KoColor>());
319 break;
321 Q_EMIT sigBGColorChanged(res.value<KoColor>());
322 break;
324 Q_EMIT sigPatternChanged(res.value<KoPatternSP>());
325 break;
327 Q_EMIT sigGradientChanged(res.value<KoAbstractGradientSP>());
328 break;
330 Q_EMIT sigNodeChanged(currentNode());
331 break;
334 break;
336 {
337 Q_EMIT sigOpacityChanged(res.toDouble());
338 }
339 default:
340 ;
341 // Do nothing
342 };
343}
344
346{
348 QVariant::fromValue(compositeOp));
349}
350
355
360
366
368{
369 if (m_fGChanged) {
370 Q_EMIT sigFGColorUsed(fgColor());
371 m_fGChanged = false;
372 }
373}
374
385
392
397
403
409
414
420
425
431
435
441
442
443
447
453
454
458
464
465
469
473
477
478
479
484
489
494
499
504
509
514
519
524
529
534
539
544
549
555
560
565
570
float value(const T *src, size_t ch)
qreal v
const QString COMPOSITE_OVER
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KoCanvasResourceProvider * resourceManager()
void notifyLoadingWorkspace(KisWorkspaceResourceSP workspace)
Notify that the workspace is loaded and settings can be read.
void sigOnScreenResolutionChanged(qreal scaleX, qreal scaleY)
void sigNodeChanged(const KisNodeSP)
void notifySavingWorkspace(KisWorkspaceResourceSP workspace)
Notify that the workspace is saved and settings should be saved to it.
void slotPatternActivated(KoResourceSP pattern)
void sigPaintOpPresetChanged(const KisPaintOpPresetSP)
void sigPatternChanged(KoPatternSP)
void sigFGColorChanged(const KoColor &)
void slotGradientActivated(KoResourceSP gradient)
KisPaintOpPresetSP currentPreset() const
KoCanvasResourceProvider * m_resourceManager
KisPaintOpPresetSP previousPreset() const
void slotGamutMaskActivated(KoGamutMaskSP mask)
void sigBGColorChanged(const KoColor &)
void sigFGColorUsed(const KoColor &)
KisPresetShadowUpdater m_presetShadowUpdater
void setTextPropertyData(KoSvgTextPropertyData data)
void slotCanvasResourceChanged(int key, const QVariant &res)
void sigSavingWorkspace(KisWorkspaceResourceSP workspace)
KoAbstractGradientSP currentGradient() const
void setPreviousPaintOpPreset(const KisPaintOpPresetSP preset)
void setMirrorVertical(bool mirrorVertical)
void setMirrorHorizontal(bool mirrorHorizontal)
void setColorHistory(const QList< KoColor > &colors)
void setResourceManager(KoCanvasResourceProvider *resourceManager)
void sigLoadingWorkspace(KisWorkspaceResourceSP workspace)
KisCanvasResourceProvider(KisViewManager *view)
void slotNodeActivated(const KisNodeSP node)
void sigGamutMaskChanged(KoGamutMaskSP mask)
void setPaintOpPreset(const KisPaintOpPresetSP preset)
void sigGradientChanged(KoAbstractGradientSP)
KoSvgTextPropertyData textPropertyData() const
void setCurrentCompositeOp(const QString &compositeOp)
KisCanvas2 * canvasBase() const
Return the canvas base class.
KisNodeSP activeNode()
KisImageWSP image() const
Return the image this view is displaying.
virtual KoUnit unit() const =0
void setResource(int key, const QVariant &value)
Write API docs here.
Definition KoPattern.h:21
#define dbgUI
Definition kis_debug.h:52
KisWeakSharedPtr< KisNode > KisNodeWSP
Definition kis_types.h:87
@ EffectiveZoom
-Used only by painting tools for non-displaying purposes
@ PageSize
The size of the (current) page in postscript points.
@ EffectivePhysicalZoom
-Used by tool for displaying purposes
@ SvgTextPropertyData
KoSvgTextPropertyDataStruct.
@ Unit
The unit of this canvas.
@ BackgroundColor
The active background color selected for this canvas.
@ ForegroundColor
The active foreground color selected for this canvas.
@ ColorHistory
Color history if not per document.
static KoColorSpaceRegistry * instance()
The KoSvgTextPropertyData struct.