Skip to content
Snippets Groups Projects
Commit cdeee01c authored by Marco Bubke's avatar Marco Bubke Committed by Kai Koehne
Browse files

Generate a style option for the paint function in the node instances

WebView is expecting a valid QStyleOptionGraphicsItem argument.

Reviewed-by: kkoehne
parent 89482b1b
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include "invalidnodeinstanceexception.h" #include "invalidnodeinstanceexception.h"
#include <QGraphicsObject> #include <QGraphicsObject>
#include "private/qgraphicsitem_p.h"
#include <QStyleOptionGraphicsItem>
#include "nodemetainfo.h" #include "nodemetainfo.h"
namespace QmlDesigner { namespace QmlDesigner {
...@@ -153,13 +155,21 @@ bool GraphicsObjectNodeInstance::equalGraphicsItem(QGraphicsItem *item) const ...@@ -153,13 +155,21 @@ bool GraphicsObjectNodeInstance::equalGraphicsItem(QGraphicsItem *item) const
return item == graphicsObject(); return item == graphicsObject();
} }
void initOption(QGraphicsItem *item, QStyleOptionGraphicsItem *option, const QTransform &transform)
{
QGraphicsItemPrivate *privateItem = QGraphicsItemPrivate::get(item);
privateItem->initStyleOption(option, transform, QRegion());
}
void GraphicsObjectNodeInstance::paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const void GraphicsObjectNodeInstance::paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const
{ {
if (graphicsItem->isVisible()) { if (graphicsItem->isVisible()) {
painter->save(); painter->save();
painter->setTransform(graphicsItem->itemTransform(graphicsItem->parentItem()), true); painter->setTransform(graphicsItem->itemTransform(graphicsItem->parentItem()), true);
painter->setOpacity(graphicsItem->opacity() * painter->opacity()); painter->setOpacity(graphicsItem->opacity() * painter->opacity());
graphicsItem->paint(painter, 0); QStyleOptionGraphicsItem option;
initOption(graphicsItem, &option, painter->transform());
graphicsItem->paint(painter, &option);
foreach(QGraphicsItem *childItem, graphicsItem->childItems()) { foreach(QGraphicsItem *childItem, graphicsItem->childItems()) {
paintRecursively(childItem, painter); paintRecursively(childItem, painter);
} }
...@@ -171,12 +181,16 @@ void GraphicsObjectNodeInstance::paint(QPainter *painter) const ...@@ -171,12 +181,16 @@ void GraphicsObjectNodeInstance::paint(QPainter *painter) const
{ {
painter->save(); painter->save();
Q_ASSERT(graphicsObject()); Q_ASSERT(graphicsObject());
if (hasContent()) if (hasContent()) {
graphicsObject()->paint(painter, 0); QStyleOptionGraphicsItem option;
initOption(graphicsObject(), &option, painter->transform());
graphicsObject()->paint(painter, &option);
}
foreach(QGraphicsItem *graphicsItem, graphicsObject()->childItems()) { foreach(QGraphicsItem *graphicsItem, graphicsObject()->childItems()) {
QGraphicsObject *graphicsObject = qgraphicsitem_cast<QGraphicsObject*>(graphicsItem); QGraphicsObject *graphicsObject = qgraphicsitem_cast<QGraphicsObject*>(graphicsItem);
if (graphicsObject && !nodeInstanceView()->hasInstanceForObject(graphicsObject)) if (graphicsObject
&& !nodeInstanceView()->hasInstanceForObject(graphicsObject))
paintRecursively(graphicsItem, painter); paintRecursively(graphicsItem, painter);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment