Commit ae9da516 authored by Marco Bubke's avatar Marco Bubke

Don't overwrite bindings

parent 49edd820
......@@ -145,15 +145,29 @@ void MoveManipulator::begin(const QPointF &beginPoint)
QPointF MoveManipulator::findSnappingOffset(const QList<QRectF> &boundingRectList)
QPointF MoveManipulator::findSnappingOffset(const QHash<FormEditorItem*, QRectF> &boundingRectHash)
{
QPointF offset;
QMap<double, double> verticalOffsetMap;
foreach (const QRectF &boundingRect, boundingRectList) {
double verticalOffset = m_snapper.snappedVerticalOffset(boundingRect);
if (verticalOffset < std::numeric_limits<double>::max())
verticalOffsetMap.insert(qAbs(verticalOffset), verticalOffset);
QMap<double, double> horizontalOffsetMap;
QHashIterator<FormEditorItem*, QRectF> hashIterator(boundingRectHash);
while(hashIterator.hasNext()) {
hashIterator.next();
FormEditorItem *formEditorItem = hashIterator.key();
QRectF boundingRect = hashIterator.value();
if (!formEditorItem->qmlItemNode().hasBindingProperty("x")) {
double verticalOffset = m_snapper.snappedVerticalOffset(boundingRect);
if (verticalOffset < std::numeric_limits<double>::max())
verticalOffsetMap.insert(qAbs(verticalOffset), verticalOffset);
}
if (!formEditorItem->qmlItemNode().hasBindingProperty("y")) {
double horizontalOffset = m_snapper.snappedHorizontalOffset(boundingRect);
if (horizontalOffset < std::numeric_limits<double>::max())
horizontalOffsetMap.insert(qAbs(horizontalOffset), horizontalOffset);
}
}
......@@ -161,15 +175,6 @@ QPointF MoveManipulator::findSnappingOffset(const QList<QRectF> &boundingRectLis
offset.rx() = verticalOffsetMap.begin().value();
QMap<double, double> horizontalOffsetMap;
foreach (const QRectF &boundingRect, boundingRectList) {
double horizontalOffset = m_snapper.snappedHorizontalOffset(boundingRect);
if (horizontalOffset < std::numeric_limits<double>::max())
horizontalOffsetMap.insert(qAbs(horizontalOffset), horizontalOffset);
}
if (!horizontalOffsetMap.isEmpty())
offset.ry() = horizontalOffsetMap.begin().value();
......@@ -177,22 +182,33 @@ QPointF MoveManipulator::findSnappingOffset(const QList<QRectF> &boundingRectLis
}
void MoveManipulator::generateSnappingLines(const QList<QRectF> &boundingRectList)
void MoveManipulator::generateSnappingLines(const QHash<FormEditorItem*, QRectF> &boundingRectHash)
{
m_graphicsLineList = m_snapper.generateSnappingLines(boundingRectList,
m_graphicsLineList = m_snapper.generateSnappingLines(boundingRectHash.values(),
m_layerItem.data(),
m_snapper.transformtionSpaceFormEditorItem()->sceneTransform());
}
QList<QRectF> MoveManipulator::tanslatedBoundingRects(const QList<QRectF> &boundingRectList, const QPointF& offsetVector)
QHash<FormEditorItem*, QRectF> MoveManipulator::tanslatedBoundingRects(const QHash<FormEditorItem*, QRectF> &boundingRectHash, const QPointF& offsetVector)
{
QList<QRectF> translatedBoundingRectList;
foreach (const QRectF &boundingRect, boundingRectList)
translatedBoundingRectList.append(boundingRect.translated(offsetVector));
QHash<FormEditorItem*, QRectF> translatedBoundingRectHash;
QHashIterator<FormEditorItem*, QRectF> hashIterator(boundingRectHash);
while(hashIterator.hasNext()) {
QPointF alignedOffset(offsetVector);
hashIterator.next();
FormEditorItem *formEditorItem = hashIterator.key();
QRectF boundingRect = hashIterator.value();
if (formEditorItem->qmlItemNode().hasBindingProperty("x"))
alignedOffset.setX(0);
if (formEditorItem->qmlItemNode().hasBindingProperty("y"))
alignedOffset.setY(0);
translatedBoundingRectHash.insert(formEditorItem, boundingRect.translated(offsetVector));
}
return translatedBoundingRectList;
return translatedBoundingRectHash;
}
......@@ -220,8 +236,8 @@ void MoveManipulator::update(const QPointF& updatePoint, Snapping useSnapping, S
}
if (useSnapping == UseSnapping || useSnapping == UseSnappingAndAnchoring) {
offsetVector -= findSnappingOffset(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector));
generateSnappingLines(tanslatedBoundingRects(m_beginItemRectHash.values(), offsetVector));
offsetVector -= findSnappingOffset(tanslatedBoundingRects(m_beginItemRectHash, offsetVector));
generateSnappingLines(tanslatedBoundingRects(m_beginItemRectHash, offsetVector));
}
foreach (FormEditorItem* item, m_itemList) {
......@@ -255,7 +271,7 @@ void MoveManipulator::update(const QPointF& updatePoint, Snapping useSnapping, S
anchors.setMargin(AnchorLine::VerticalCenter, m_beginVerticalCenterHash.value(item) + offsetVector.y());
}
item->qmlItemNode().setPosition(positionInContainerSpace);
setPosition(item->qmlItemNode(), positionInContainerSpace);
} else {
item->qmlItemNode().modelNode().variantProperty("x").setValue(qRound(positionInContainerSpace.x()));
item->qmlItemNode().modelNode().variantProperty("y").setValue(qRound(positionInContainerSpace.y()));
......@@ -345,8 +361,8 @@ void MoveManipulator::moveBy(double deltaX, double deltaY)
anchors.setMargin(AnchorLine::VerticalCenter, anchors.instanceMargin(AnchorLine::VerticalCenter) + deltaY);
}
item->qmlItemNode().setPosition(QPointF(item->qmlItemNode().instanceValue("x").toDouble() + deltaX,
item->qmlItemNode().instanceValue("y").toDouble() + deltaY));
setPosition(item->qmlItemNode(), QPointF(item->qmlItemNode().instanceValue("x").toDouble() + deltaX,
item->qmlItemNode().instanceValue("y").toDouble() + deltaY));
}
}
......@@ -381,4 +397,13 @@ bool MoveManipulator::isActive() const
return m_isActive;
}
void MoveManipulator::setPosition(QmlItemNode itemNode, const QPointF &position)
{
if (!itemNode.hasBindingProperty("x"))
itemNode.setVariantProperty("x", qRound(position.x()));
if (!itemNode.hasBindingProperty("y"))
itemNode.setVariantProperty("y", qRound(position.y()));
}
}
......@@ -86,19 +86,21 @@ public:
protected:
void setOpacityForAllElements(qreal opacity);
QPointF findSnappingOffset(const QList<QRectF> &boundingRectList);
QPointF findSnappingOffset(const QHash<FormEditorItem*, QRectF> &boundingRectHash);
void deleteSnapLines();
QList<QRectF> tanslatedBoundingRects(const QList<QRectF> &boundingRectList, const QPointF& offset);
QHash<FormEditorItem*, QRectF> tanslatedBoundingRects(const QHash<FormEditorItem*, QRectF> &boundingRectHash, const QPointF& offset);
QPointF calculateBoundingRectMovementOffset(const QPointF& updatePoint);
QRectF boundingRect(FormEditorItem* item, const QPointF& updatePoint);
void generateSnappingLines(const QList<QRectF> &boundingRectList);
void generateSnappingLines(const QHash<FormEditorItem*, QRectF> &boundingRectHash);
void updateHashes();
bool itemsCanReparented() const;
void setPosition(QmlItemNode itemNode, const QPointF &position);
private:
Snapper m_snapper;
QWeakPointer<LayerItem> m_layerItem;
......
......@@ -146,7 +146,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.height() < minimumHeight)
boundingRect.setHeight(minimumHeight);
formEditorItem->qmlItemNode().setSize(boundingRect.size());
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
if (anchors.instanceHasAnchor(AnchorLine::Bottom)) {
......@@ -186,8 +186,8 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.height() < minimumHeight)
boundingRect.setTop(boundingRect.top() - minimumHeight + boundingRect.height());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
setPosition(formEditorItem->qmlItemNode(), m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Top)) {
......@@ -227,8 +227,8 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.width() < minimumWidth)
boundingRect.setWidth(minimumWidth);
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
setPosition(formEditorItem->qmlItemNode(), m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Top)) {
anchors.setMargin(AnchorLine::Top,
......@@ -267,8 +267,8 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.width() < minimumWidth)
boundingRect.setLeft(boundingRect.left() - minimumWidth + boundingRect.width());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
setPosition(formEditorItem->qmlItemNode(), m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Left)) {
anchors.setMargin(AnchorLine::Left,
......@@ -297,7 +297,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.height() < minimumHeight)
boundingRect.setHeight(minimumHeight);
formEditorItem->qmlItemNode().setSize(boundingRect.size());
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
if (anchors.instanceHasAnchor(AnchorLine::Bottom)) {
anchors.setMargin(AnchorLine::Bottom,
......@@ -321,8 +321,8 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.height() < minimumHeight)
boundingRect.setTop(boundingRect.top() - minimumHeight + boundingRect.height());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
setPosition(formEditorItem->qmlItemNode(), m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Top)) {
anchors.setMargin(AnchorLine::Top,
......@@ -346,7 +346,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.width() < minimumWidth)
boundingRect.setWidth(minimumWidth);
formEditorItem->qmlItemNode().setSize(boundingRect.size());
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
if (anchors.instanceHasAnchor(AnchorLine::Right)) {
......@@ -371,8 +371,8 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
if (boundingRect.width() < minimumWidth)
boundingRect.setLeft(boundingRect.left() - minimumWidth + boundingRect.width());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
setSize(formEditorItem->qmlItemNode(), boundingRect.size());
setPosition(formEditorItem->qmlItemNode(), m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Left)) {
anchors.setMargin(AnchorLine::Left,
......@@ -503,4 +503,23 @@ void ResizeManipulator::clear()
removeHandle();
}
void ResizeManipulator::setSize(QmlItemNode itemNode, const QSizeF &size)
{
int penWidth = (itemNode.instancePenWidth() / 2) * 2;
if (!itemNode.hasBindingProperty("width"))
itemNode.setVariantProperty("width", qRound(size.width()) - penWidth);
if (!itemNode.hasBindingProperty("height"))
itemNode.setVariantProperty("height", qRound(size.height()) - penWidth);
}
void ResizeManipulator::setPosition(QmlItemNode itemNode, const QPointF &position)
{
if (!itemNode.hasBindingProperty("x"))
itemNode.setVariantProperty("x", qRound(position.x()) + (itemNode.instancePenWidth() / 2));
if (!itemNode.hasBindingProperty("y"))
itemNode.setVariantProperty("y", qRound(position.y()) + (itemNode.instancePenWidth() / 2));
}
}
......@@ -68,6 +68,8 @@ protected:
bool isInvalidSize(const QSizeF & size);
void deleteSnapLines();
ResizeHandleItem *resizeHandle();
void setSize(QmlItemNode itemNode, const QSizeF &size);
void setPosition(QmlItemNode itemNode, const QPointF &position);
private:
Snapper m_snapper;
......
......@@ -71,12 +71,10 @@ public:
QTransform instanceSceneTransform() const;
QPointF instancePosition() const;
QSizeF instanceSize() const;
int instancePenWidth() const;
void paintInstance(QPainter *painter) const;
void setSize(const QSizeF &size);
void setPosition(const QPointF &position);
void setPositionWithBorder(const QPointF &position);
void paintInstance(QPainter *painter) const;
void selectNode();
void deselectNode();
......
......@@ -196,6 +196,9 @@ QRectF QmlGraphicsItemNodeInstance::boundingRect() const
void QmlGraphicsItemNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
{
if (name == "state")
return; // states are only set by us
if (name == "height") {
if (value.isValid())
m_hasHeight = true;
......@@ -215,6 +218,9 @@ void QmlGraphicsItemNodeInstance::setPropertyVariant(const QString &name, const
void QmlGraphicsItemNodeInstance::setPropertyBinding(const QString &name, const QString &expression)
{
if (name == "state")
return; // states are only set by us
GraphicsObjectNodeInstance::setPropertyBinding(name, expression);
}
......
......@@ -191,32 +191,15 @@ QSizeF QmlItemNode::instanceSize() const
return nodeInstance().size();
}
void QmlItemNode::paintInstance(QPainter *painter) const
{
if (nodeInstance().isValid())
nodeInstance().paint(painter);
}
void QmlItemNode::setSize(const QSizeF &size)
int QmlItemNode::instancePenWidth() const
{
int penWidth = (nodeInstance().penWidth() / 2) * 2;
RewriterTransaction transaction = qmlModelView()->beginRewriterTransaction();
setVariantProperty("width", qRound(size.width()) - penWidth);
setVariantProperty("height", qRound(size.height()) - penWidth);
return nodeInstance().penWidth();
}
void QmlItemNode::setPosition(const QPointF &position)
{
RewriterTransaction transaction = qmlModelView()->beginRewriterTransaction();
setVariantProperty("x", qRound(position.x()));
setVariantProperty("y", qRound(position.y()));
}
void QmlItemNode::setPositionWithBorder(const QPointF &position)
void QmlItemNode::paintInstance(QPainter *painter) const
{
RewriterTransaction transaction = qmlModelView()->beginRewriterTransaction();
setVariantProperty("x", qRound(position.x()) + (nodeInstance().penWidth() / 2));
setVariantProperty("y", qRound(position.y()) + (nodeInstance().penWidth() / 2));
if (nodeInstance().isValid())
nodeInstance().paint(painter);
}
void QmlItemNode::selectNode()
......
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