Commit 79764560 authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner: Add content item hack



There is no stand content item interface, so try to work around to enable
snapping and anchoring.

Change-Id: Ib2eaf0d6c35e3ba289dd7d55b2ba4c064ad40748
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 288d2396
......@@ -54,7 +54,8 @@ enum InformationName
IsAnchoredByChildren,
IsAnchoredBySibling,
HasContent,
HasBindingForProperty
HasBindingForProperty,
ContentTransform
};
}
......
......@@ -183,6 +183,22 @@ QTransform GraphicalNodeInstance::customTransform() const
return QTransform();
}
static QTransform contentTransformForItem(QQuickItem *item, NodeInstanceServer *nodeInstanceServer)
{
QTransform contentTransform;
if (item->parentItem() && !nodeInstanceServer->hasInstanceForObject(item->parentItem())) {
contentTransform = DesignerSupport::parentTransform(item->parentItem());
return contentTransformForItem(item->parentItem(), nodeInstanceServer) * contentTransform;
}
return contentTransform;
}
QTransform GraphicalNodeInstance::contentTransform() const
{
return contentTransformForItem(quickItem(), nodeInstanceServer());
}
QTransform GraphicalNodeInstance::sceneTransform() const
{
return DesignerSupport::windowTransform(quickItem());
......
#ifndef QMLDESIGNER_GRAPHICALNODEINSTANCE_H
#define QMLDESIGNER_GRAPHICALNODEINSTANCE_H
#include <QtGlobal>
#include "objectnodeinstance.h"
#include <designersupport.h>
......@@ -23,6 +25,7 @@ public:
QRectF boundingRect() const;
QTransform customTransform() const;
QTransform contentTransform() const Q_DECL_OVERRIDE;
QTransform sceneTransform() const;
double opacity() const;
double rotation() const;
......
......@@ -888,6 +888,7 @@ static QVector<InformationContainer> createInformationVector(const QList<ServerN
informationVector.append(InformationContainer(instance.instanceId(), Size, instance.size()));
informationVector.append(InformationContainer(instance.instanceId(), BoundingRect, instance.boundingRect()));
informationVector.append(InformationContainer(instance.instanceId(), Transform, instance.transform()));
informationVector.append(InformationContainer(instance.instanceId(), ContentTransform, instance.contentTransform()));
informationVector.append(InformationContainer(instance.instanceId(), HasContent, instance.hasContent()));
informationVector.append(InformationContainer(instance.instanceId(), IsMovable, instance.isMovable()));
informationVector.append(InformationContainer(instance.instanceId(), IsResizable, instance.isResizable()));
......
......@@ -245,6 +245,11 @@ QTransform ObjectNodeInstance::transform() const
return QTransform();
}
QTransform ObjectNodeInstance::contentTransform() const
{
return QTransform();
}
QTransform ObjectNodeInstance::customTransform() const
{
return QTransform();
......
......@@ -108,6 +108,7 @@ public:
virtual QPointF position() const;
virtual QSizeF size() const;
virtual QTransform transform() const;
virtual QTransform contentTransform() const;
virtual QTransform customTransform() const;
virtual QTransform sceneTransform() const;
virtual double opacity() const;
......
......@@ -510,6 +510,11 @@ QTransform ServerNodeInstance::sceneTransform() const
return m_nodeInstance->sceneTransform();
}
QTransform ServerNodeInstance::contentTransform() const
{
return m_nodeInstance->contentTransform();
}
double ServerNodeInstance::rotation() const
{
return m_nodeInstance->rotation();
......
......@@ -110,6 +110,7 @@ public:
QTransform transform() const;
QTransform customTransform() const;
QTransform sceneTransform() const;
QTransform contentTransform() const;
double rotation() const;
double scale() const;
QList<QGraphicsTransform *> transformations() const;
......
......@@ -65,6 +65,7 @@ public:
bool isMovable() const;
bool isResizable() const;
QTransform transform() const;
QTransform contentTransform() const;
QTransform sceneTransform() const;
bool isInLayoutable() const;
QPointF position() const;
......@@ -93,6 +94,7 @@ protected:
InformationName setInformationSize(const QSizeF &size);
InformationName setInformationBoundingRect(const QRectF &rectangle);
InformationName setInformationTransform(const QTransform &transform);
InformationName setInformationContentTransform(const QTransform &contentTransform);
InformationName setInformationPenWith(int penWidth);
InformationName setInformationPosition(const QPointF &position);
InformationName setInformationIsInLayoutable(bool isInLayoutable);
......
......@@ -56,6 +56,7 @@ public:
QPointF position;
QSizeF size;
QTransform transform;
QTransform contentTransform;
QTransform sceneTransform;
int penWidth;
bool isAnchoredBySibling;
......@@ -190,6 +191,14 @@ QTransform NodeInstance::transform() const
else
return QTransform();
}
QTransform NodeInstance::contentTransform() const
{
if (isValid())
return d->contentTransform;
else
return QTransform();
}
QTransform NodeInstance::sceneTransform() const
{
if (isValid())
......@@ -334,6 +343,16 @@ InformationName NodeInstance::setInformationTransform(const QTransform &transfor
return NoInformationChange;
}
InformationName NodeInstance::setInformationContentTransform(const QTransform &contentTransform)
{
if (d->contentTransform != contentTransform) {
d->contentTransform = contentTransform;
return ContentTransform;
}
return NoInformationChange;
}
InformationName NodeInstance::setInformationPenWith(int penWidth)
{
if (d->penWidth != penWidth) {
......@@ -468,22 +487,23 @@ InformationName NodeInstance::setInformationHasBindingForProperty(const Property
InformationName NodeInstance::setInformation(InformationName name, const QVariant &information, const QVariant &secondInformation, const QVariant &thirdInformation)
{
switch (name) {
case Size: return setInformationSize(information.toSizeF()); break;
case BoundingRect: return setInformationBoundingRect(information.toRectF()); break;
case Transform: return setInformationTransform(information.value<QTransform>()); break;
case PenWidth: return setInformationPenWith(information.toInt()); break;
case Position: return setInformationPosition(information.toPointF()); break;
case IsInLayoutable: return setInformationIsInLayoutable(information.toBool()); break;
case SceneTransform: return setInformationSceneTransform(information.value<QTransform>()); break;
case IsResizable: return setInformationIsResizable(information.toBool()); break;
case IsMovable: return setInformationIsMovable(information.toBool()); break;
case IsAnchoredByChildren: return setInformationIsAnchoredByChildren(information.toBool()); break;
case IsAnchoredBySibling: return setInformationIsAnchoredBySibling(information.toBool()); break;
case HasContent: return setInformationHasContent(information.toBool()); break;
case Size: return setInformationSize(information.toSizeF());
case BoundingRect: return setInformationBoundingRect(information.toRectF());
case Transform: return setInformationTransform(information.value<QTransform>());
case ContentTransform: return setInformationContentTransform(information.value<QTransform>());
case PenWidth: return setInformationPenWith(information.toInt());
case Position: return setInformationPosition(information.toPointF());
case IsInLayoutable: return setInformationIsInLayoutable(information.toBool());
case SceneTransform: return setInformationSceneTransform(information.value<QTransform>());
case IsResizable: return setInformationIsResizable(information.toBool());
case IsMovable: return setInformationIsMovable(information.toBool());
case IsAnchoredByChildren: return setInformationIsAnchoredByChildren(information.toBool());
case IsAnchoredBySibling: return setInformationIsAnchoredBySibling(information.toBool());
case HasContent: return setInformationHasContent(information.toBool());
case HasAnchor: return setInformationHasAnchor(information.toByteArray(), secondInformation.toBool());break;
case Anchor: return setInformationAnchor(information.toByteArray(), secondInformation.toByteArray(), thirdInformation.value<qint32>()); break;
case InstanceTypeForProperty: return setInformationInstanceTypeForProperty(information.toByteArray(), secondInformation.toByteArray()); break;
case HasBindingForProperty: return setInformationHasBindingForProperty(information.toByteArray(), secondInformation.toBool()); break;
case Anchor: return setInformationAnchor(information.toByteArray(), secondInformation.toByteArray(), thirdInformation.value<qint32>());
case InstanceTypeForProperty: return setInformationInstanceTypeForProperty(information.toByteArray(), secondInformation.toByteArray());
case HasBindingForProperty: return setInformationHasBindingForProperty(information.toByteArray(), secondInformation.toBool());
case NoName:
default: break;
}
......
......@@ -396,24 +396,30 @@ bool QmlAnchors::instanceHasAnchors() const
instanceHasAnchor(AnchorLine::Baseline);
}
QRectF contentRect(const NodeInstance &nodeInstance)
{
QRectF contentRect(nodeInstance.position(), nodeInstance.size());
return nodeInstance.contentTransform().mapRect(contentRect);
}
double QmlAnchors::instanceLeftAnchorLine() const
{
return qmlItemNode().nodeInstance().position().x();
return contentRect(qmlItemNode().nodeInstance()).x();
}
double QmlAnchors::instanceTopAnchorLine() const
{
return qmlItemNode().nodeInstance().position().y();
return contentRect(qmlItemNode().nodeInstance()).y();
}
double QmlAnchors::instanceRightAnchorLine() const
{
return qmlItemNode().nodeInstance().position().x() + qmlItemNode().nodeInstance().size().width();
return contentRect(qmlItemNode().nodeInstance()).x() + contentRect(qmlItemNode().nodeInstance()).width();
}
double QmlAnchors::instanceBottomAnchorLine() const
{
return qmlItemNode().nodeInstance().position().y() + qmlItemNode().nodeInstance().size().height();
return contentRect(qmlItemNode().nodeInstance()).y() + contentRect(qmlItemNode().nodeInstance()).height();
}
double QmlAnchors::instanceHorizontalCenterAnchorLine() 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