Krita

PaintingResources.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Scott Petrovic <scottpetrovic@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#include "PaintingResources.h"
7
8#include "KisView.h"
9#include "KisPart.h"
10#include "kis_canvas_resource_provider.h"
11#include "KisViewManager.h"
12#include "KisMainWindow.h"
13#include "kis_image.h"
14#include "KisToolShapeUtils.h"
15
16
17const QStringList StrokeStyle = {
18 "None", // 0 = KisToolShapeUtils::StrokeStyle::StrokeStyleNone
19 "ForegroundColor", // KisToolShapeUtils::StrokeStyle::StrokeStyleForeground
20 "BackgroundColor" // KisToolShapeUtils::StrokeStyle::StrokeStyleBackground
21};
22
23const QStringList FillStyle = {
24 "None", // 0 = KisToolShapeUtils::FillStyle::FillStyleNone
25 "ForegroundColor", // KisToolShapeUtils::FillStyle::FillStyleForegroundColor
26 "BackgroundColor", // KisToolShapeUtils::FillStyle::FillStyleBackgroundColor
27 "Pattern" // KisToolShapeUtils::FillStyle::FillStylePattern
28};
29
30KisFigurePaintingToolHelper PaintingResources::createHelper(KisImageWSP image,
31 const QString strokeStyleString,
32 const QString fillStyleString)
33{
34 // need to grab the resource provider
35 KisView *activeView = KisPart::instance()->currentMainwindow()->activeView();
36 KoCanvasResourceProvider *resourceManager = activeView->viewManager()->canvasResourceProvider()->resourceManager();
37
38 // grab the image and current layer
39 KisNodeSP node = activeView->currentNode();
40
41 int strokeIndex = StrokeStyle.indexOf(strokeStyleString);
42 if (strokeIndex == -1) {
43 dbgScript << "Script tried to paint with invalid strokeStyle" << strokeStyleString << ", ignoring and using" << defaultStrokeStyle << ".";
44 strokeIndex = StrokeStyle.indexOf(defaultStrokeStyle);
45 if (strokeIndex == -1) {
46 warnScript << "PaintingResources::createHelper(): defaultStrokeStyle" << defaultStrokeStyle << "is invalid!";
47 strokeIndex = 1;
48 }
49 }
50 KisToolShapeUtils::StrokeStyle strokeStyle = (KisToolShapeUtils::StrokeStyle) strokeIndex;
51
52 int fillIndex = FillStyle.indexOf(fillStyleString);
53 if (fillIndex == -1) {
54 dbgScript << "Script tried to paint with invalid fillStyle" << fillStyleString << ", ignoring and using" << defaultFillStyle << ".";
55 fillIndex = FillStyle.indexOf(defaultFillStyle);
56 if (fillIndex == -1) {
57 warnScript << "PaintingResources::createHelper(): defaultFillStyle" << defaultFillStyle << " is invalid!";
58 fillIndex = 0;
59 }
60 }
61 KisToolShapeUtils::FillStyle fillStyle = (KisToolShapeUtils::FillStyle) fillIndex;
62
63 const KUndo2MagicString name = kundo2_i18n("Scripted Brush Stroke");
64 KisFigurePaintingToolHelper helper(
65 name,
66 image,
67 node, resourceManager,
68 strokeStyle,
69 fillStyle
70 );
71
72 return helper;
73}
QString name(StandardAction id)
qsizetype indexOf(const QRegularExpression &re, qsizetype from) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:09 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.