Commit 2d8c0dd4 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Add blur render image



To give the impression that the content is non editable.

Change-Id: I1869d02a27b2d1a7c2c12abb9a8d8d24068adf22
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 6a6264db
......@@ -55,6 +55,7 @@ FormEditorItem::FormEditorItem(const QmlItemNode &qmlItemNode, FormEditorScene*
m_qmlItemNode(qmlItemNode),
m_borderWidth(1.0),
m_highlightBoundingRect(false),
m_blurContent(false),
m_isContentVisible(true),
m_isFormEditorVisible(true)
{
......@@ -118,6 +119,14 @@ void FormEditorItem::setHighlightBoundingRect(bool highlight)
}
}
void FormEditorItem::blurContent(bool blurContent)
{
if (m_blurContent != blurContent) {
m_blurContent = blurContent;
update();
}
}
void FormEditorItem::setContentVisible(bool visible)
{
if (visible == m_isContentVisible)
......@@ -275,7 +284,10 @@ void FormEditorItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *,
if (scene()->showBoundingRects() && m_boundingRect.width() > 15 && m_boundingRect.height() > 15)
paintPlaceHolderForInvisbleItem(painter);
} else {
qmlItemNode().paintInstance(painter);
if (m_blurContent)
painter->drawPixmap(boundingRect().topLeft(), qmlItemNode().instanceBlurredRenderPixmap());
else
painter->drawPixmap(boundingRect().topLeft(), qmlItemNode().instanceRenderPixmap());
}
if (!qmlItemNode().isRootModelNode())
......
......@@ -99,6 +99,7 @@ public:
FormEditorView *formEditorView() const;
void setHighlightBoundingRect(bool highlight);
void blurContent(bool blurContent);
void setContentVisible(bool visible);
bool isContentVisible() const;
......@@ -124,6 +125,7 @@ private: // variables
QRectF m_paintedBoundingRect;
double m_borderWidth;
bool m_highlightBoundingRect;
bool m_blurContent;
bool m_isContentVisible;
bool m_isFormEditorVisible;
};
......
......@@ -73,7 +73,9 @@ public:
QPointF position() const;
QSizeF size() const;
int penWidth() const;
void paint(QPainter *painter);
QPixmap renderPixmap() const;
QPixmap blurredRenderPixmap() const;
QVariant property(const PropertyName &name) const;
bool hasBindingForProperty(const PropertyName &name) const;
......@@ -84,7 +86,6 @@ public:
qint32 parentId() const;
qint32 instanceId() const;
QPixmap renderPixmap() const;
protected:
void setProperty(const PropertyName &name, const QVariant &value);
......
......@@ -102,7 +102,8 @@ public:
int instancePenWidth() const;
bool instanceIsRenderPixmapNull() const;
void paintInstance(QPainter *painter);
QPixmap instanceRenderPixmap() const;
QPixmap instanceBlurredRenderPixmap() const;
TypeName simplifiedTypeName() const;
......
......@@ -34,6 +34,10 @@
#include <QDebug>
QT_BEGIN_NAMESPACE
void qt_blurImage(QPainter *painter, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed = 0);
QT_END_NAMESPACE
namespace QmlDesigner {
class ProxyNodeInstanceData
......@@ -75,6 +79,8 @@ public:
QHash<PropertyName, TypeName> instanceTypes;
QPixmap renderPixmap;
QPixmap blurredRenderPixmap;
QHash<PropertyName, QPair<PropertyName, qint32> > anchors;
};
......@@ -256,12 +262,6 @@ int NodeInstance::penWidth() const
return 1;
}
void NodeInstance::paint(QPainter *painter)
{
if (isValid() && !d->renderPixmap.isNull())
painter->drawPixmap(boundingRect().topLeft(), d->renderPixmap);
}
QVariant NodeInstance::property(const PropertyName &name) const
{
if (isValid())
......@@ -320,10 +320,24 @@ QPixmap NodeInstance::renderPixmap() const
return d->renderPixmap;
}
QPixmap NodeInstance::blurredRenderPixmap() const
{
if (d->blurredRenderPixmap.isNull()) {
d->blurredRenderPixmap = QPixmap(d->renderPixmap.size());
QPainter blurPainter(&d->blurredRenderPixmap);
QImage renderImage = d->renderPixmap.toImage();
qt_blurImage(&blurPainter, renderImage, 8.0, false, false);
}
return d->blurredRenderPixmap;
}
void NodeInstance::setRenderPixmap(const QImage &image)
{
if (!image.isNull())
if (!image.isNull()) {
d->renderPixmap = QPixmap::fromImage(image);
d->blurredRenderPixmap = QPixmap();
}
}
void NodeInstance::setParentId(qint32 instanceId)
......
......@@ -482,10 +482,14 @@ bool QmlItemNode::instanceIsRenderPixmapNull() const
return nodeInstance().renderPixmap().isNull();
}
void QmlItemNode::paintInstance(QPainter *painter)
QPixmap QmlItemNode::instanceRenderPixmap() const
{
if (nodeInstance().isValid())
nodeInstance().paint(painter);
return nodeInstance().renderPixmap();
}
QPixmap QmlItemNode::instanceBlurredRenderPixmap() const
{
return nodeInstance().blurredRenderPixmap();
}
QList<QmlModelState> QmlModelStateGroup::allStates() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment