[krita/krita/3.2] /: FEATURE: Actions for toggling layer visibility, lock, alpha inherit and alpha lock

Boudewijn Rempt null at kde.org
Thu Jun 8 07:22:37 UTC 2017


Git commit 59f5e1a1e6cc0c89eec57a17998af722f2c971d7 by Boudewijn Rempt.
Committed on 08/06/2017 at 07:22.
Pushed by rempt into branch 'krita/3.2'.

FEATURE: Actions for toggling layer visibility, lock, alpha inherit and alpha lock

CCMAIL:kimageshop at kde.org
BUG:376946

The actions don't have shortcuts by default, but are in the layer
menu.

Patch by Valeriy Malov

M  +48   -0    krita/krita.action
M  +80   -0    libs/ui/kis_node_manager.cpp
M  +5    -0    libs/ui/kis_node_manager.h
M  +5    -0    plugins/dockers/defaultdockers/kis_layer_box.cpp

https://commits.kde.org/krita/59f5e1a1e6cc0c89eec57a17998af722f2c971d7

diff --git a/krita/krita.action b/krita/krita.action
index 77d89a756e6..e8febff4609 100644
--- a/krita/krita.action
+++ b/krita/krita.action
@@ -2264,6 +2264,54 @@
       <isCheckable>true</isCheckable>
       <statusTip></statusTip>
     </Action>
+    <Action name="toggle_layer_lock">
+      <icon>layer-locked</icon>
+      <text>&Lock/unlock layer</text>
+      <whatsThis></whatsThis>
+      <toolTip>Lock/unlock layer</toolTip>
+      <iconText>Lock/unlock layer</iconText>
+      <activationFlags>1000</activationFlags>
+      <activationConditions>0</activationConditions>
+      <shortcut></shortcut>
+      <isCheckable>false</isCheckable>
+      <statusTip></statusTip>
+    </Action>
+    <Action name="toggle_layer_visibility">
+      <icon>visible</icon>
+      <text>Toggle layer &visibility</text>
+      <whatsThis></whatsThis>
+      <toolTip>Toggle layer visibility</toolTip>
+      <iconText>Toggle layer visibility</iconText>
+      <activationFlags>1000</activationFlags>
+      <activationConditions>0</activationConditions>
+      <shortcut></shortcut>
+      <isCheckable>false</isCheckable>
+      <statusTip></statusTip>
+    </Action>
+    <Action name="toggle_layer_alpha_lock">
+      <icon>transparency-locked</icon>
+      <text>Lock/unlock layer &alpha</text>
+      <whatsThis></whatsThis>
+      <toolTip>Lock/unlock layer's alpha</toolTip>
+      <iconText>Lock/unlock layer's alpha</iconText>
+      <activationFlags>1000</activationFlags>
+      <activationConditions>0</activationConditions>
+      <shortcut></shortcut>
+      <isCheckable>false</isCheckable>
+      <statusTip></statusTip>
+    </Action>
+    <Action name="toggle_layer_inherit_alpha">
+      <icon>transparency-enabled</icon>
+      <text>Toggle layer alpha &inheritance</text>
+      <whatsThis></whatsThis>
+      <toolTip>Toggle layer alpha inheritance</toolTip>
+      <iconText>Toggle layer alpha inheritance</iconText>
+      <activationFlags>1000</activationFlags>
+      <activationConditions>0</activationConditions>
+      <shortcut></shortcut>
+      <isCheckable>false</isCheckable>
+      <statusTip></statusTip>
+    </Action>
     <Action name="add_new_paint_layer">
       <icon>paintLayer</icon>
       <text>&Paint Layer</text>
diff --git a/libs/ui/kis_node_manager.cpp b/libs/ui/kis_node_manager.cpp
index e861a0aab57..374e5a1cb84 100644
--- a/libs/ui/kis_node_manager.cpp
+++ b/libs/ui/kis_node_manager.cpp
@@ -343,6 +343,18 @@ void KisNodeManager::setup(KActionCollection * actionCollection, KisActionManage
     action = actionManager->createAction("isolate_layer");
     connect(action, SIGNAL(triggered(bool)), this, SLOT(toggleIsolateMode(bool)));
 
+    action = actionManager->createAction("toggle_layer_lock");
+    connect(action, SIGNAL(triggered()), this, SLOT(toggleLock()));
+
+    action = actionManager->createAction("toggle_layer_visibility");
+    connect(action, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
+
+    action = actionManager->createAction("toggle_layer_alpha_lock");
+    connect(action, SIGNAL(triggered()), this, SLOT(toggleAlphaLock()));
+
+    action = actionManager->createAction("toggle_layer_inherit_alpha");
+    connect(action, SIGNAL(triggered()), this, SLOT(toggleInheritAlpha()));
+
     action  = actionManager->createAction("split_alpha_into_mask");
     connect(action, SIGNAL(triggered()), this, SLOT(slotSplitAlphaIntoMask()));
 
@@ -1130,6 +1142,74 @@ void KisNodeManager::slotSplitAlphaSaveMerged()
     m_d->mergeTransparencyMaskAsAlpha(false);
 }
 
+void KisNodeManager::toggleLock()
+{
+    KisNodeList nodes = this->selectedNodes();
+    KisNodeSP active = activeNode();
+    if (nodes.isEmpty() || !active) return;
+
+    bool isLocked = active->userLocked();
+
+    for (auto &node : nodes) {
+        node->setUserLocked(!isLocked);
+    }
+}
+
+void KisNodeManager::toggleVisibility()
+{
+    KisNodeList nodes = this->selectedNodes();
+    KisNodeSP active = activeNode();
+    if (nodes.isEmpty() || !active) return;
+
+    bool isVisible = active->visible();
+
+    for (auto &node : nodes) {
+        node->setVisible(!isVisible);
+        node->setDirty();
+    }
+}
+
+void KisNodeManager::toggleAlphaLock()
+{
+    KisNodeList nodes = this->selectedNodes();
+    KisNodeSP active = activeNode();
+    if (nodes.isEmpty() || !active) return;
+
+    auto layer = qobject_cast<KisPaintLayer*>(active.data());
+    if (!layer) {
+        return;
+    }
+
+    bool isAlphaLocked = layer->alphaLocked();
+    for (auto &node : nodes) {
+        auto layer = qobject_cast<KisPaintLayer*>(node.data());
+        if (layer) {
+            layer->setAlphaLocked(!isAlphaLocked);
+        }
+    }
+}
+
+void KisNodeManager::toggleInheritAlpha()
+{
+    KisNodeList nodes = this->selectedNodes();
+    KisNodeSP active = activeNode();
+    if (nodes.isEmpty() || !active) return;
+
+    auto layer = qobject_cast<KisLayer*>(active.data());
+    if (!layer) {
+        return;
+    }
+
+    bool isAlphaDisabled = layer->alphaChannelDisabled();
+    for (auto &node : nodes) {
+        auto layer = qobject_cast<KisLayer*>(node.data());
+        if (layer) {
+            layer->disableAlphaChannel(!isAlphaDisabled);
+            node->setDirty();
+        }
+    }
+}
+
 void KisNodeManager::cutLayersToClipboard()
 {
     KisNodeList nodes = this->selectedNodes();
diff --git a/libs/ui/kis_node_manager.h b/libs/ui/kis_node_manager.h
index 58cc9006647..9455adb57ed 100644
--- a/libs/ui/kis_node_manager.h
+++ b/libs/ui/kis_node_manager.h
@@ -203,6 +203,11 @@ public Q_SLOTS:
     void slotSplitAlphaWrite();
     void slotSplitAlphaSaveMerged();
 
+    void toggleLock();
+    void toggleVisibility();
+    void toggleAlphaLock();
+    void toggleInheritAlpha();
+
     /**
      * @brief slotSetSelectedNodes set the list of nodes selected in the layerbox. Selected nodes are not necessarily active nodes.
      * @param nodes the selected nodes
diff --git a/plugins/dockers/defaultdockers/kis_layer_box.cpp b/plugins/dockers/defaultdockers/kis_layer_box.cpp
index 8417de1757d..ad7ef0e8813 100644
--- a/plugins/dockers/defaultdockers/kis_layer_box.cpp
+++ b/plugins/dockers/defaultdockers/kis_layer_box.cpp
@@ -568,6 +568,11 @@ void KisLayerBox::slotContextMenuRequested(const QPoint &pos, const QModelIndex
             addActionToMenu(groupMenu, "create_quick_group");
             addActionToMenu(groupMenu, "create_quick_clipping_group");
             addActionToMenu(groupMenu, "quick_ungroup");
+            QMenu *locksMenu = menu.addMenu(i18n("&Locks && visibility"));
+            addActionToMenu(locksMenu, "toggle_layer_lock");
+            addActionToMenu(locksMenu, "toggle_layer_visibility");
+            addActionToMenu(locksMenu, "toggle_layer_alpha_lock");
+            addActionToMenu(locksMenu, "toggle_layer_inherit_alpha");
 
             if (singleLayer) {
                 QMenu *addLayerMenu = menu.addMenu(i18n("&Add"));


More information about the kimageshop mailing list