diff --git a/krita/image/commands/kis_node_property_list_command.cpp b/krita/image/commands/kis_node_property_list_command.cpp index 889af70a08..6cdf356f8a 100644 --- a/krita/image/commands/kis_node_property_list_command.cpp +++ b/krita/image/commands/kis_node_property_list_command.cpp @@ -1,46 +1,77 @@ /* * Copyright (c) 2009 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "kis_node.h" +#include "kis_layer.h" +#include "kis_image.h" #include "commands/kis_node_property_list_command.h" KisNodePropertyListCommand::KisNodePropertyListCommand(KisNodeSP node, KisDocumentSectionModel::PropertyList newPropertyList) : KisNodeCommand(kundo2_i18n("Property Changes"), node), m_newPropertyList(newPropertyList), m_oldPropertyList(node->sectionModelProperties()) /** * TODO instead of "Property Changes" check which property * has been changed and display either lock/unlock, visible/hidden * or "Property Changes" (this require new strings) */ { } void KisNodePropertyListCommand::redo() { m_node->setSectionModelProperties(m_newPropertyList); - m_node->setDirty(); // TODO check if visibility was changed or not + doUpdate(m_oldPropertyList, m_newPropertyList); } void KisNodePropertyListCommand::undo() { m_node->setSectionModelProperties(m_oldPropertyList); - m_node->setDirty(); // TODO check if visibility was changed or not + doUpdate(m_newPropertyList, m_oldPropertyList); +} + +void KisNodePropertyListCommand::doUpdate(const KisDocumentSectionModel::PropertyList &oldPropertyList, + const KisDocumentSectionModel::PropertyList &newPropertyList) +{ + bool oldPassThroughValue = false; + bool newPassThroughValue = false; + + foreach(const KisDocumentSectionModel::Property &prop, oldPropertyList) { + if (prop.name == i18n("Pass Through")) { + oldPassThroughValue = prop.state.toBool(); + } + } + + foreach(const KisDocumentSectionModel::Property &prop, newPropertyList) { + if (prop.name == i18n("Pass Through")) { + newPassThroughValue = prop.state.toBool(); + } + } + + if (oldPassThroughValue && !newPassThroughValue) { + KisLayer *layer = qobject_cast(m_node.data()); + layer->image()->refreshGraphAsync(layer); + } else if (m_node->parent() && !oldPassThroughValue && newPassThroughValue) { + KisLayer *layer = qobject_cast(m_node->parent().data()); + layer->image()->refreshGraphAsync(layer); + } else { + m_node->setDirty(); // TODO check if visibility was changed or not + } } diff --git a/krita/image/commands/kis_node_property_list_command.h b/krita/image/commands/kis_node_property_list_command.h index fdceab2821..418995d1b2 100644 --- a/krita/image/commands/kis_node_property_list_command.h +++ b/krita/image/commands/kis_node_property_list_command.h @@ -1,44 +1,48 @@ /* * Copyright (c) 2009 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KIS_IMAGE_NODE_PROPERTY_LIST_COMMAND_H_ #define KIS_IMAGE_NODE_PROPERTY_LIST_COMMAND_H_ #include "kis_node_command.h" #include "KisDocumentSectionModel.h" /// The command for changing the property list of a layer class KRITAIMAGE_EXPORT KisNodePropertyListCommand : public KisNodeCommand { public: /** * Constructor * @param node the layer to add */ KisNodePropertyListCommand(KisNodeSP node, KisDocumentSectionModel::PropertyList newPropertyList); virtual void redo(); virtual void undo(); +private: + void doUpdate(const KisDocumentSectionModel::PropertyList &oldPropertyList, + const KisDocumentSectionModel::PropertyList &newPropertyList); + private: KisDocumentSectionModel::PropertyList m_newPropertyList; KisDocumentSectionModel::PropertyList m_oldPropertyList; }; #endif diff --git a/krita/image/kis_projection_leaf.cpp b/krita/image/kis_projection_leaf.cpp index 71602ecb4b..948847ed11 100644 --- a/krita/image/kis_projection_leaf.cpp +++ b/krita/image/kis_projection_leaf.cpp @@ -1,208 +1,214 @@ /* * Copyright (c) 2015 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_projection_leaf.h" #include #include "kis_layer.h" #include "kis_mask.h" #include "kis_group_layer.h" #include "kis_adjustment_layer.h" struct KisProjectionLeaf::Private { Private(KisNode *_node) : node(_node) {} KisNode* node; static bool checkPassThrough(const KisNode *node) { const KisGroupLayer *group = qobject_cast(node); return group && group->passThroughMode(); } bool checkParentPassThrough() { return node->parent() && checkPassThrough(node->parent()); } bool checkThisPassThrough() { return checkPassThrough(node); } }; KisProjectionLeaf::KisProjectionLeaf(KisNode *node) : m_d(new Private(node)) { } KisProjectionLeaf::~KisProjectionLeaf() { } KisProjectionLeafSP KisProjectionLeaf::parent() const { KisNodeSP node = m_d->node->parent(); if (node && Private::checkPassThrough(node)) { node = node->parent(); } return node ? node->projectionLeaf() : KisProjectionLeafSP(); } KisProjectionLeafSP KisProjectionLeaf::firstChild() const { KisNodeSP node; if (!m_d->checkThisPassThrough()) { node = m_d->node->firstChild(); } return node ? node->projectionLeaf() : KisProjectionLeafSP(); } KisProjectionLeafSP KisProjectionLeaf::lastChild() const { KisNodeSP node; if (!m_d->checkThisPassThrough()) { node = m_d->node->lastChild(); } return node ? node->projectionLeaf() : KisProjectionLeafSP(); } KisProjectionLeafSP KisProjectionLeaf::prevSibling() const { KisNodeSP node; if (m_d->checkThisPassThrough()) { node = m_d->node->lastChild(); } if (!node) { node = m_d->node->prevSibling(); } if (!node && m_d->checkParentPassThrough()) { node = m_d->node->parent()->prevSibling(); } return node ? node->projectionLeaf() : KisProjectionLeafSP(); } KisProjectionLeafSP KisProjectionLeaf::nextSibling() const { KisNodeSP node = m_d->node->nextSibling(); if (node && Private::checkPassThrough(node) && node->firstChild()) { node = node->firstChild(); } if (!node && m_d->checkParentPassThrough()) { node = m_d->node->parent(); } return node ? node->projectionLeaf() : KisProjectionLeafSP(); } int KisProjectionLeaf::childCount() const { return m_d->node->childCount(); } KisNodeSP KisProjectionLeaf::node() const { return m_d->node; } KisAbstractProjectionPlaneSP KisProjectionLeaf::projectionPlane() const { return m_d->node->projectionPlane(); } bool KisProjectionLeaf::accept(KisNodeVisitor &visitor) { return m_d->node->accept(visitor); } KisPaintDeviceSP KisProjectionLeaf::original() { return m_d->node->original(); } KisPaintDeviceSP KisProjectionLeaf::projection() { return m_d->node->projection(); } bool KisProjectionLeaf::isRoot() const { return (bool)!m_d->node->parent(); } bool KisProjectionLeaf::isLayer() const { return (bool)qobject_cast(m_d->node); } bool KisProjectionLeaf::isMask() const { return (bool)qobject_cast(m_d->node); } bool KisProjectionLeaf::canHaveChildLayers() const { return (bool)qobject_cast(m_d->node); } bool KisProjectionLeaf::dependsOnLowerNodes() const { return (bool)qobject_cast(m_d->node); } bool KisProjectionLeaf::visible() const { - // check opacity as well! - return m_d->node->visible(true); + // TODO: check opacity as well! + + bool hiddenByParentPassThrough = + m_d->checkParentPassThrough() && !m_d->node->parent()->visible(); + + return m_d->node->visible(false) && + !m_d->checkThisPassThrough() && + !hiddenByParentPassThrough; } quint8 KisProjectionLeaf::opacity() const { quint8 resultOpacity = m_d->node->opacity(); quint8 parentOpacity = 255; if (m_d->checkParentPassThrough()) { quint8 parentOpacity = m_d->node->parent()->projectionLeaf()->opacity(); if (parentOpacity != OPACITY_OPAQUE_U8) { resultOpacity = (int(resultOpacity) * parentOpacity) / OPACITY_OPAQUE_U8; } } return resultOpacity; } bool KisProjectionLeaf::isStillInGraph() const { return (bool)m_d->node->graphListener(); }