Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Prevent Python brushstrokes on unpaintable nodes

Freya Lupend0d43089ac09
diff --git a/libs/libkis/Node.cpp b/libs/libkis/Node.cpp
index d6ab5811d3..cac2c181e2 100644
--- a/libs/libkis/Node.cpp
+++ b/libs/libkis/Node.cpp
@@ -68,6 +68,9 @@
#include <kis_layer_utils.h>
#include "PaintingResources.h"
+#include "KisMainWindow.h"
+#include "kis_canvas2.h"
+#include "KoCanvasResourceProvider.h"
struct Node::Private {
@@ -825,8 +828,48 @@ KisNodeSP Node::node() const
return d->node;
}
+QString Node::paintAbility()
+{
+ // Taken from KisTool:nodePaintAbility().
+ KisMainWindow *mainWindow = KisPart::instance()->currentMainwindow();
+ KisCanvas2 *canvas = mainWindow->activeView()->canvasBase();
+ if (canvas->resourceManager()->resource(KoCanvasResource::CurrentPaintOpPreset).isNull()) {
+ return "UNPAINTABLE";
+ }
+
+ if (!d->node) {
+ return "UNPAINTABLE";
+ }
+
+ if (d->node->inherits("KisShapeLayer")) {
+ return "VECTOR";
+ }
+ if (d->node->inherits("KisCloneLayer")) {
+ return "CLONE";
+ }
+ if (d->node->paintDevice()) {
+
+ KisPaintOpPresetSP currentPaintOpPreset = canvas->resourceManager()->resource(KoCanvasResource::CurrentPaintOpPreset).value<KisPaintOpPresetSP>();
+ if (currentPaintOpPreset->paintOp().id() == "mypaintbrush") {
+ const KoColorSpace *colorSpace = d->node->paintDevice()->colorSpace();
+ if (colorSpace->colorModelId() != RGBAColorModelID) {
+ return "MYPAINTBRUSH_UNPAINTABLE";
+ }
+ }
+
+ return "PAINT";
+ }
+
+ return "UNPAINTABLE";
+}
+
void Node::paintLine(const QPointF pointOne, const QPointF pointTwo)
{
+ if (paintAbility() != "PAINT") {
+ dbgScript << "Script attempted to use Node::paintLine() on an unpaintable node, ignoring.";
+ return;
+ }
+
KisPaintInformation pointOneInfo;
pointOneInfo.setPressure(1.0);
pointOneInfo.setPos(pointOne);
@@ -842,6 +885,11 @@ void Node::paintLine(const QPointF pointOne, const QPointF pointTwo)
void Node::paintRectangle(const QRectF &rect)
{
+ if (paintAbility() != "PAINT") {
+ dbgScript << "Script attempted to use Node::paintRectangle() on an unpaintable node, ignoring.";
+ return;
+ }
+
// reference class where this stuff is being done. Maybe can use the "facade" like that does for setup?
// void KisFigurePaintingToolHelper::paintRect(const QRectF &rect)
@@ -852,6 +900,11 @@ void Node::paintRectangle(const QRectF &rect)
void Node::paintPolygon(const QList<QPointF> listPoint)
{
+ if (paintAbility() != "PAINT") {
+ dbgScript << "Script attempted to use Node::paintPolygon() on an unpaintable node, ignoring.";
+ return;
+ }
+
// strategy needs points in vPointF format
QVector<QPointF> points = points.fromList(listPoint);
KisFigurePaintingToolHelper helper = PaintingResources::createHelper(d->image);
@@ -861,6 +914,11 @@ void Node::paintPolygon(const QList<QPointF> listPoint)
void Node::paintEllipse(const QRectF &rect)
{
+ if (paintAbility() != "PAINT") {
+ dbgScript << "Script attempted to use Node::paintEllipse() on an unpaintable node, ignoring.";
+ return;
+ }
+
KisFigurePaintingToolHelper helper = PaintingResources::createHelper(d->image);
helper.paintEllipse(rect);
}
@@ -868,6 +926,11 @@ void Node::paintEllipse(const QRectF &rect)
void Node::paintPath(const QPainterPath &path)
{
+ if (paintAbility() != "PAINT") {
+ dbgScript << "Script attempted to use Node::paintPath() on an unpaintable node, ignoring.";
+ return;
+ }
+
KisFigurePaintingToolHelper helper = PaintingResources::createHelper(d->image);
helper.paintPainterPath(path);
}
diff --git a/libs/libkis/Node.h b/libs/libkis/Node.h
index 10daba42dc..89a6f405e0 100644
--- a/libs/libkis/Node.h
+++ b/libs/libkis/Node.h
@@ -601,6 +601,18 @@ public Q_SLOTS:
*/
void paintPath(const QPainterPath &path);
+ /**
+ * @brief paintAbility can be used to determine whether this node can be painted on with the current brush preset.
+ * @return QString, one of the following:
+ * <ul>
+ * <li>VECTOR - This node is vector-based.</li>
+ * <li>CLONE - This node is a Clone Layer.</li>
+ * <li>PAINT - This node is paintable by the current brush preset.</li>
+ * <li>UNPAINTABLE - This node is not paintable, or a null preset is somehow selected./li>
+ * <li>MYPAINTBRUSH_UNPAINTABLE - This node's non-RGBA colorspace cannot be painted on by the currently selected MyPaint brush.</li>
+ */
+ QString paintAbility();
+
private:
friend class Filter;
diff --git a/plugins/extensions/pykrita/sip/krita/Node.sip b/plugins/extensions/pykrita/sip/krita/Node.sip
index 2e2dd15be2..ce483e4569 100644
--- a/plugins/extensions/pykrita/sip/krita/Node.sip
+++ b/plugins/extensions/pykrita/sip/krita/Node.sip
@@ -87,6 +87,7 @@ public Q_SLOTS:
void paintPolygon(const QList<QPointF> points);
void paintEllipse(const QRectF &rect);
void paintPath(const QPainterPath &path);
+ QString paintAbility();
Q_SIGNALS:
private:
};