forked from qt-creator/qt-creator
QmlDesigner: Enable rendering of DesignerEffects
* Effects are items and we have to use __effect/source and allEffects to idenfify them and get the correct bounding rectangle. * For now we use a custom parser to work around issues when editig the model Change-Id: I78690498c44f8285d3bb6ce78eafcafb9c26b2f1 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -436,10 +436,18 @@ QQuickItem *Qt5NodeInstanceServer::parentEffectItem(QQuickItem *item)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool isEffectItem(QQuickItem *item, QQuickShaderEffectSource *sourceItem)
|
||||
static bool isEffectItem(QQuickItem *item, QQuickShaderEffectSource *sourceItem, QQuickItem *target)
|
||||
{
|
||||
QQuickItemPrivate *pItem = QQuickItemPrivate::get(sourceItem);
|
||||
|
||||
if (item) {
|
||||
QQmlProperty prop(item, "__effect");
|
||||
if (prop.read().toBool()) {
|
||||
prop = QQmlProperty(item, "source");
|
||||
return prop.read().value<QQuickItem *>() == target;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pItem || !pItem->layer())
|
||||
return false;
|
||||
|
||||
@@ -477,7 +485,7 @@ QImage Qt5NodeInstanceServer::grabItem([[maybe_unused]] QQuickItem *item)
|
||||
if (auto parent = item->parentItem()) {
|
||||
const auto siblings = parent->childItems();
|
||||
for (auto sibling : siblings) {
|
||||
if (isEffectItem(sibling, pItem->layer()->effectSource()))
|
||||
if (isEffectItem(sibling, pItem->layer()->effectSource(), item))
|
||||
return grabItem(sibling);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +120,20 @@ QRectF ServerNodeInstance::effectAdjustedBoundingRect(QQuickItem *item)
|
||||
{
|
||||
if (item) {
|
||||
QQuickItemPrivate *pItem = QQuickItemPrivate::get(item);
|
||||
if (pItem && pItem->layer() && pItem->layer()->sourceRect().isValid())
|
||||
|
||||
QQmlProperty prop(item, "__effect");
|
||||
|
||||
if (pItem && pItem->layer() && pItem->layer()->sourceRect().isValid()) {
|
||||
return pItem->layer()->sourceRect();
|
||||
else
|
||||
} else if (prop.read().toBool()) {
|
||||
prop = QQmlProperty(item, "allEffects");
|
||||
QRectF rect = prop.read().toRectF().adjusted(-20, -20, 20, 20);
|
||||
if (rect.isValid())
|
||||
return rect;
|
||||
return item->boundingRect();
|
||||
} else {
|
||||
return item->boundingRect();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user