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

Implement KisAbstractProjectionPlane::looseUserVisibleBounds()

Dmitry Kazakov75a084ca7e90
diff --git a/libs/image/kis_abstract_projection_plane.cpp b/libs/image/kis_abstract_projection_plane.cpp
index 6432014f0a..96d601ba80 100644
--- a/libs/image/kis_abstract_projection_plane.cpp
+++ b/libs/image/kis_abstract_projection_plane.cpp
@@ -57,6 +57,11 @@ QRect KisDumbProjectionPlane::tightUserVisibleBounds() const
return QRect();
}
+QRect KisDumbProjectionPlane::looseUserVisibleBounds() const
+{
+ return QRect();
+}
+
KisPaintDeviceList KisDumbProjectionPlane::getLodCapableDevices() const
{
// arghm...
diff --git a/libs/image/kis_abstract_projection_plane.h b/libs/image/kis_abstract_projection_plane.h
index 87d8eb50c8..a920891543 100644
--- a/libs/image/kis_abstract_projection_plane.h
+++ b/libs/image/kis_abstract_projection_plane.h
@@ -80,6 +80,16 @@ public:
*/
virtual QRect tightUserVisibleBounds() const = 0;
+ /**
+ * Return an approximate (loose) rectangle, where the contents of the
+ * plane is placed from user's point of view. It includes everything
+ * belonging to the plane (e.g. layer styles).
+ *
+ * This rectangle contains or is bigger than the rectangle returned by
+ * tightUserVisibleBounds().
+ */
+ virtual QRect looseUserVisibleBounds() const = 0;
+
/**
* Returns a list of devices which should synchronize the lod cache on update
*/
@@ -101,6 +111,7 @@ public:
QRect accessRect(const QRect &rect, KisLayer::PositionToFilthy pos) const override;
QRect needRectForOriginal(const QRect &rect) const override;
QRect tightUserVisibleBounds() const override;
+ QRect looseUserVisibleBounds() const override;
KisPaintDeviceList getLodCapableDevices() const override;
};
diff --git a/libs/image/kis_group_layer.cc b/libs/image/kis_group_layer.cc
index efd0ea1077..6f498f2fa2 100644
--- a/libs/image/kis_group_layer.cc
+++ b/libs/image/kis_group_layer.cc
@@ -25,6 +25,8 @@
#include "kis_selection_mask.h"
#include "kis_psd_layer_style.h"
#include "kis_layer_properties_icons.h"
+#include <kis_projection_leaf.h>
+#include <kis_abstract_projection_plane.h>
struct Q_DECL_HIDDEN KisGroupLayer::Private
@@ -392,14 +394,14 @@ void KisGroupLayer::setY(qint32 y)
struct ExtentPolicy
{
inline QRect operator() (const KisNode *node) {
- return node->extent();
+ return node->projectionPlane()->looseUserVisibleBounds();
}
};
struct ExactBoundsPolicy
{
inline QRect operator() (const KisNode *node) {
- return node->exactBounds();
+ return node->projectionPlane()->tightUserVisibleBounds();
}
};
@@ -410,7 +412,9 @@ QRect collectRects(const KisNode *node, MetricPolicy policy)
const KisNode *child = node->firstChild();
while (child) {
- if (!qobject_cast<const KisMask*>(child)) {
+ if (child->projectionLeaf()->isLayer() &&
+ child->projectionLeaf()->visible()) {
+
accumulator |= policy(child);
}
child = child->nextSibling();
@@ -422,13 +426,23 @@ QRect collectRects(const KisNode *node, MetricPolicy policy)
QRect KisGroupLayer::extent() const
{
return m_d->passThroughMode ?
- collectRects(this, ExtentPolicy()) :
+ calculateChildrenLooseUserVisibleBounds() :
KisLayer::extent();
}
QRect KisGroupLayer::exactBounds() const
{
return m_d->passThroughMode ?
- collectRects(this, ExactBoundsPolicy()) :
+ calculateChildrenTightUserVisibleBounds() :
KisLayer::exactBounds();
}
+
+QRect KisGroupLayer::calculateChildrenTightUserVisibleBounds() const
+{
+ return collectRects(this, ExactBoundsPolicy());
+}
+
+QRect KisGroupLayer::calculateChildrenLooseUserVisibleBounds() const
+{
+ return collectRects(this, ExtentPolicy());
+}
diff --git a/libs/image/kis_group_layer.h b/libs/image/kis_group_layer.h
index dffb3cc723..8283e906dc 100644
--- a/libs/image/kis_group_layer.h
+++ b/libs/image/kis_group_layer.h
@@ -102,6 +102,9 @@ public:
bool projectionIsValid() const;
+ QRect calculateChildrenTightUserVisibleBounds() const;
+ QRect calculateChildrenLooseUserVisibleBounds() const;
+
protected:
KisLayer* onlyMeaningfulChild() const;
KisPaintDeviceSP tryObligeChild() const;
diff --git a/libs/image/kis_layer.cc b/libs/image/kis_layer.cc
index 12b0cdb2a9..65f526f957 100644
--- a/libs/image/kis_layer.cc
+++ b/libs/image/kis_layer.cc
@@ -804,9 +804,9 @@ KisPaintDeviceSP KisLayer::projection() const
m_d->safeProjection->getDeviceLazy(originalDevice) : originalDevice;
}
-QRect KisLayer::tightUserVisibleBounds() const
+QRect KisLayer::userVisibleBoundsImpl(bool exactBounds) const
{
- QRect changeRect = exactBounds();
+ QRect changeRect = exactBounds ? this->exactBounds() : this->extent();
/// we do not use incomingChangeRect() here, because
/// exactBounds() already takes it into account (it
@@ -819,6 +819,17 @@ QRect KisLayer::tightUserVisibleBounds() const
return changeRect;
}
+
+QRect KisLayer::tightUserVisibleBounds() const
+{
+ return userVisibleBoundsImpl(true);
+}
+
+QRect KisLayer::looseUserVisibleBounds() const
+{
+ return userVisibleBoundsImpl(false);
+}
+
QRect KisLayer::amortizedProjectionRectForCleanupInChangePass() const
{
return projection()->exactBoundsAmortized();
diff --git a/libs/image/kis_layer.h b/libs/image/kis_layer.h
index 926d68c304..1366b8d1bb 100644
--- a/libs/image/kis_layer.h
+++ b/libs/image/kis_layer.h
@@ -250,6 +250,16 @@ public:
*/
QRect tightUserVisibleBounds() const;
+ /**
+ * Return an approximated (loose) rectangle, where the contents of
+ * the layer is placed from user's point of view. This rectangle
+ * includes all the masks and effects the layer has (excluding layer
+ * styles, they report their bounds via projection plane).
+ *
+ * This rect is always equal or bigger than tightUserVisibleBounds()
+ */
+ QRect looseUserVisibleBounds() const;
+
public:
/**
* Returns true if there are any effect masks present
@@ -416,6 +426,7 @@ private:
private:
QRect layerExtentImpl(bool exactBounds) const;
+ QRect userVisibleBoundsImpl(bool exactBounds) const;
private:
struct Private;
diff --git a/libs/image/kis_layer_projection_plane.cpp b/libs/image/kis_layer_projection_plane.cpp
index b465a8b864..84db72af0a 100644
--- a/libs/image/kis_layer_projection_plane.cpp
+++ b/libs/image/kis_layer_projection_plane.cpp
@@ -114,3 +114,8 @@ QRect KisLayerProjectionPlane::tightUserVisibleBounds() const
return m_d->layer->tightUserVisibleBounds();
}
+QRect KisLayerProjectionPlane::looseUserVisibleBounds() const
+{
+ return m_d->layer->looseUserVisibleBounds();
+}
+
diff --git a/libs/image/kis_layer_projection_plane.h b/libs/image/kis_layer_projection_plane.h
index ddfa3b955d..4c0803310e 100644
--- a/libs/image/kis_layer_projection_plane.h
+++ b/libs/image/kis_layer_projection_plane.h
@@ -31,6 +31,7 @@ public:
QRect accessRect(const QRect &rect, KisLayer::PositionToFilthy pos) const override;
QRect needRectForOriginal(const QRect &rect) const override;
QRect tightUserVisibleBounds() const override;
+ QRect looseUserVisibleBounds() const override;
KisPaintDeviceList getLodCapableDevices() const override;
diff --git a/libs/image/kis_mask_projection_plane.cpp b/libs/image/kis_mask_projection_plane.cpp
index 2652346cb3..a0c2b6749c 100644
--- a/libs/image/kis_mask_projection_plane.cpp
+++ b/libs/image/kis_mask_projection_plane.cpp
@@ -80,3 +80,10 @@ QRect KisMaskProjectionPlane::tightUserVisibleBounds() const
return m_d->mask->extent();
}
+QRect KisMaskProjectionPlane::looseUserVisibleBounds() const
+{
+ // masks don't have anything complex inside, so just
+ // fall back to tightUserVisibleBounds()
+ return tightUserVisibleBounds();
+}
+
diff --git a/libs/image/kis_mask_projection_plane.h b/libs/image/kis_mask_projection_plane.h
index 3e066ea9e8..c8628b43df 100644
--- a/libs/image/kis_mask_projection_plane.h
+++ b/libs/image/kis_mask_projection_plane.h
@@ -33,6 +33,7 @@ public:
QRect accessRect(const QRect &rect, KisNode::PositionToFilthy pos) const override;
QRect needRectForOriginal(const QRect &rect) const override;
QRect tightUserVisibleBounds() const override;
+ QRect looseUserVisibleBounds() const override;
KisPaintDeviceList getLodCapableDevices() const override;
diff --git a/libs/image/kis_transform_mask.cpp b/libs/image/kis_transform_mask.cpp
index 6cb770246b..ba67ff3851 100644
--- a/libs/image/kis_transform_mask.cpp
+++ b/libs/image/kis_transform_mask.cpp
@@ -11,6 +11,7 @@
#include "kis_layer.h"
#include "kis_transform_mask.h"
+#include <kis_group_layer.h>
#include "filter/kis_filter.h"
#include "filter/kis_filter_configuration.h"
#include "filter/kis_filter_registry.h"
@@ -559,6 +560,20 @@ void KisTransformMask::accept(KisProcessingVisitor &visitor, KisUndoAdapter *und
return visitor.visit(this, undoAdapter);
}
+namespace {
+QRect calculateInterestRect(KisNodeSP node) {
+ QRect resultInterestRect;
+
+ if (KisGroupLayer *group = qobject_cast<KisGroupLayer*>(node.data())) {
+ resultInterestRect = group->calculateChildrenLooseUserVisibleBounds();
+ } else {
+ resultInterestRect = node->original()->extent();
+ }
+
+ return resultInterestRect;
+}
+}
+
QRect KisTransformMask::changeRect(const QRect &rect, PositionToFilthy pos) const
{
Q_UNUSED(pos);
@@ -580,7 +595,7 @@ QRect KisTransformMask::changeRect(const QRect &rect, PositionToFilthy pos) cons
if (parentNode) {
bounds = parentNode->original()->defaultBounds()->bounds();
- interestRect = parentNode->original()->extent();
+ interestRect = calculateInterestRect(parentNode);
} else {
bounds = QRect(0,0,777,777);
interestRect = QRect(0,0,888,888);
@@ -594,9 +609,6 @@ QRect KisTransformMask::changeRect(const QRect &rect, PositionToFilthy pos) cons
KisSafeTransform transform(params->finalAffineTransform(), limitingRect, interestRect);
changeRect = transform.mapRectForward(rect);
} else {
- QRect interestRect;
- interestRect = parent() ? parent()->original()->extent() : QRect();
-
changeRect = params->nonAffineChangeRect(rect);
}
@@ -621,7 +633,7 @@ QRect KisTransformMask::needRect(const QRect& rect, PositionToFilthy pos) const
if (parentNode) {
bounds = parentNode->original()->defaultBounds()->bounds();
- interestRect = parentNode->original()->extent();
+ interestRect = calculateInterestRect(parentNode);
} else {
bounds = QRect(0,0,777,777);
interestRect = QRect(0,0,888,888);
diff --git a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp
index 133ee9666f..1820640e66 100644
--- a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp
+++ b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp
@@ -163,3 +163,12 @@ QRect KisLayerStyleFilterProjectionPlane::tightUserVisibleBounds() const
m_d->environment.data());
}
+QRect KisLayerStyleFilterProjectionPlane::looseUserVisibleBounds() const
+{
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_d->filter, QRect());
+ KIS_SAFE_ASSERT_RECOVER_RETURN_VALUE(m_d->sourceLayer, QRect());
+
+ return m_d->filter->changedRect(m_d->sourceLayer->extent(),
+ m_d->style,
+ m_d->environment.data());
+}
diff --git a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.h b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.h
index 0a38054877..5f2b8f5949 100644
--- a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.h
+++ b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.h
@@ -33,6 +33,7 @@ public:
QRect accessRect(const QRect &rect, KisLayer::PositionToFilthy pos) const override;
QRect needRectForOriginal(const QRect &rect) const override;
QRect tightUserVisibleBounds() const override;
+ QRect looseUserVisibleBounds() const override;
KisPaintDeviceList getLodCapableDevices() const override;
diff --git a/libs/image/layerstyles/kis_layer_style_projection_plane.cpp b/libs/image/layerstyles/kis_layer_style_projection_plane.cpp
index 0a02a4ff36..ac6e6e023a 100644
--- a/libs/image/layerstyles/kis_layer_style_projection_plane.cpp
+++ b/libs/image/layerstyles/kis_layer_style_projection_plane.cpp
@@ -432,6 +432,18 @@ QRect KisLayerStyleProjectionPlane::tightUserVisibleBounds() const
return rect;
}
+QRect KisLayerStyleProjectionPlane::looseUserVisibleBounds() const
+{
+ KisAbstractProjectionPlaneSP sourcePlane = m_d->sourceProjectionPlane.toStrongRef();
+ QRect rect = sourcePlane->looseUserVisibleBounds();
+
+ Q_FOREACH (const KisAbstractProjectionPlaneSP plane, m_d->allStyles()) {
+ rect |= plane->looseUserVisibleBounds();
+ }
+
+ return rect;
+}
+
QRect KisLayerStyleProjectionPlane::stylesNeedRect(const QRect &rect) const
{
QRect needRect = rect;
diff --git a/libs/image/layerstyles/kis_layer_style_projection_plane.h b/libs/image/layerstyles/kis_layer_style_projection_plane.h
index 58b2c6b488..298cb4935e 100644
--- a/libs/image/layerstyles/kis_layer_style_projection_plane.h
+++ b/libs/image/layerstyles/kis_layer_style_projection_plane.h
@@ -32,6 +32,7 @@ public:
QRect accessRect(const QRect &rect, KisLayer::PositionToFilthy pos) const override;
QRect needRectForOriginal(const QRect &rect) const override;
QRect tightUserVisibleBounds() const override;
+ QRect looseUserVisibleBounds() const override;
KisPaintDeviceList getLodCapableDevices() const override;