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++

Allow SVG text tool to check whether it can edit the layer.

Wolthera van Hövell4ddea07e2e8c
diff --git a/libs/ui/tool/kis_tool.cc b/libs/ui/tool/kis_tool.cc
index 445cbc5ba2..d470d405c3 100644
--- a/libs/ui/tool/kis_tool.cc
+++ b/libs/ui/tool/kis_tool.cc
@@ -676,18 +676,7 @@ bool KisTool::nodeEditable()
if (!nodeEditable) {
KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
- QString message;
- if (!node->visible() && node->userLocked()) {
- message = i18n("Layer is locked and invisible.");
- } else if (node->userLocked()) {
- message = i18n("Layer is locked.");
- } else if(!node->visible()) {
- message = i18n("Layer is invisible.");
- } else if (blockedNoIndirectPainting) {
- message = i18n("Layer can be painted in Wash Mode only.");
- } else {
- message = i18n("Group not editable.");
- }
+ QString message = KisToolUtils::nodeEditableMessage(node, blockedNoIndirectPainting);
kiscanvas->viewManager()->showFloatingMessage(message, KisIconUtils::loadIcon("object-locked"));
}
return nodeEditable;
diff --git a/libs/ui/tool/kis_tool_utils.cpp b/libs/ui/tool/kis_tool_utils.cpp
index 602d0dddcb..40c65732ac 100644
--- a/libs/ui/tool/kis_tool_utils.cpp
+++ b/libs/ui/tool/kis_tool_utils.cpp
@@ -435,4 +435,24 @@ namespace KisToolUtils {
m_tool->action("movetool-move-left-more")->setEnabled(value);
m_tool->action("movetool-move-right-more")->setEnabled(value);
}
+
+ QString nodeEditableMessage(KisNodeSP node, bool blockedNoIndirectPainting)
+ {
+ QString message;
+ if (!node->isEditable(true) || blockedNoIndirectPainting) {
+ if (!node->visible() && node->userLocked()) {
+ message = i18n("Layer is locked and invisible.");
+ } else if (node->userLocked()) {
+ message = i18n("Layer is locked.");
+ } else if(!node->visible()) {
+ message = i18n("Layer is invisible.");
+ } else if (blockedNoIndirectPainting) {
+ message = i18n("Layer can be painted in Wash Mode only.");
+ } else {
+ message = i18n("Group not editable.");
+ }
+ }
+ return message;
+ }
+
}
diff --git a/libs/ui/tool/kis_tool_utils.h b/libs/ui/tool/kis_tool_utils.h
index de613cd56b..9f2242d1c6 100644
--- a/libs/ui/tool/kis_tool_utils.h
+++ b/libs/ui/tool/kis_tool_utils.h
@@ -62,6 +62,14 @@ KisNodeSP KRITAUI_EXPORT findNode(KisNodeSP node, const QPoint &point, bool whol
KisNodeList KRITAUI_EXPORT findNodes(KisNodeSP node, const QPoint &point, bool wholeGroup,
bool includeGroups = true, bool editableOnly = true);
+/**
+ * @brief nodeEditableMessage
+ * @param node -- active node.
+ * @param blockedNoIndirectPainting -- whether editing is blocked due no-indirect painting being possible.
+ * @return the message for why the node is not editable. Will return empty if it is editable after all.
+ */
+QString KRITAUI_EXPORT nodeEditableMessage(KisNodeSP node, bool blockedNoIndirectPainting = false);
+
/**
* @brief shapeHoverInfoCrossLayer
* get hover info of shapes on all layers.
diff --git a/plugins/tools/svgtexttool/SvgTextTool.cpp b/plugins/tools/svgtexttool/SvgTextTool.cpp
index 35d8319754..c5f78386e9 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.cpp
+++ b/plugins/tools/svgtexttool/SvgTextTool.cpp
@@ -634,6 +634,20 @@ void SvgTextTool::slotUpdateTypeSettingMode()
slotTextTypeUpdated();
}
+bool SvgTextTool::nodeEditable()
+{
+ KisNodeSP node = canvas()->resourceManager()->resource(KoCanvasResource::CurrentKritaNode).value<KisNodeWSP>();
+ if (!node->isEditable(true)) {
+ KisCanvas2 * kiscanvas = static_cast<KisCanvas2*>(canvas());
+ if (kiscanvas) {
+ QString message = KisToolUtils::nodeEditableMessage(node);
+ kiscanvas->viewManager()->showFloatingMessage(message, KisIconUtils::loadIcon("object-locked"));
+ }
+ return false;
+ }
+ return true;
+}
+
QRectF SvgTextTool::decorationsRect() const
{
QRectF rect;
@@ -767,6 +781,11 @@ void SvgTextTool::mousePressEvent(KoPointerEvent *event)
mouseMoveEvent(event);
}
+ if (!nodeEditable()) {
+ event->accept();
+ return;
+ }
+
KoSvgTextShape *selectedShape = this->selectedShape();
if (selectedShape) {
diff --git a/plugins/tools/svgtexttool/SvgTextTool.h b/plugins/tools/svgtexttool/SvgTextTool.h
index 8e7a0c9049..3face95d7f 100644
--- a/plugins/tools/svgtexttool/SvgTextTool.h
+++ b/plugins/tools/svgtexttool/SvgTextTool.h
@@ -105,6 +105,13 @@ private:
void addMappedAction(KisSignalMapper* mapper, const QString &actionName, const int value, QActionGroup *group = nullptr);
+ /**
+ * @brief nodeEditable
+ * @see nodeEditable in KisTool.
+ * @return whether the current Node is editable. If not, it'll display an oncanvas message.
+ */
+ bool nodeEditable();
+
private Q_SLOTS:
void showEditor();