aboutsummaryrefslogtreecommitdiffstats
path: root/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2021-08-26 18:31:40 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2021-08-30 12:06:57 +0000
commit3945868670238358d8733fad71264f2a9996d3bd (patch)
treec7e85ab9fdc88738c2dd824a43508ea6c46aeb36 /share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp
parente4995fd6c7bcc624142babc5b0d861aedca7fb81 (diff)
QmlDesigner: Render item inside the bounding rect
We have to render an item inside the bounding rect, because if it is a component there might be child items outside its actual size. The way we calculate the bounding rectangle excludes children on the document level. We take clipping into account when calculating the bounding rect. When rendering the effect we do not have the instance. Therefore we fall back to the standard bounding rectangle. Change-Id: I7cd09d08d461d28c49a91fb891a5487185df0245 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp')
-rw-r--r--share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp43
1 files changed, 38 insertions, 5 deletions
diff --git a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp
index ab38b33aaf..33bc2ee156 100644
--- a/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp
+++ b/share/qtcreator/qml/qmlpuppet/qml2puppet/instances/quickitemnodeinstance.cpp
@@ -28,6 +28,9 @@
#include <qmlprivategate.h>
+#include <QtQuick/private/qquickitem_p.h>
+#include <QtQuick/private/qquickshadereffectsource_p.h>
+
#include <QQmlProperty>
#include <QQmlExpression>
#include <QQuickView>
@@ -476,11 +479,12 @@ QImage QuickItemNodeInstance::renderImage() const
}
renderImage.setDevicePixelRatio(devicePixelRatio);
#else
- if (s_unifiedRenderPath)
+ if (s_unifiedRenderPath) {
renderImage = nodeInstanceServer()->grabWindow();
- else
+ renderImage = renderImage.copy(renderBoundingRect.toRect());
+ } else {
renderImage = nodeInstanceServer()->grabItem(quickItem());
- renderImage = renderImage.copy(renderBoundingRect.toRect());
+ }
/* When grabbing an offscren window the device pixel ratio is 1 */
renderImage.setDevicePixelRatio(1);
@@ -613,6 +617,34 @@ static inline bool isRectangleSane(const QRectF &rect)
return rect.isValid() && (rect.width() < 10000) && (rect.height() < 10000);
}
+static bool isEffectItem(QQuickItem *item)
+{
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ Q_UNUSED(item)
+ return false;
+#else
+ if (qobject_cast<QQuickShaderEffectSource *>(item))
+ return true;
+
+ const auto propName = "source";
+
+ QQmlProperty prop(item, QString::fromLatin1(propName));
+ if (!prop.isValid())
+ return false;
+
+ QQuickShaderEffectSource *source = prop.read().value<QQuickShaderEffectSource *>();
+
+ if (source && source->sourceItem()) {
+ QQuickItemPrivate *pItem = QQuickItemPrivate::get(source->sourceItem());
+
+ if (pItem && pItem->layer() && pItem->layer()->enabled() && pItem->layer()->effect())
+ return true;
+ }
+
+ return false;
+#endif
+}
+
QRectF QuickItemNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem) const
{
QRectF boundingRect = parentItem->boundingRect();
@@ -620,8 +652,9 @@ QRectF QuickItemNodeInstance::boundingRectWithStepChilds(QQuickItem *parentItem)
boundingRect = boundingRect.united(QRectF(QPointF(0, 0), size()));
for (QQuickItem *childItem : parentItem->childItems()) {
- if (!nodeInstanceServer()->hasInstanceForObject(childItem)) {
- QRectF transformedRect = childItem->mapRectToItem(parentItem, boundingRectWithStepChilds(childItem));
+ if (!nodeInstanceServer()->hasInstanceForObject(childItem) && !isEffectItem(childItem)) {
+ QRectF transformedRect = childItem->mapRectToItem(parentItem,
+ boundingRectWithStepChilds(childItem));
if (isRectangleSane(transformedRect))
boundingRect = boundingRect.united(transformedRect);
}