Commit eab3a5eb authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.PropertyEditor: Fix relative anchor targets

If the target is the parent we want to anchor to the same edge by default.
If the target is a sibling we want to anchor to the opposite edge by default.

If the anchor target is changed we have to evaluate this.

Change-Id: I80ee52da7537435956880bcc132c2bc34ddfc0ed
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent 114d3843
......@@ -247,6 +247,42 @@ void QmlAnchorBindingProxy::emitAnchorSignals()
emit relativeAnchorTargetRightChanged();
}
void QmlAnchorBindingProxy::setDefaultRelativeTopTarget()
{
if (m_topTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeTopTarget = SameEdge;
} else {
m_relativeTopTarget = OppositeEdge;
}
}
void QmlAnchorBindingProxy::setDefaultRelativeBottomTarget()
{
if (m_bottomTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeBottomTarget = SameEdge;
} else {
m_relativeBottomTarget = OppositeEdge;
}
}
void QmlAnchorBindingProxy::setDefaultRelativeLeftTarget()
{
if (m_leftTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeLeftTarget = SameEdge;
} else {
m_relativeLeftTarget = OppositeEdge;
}
}
void QmlAnchorBindingProxy::setDefaultRelativeRightTarget()
{
if (m_rightTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeRightTarget = SameEdge;
} else {
m_relativeRightTarget = OppositeEdge;
}
}
bool QmlAnchorBindingProxy::hasParent()
{
return m_qmlItemNode.isValid() && m_qmlItemNode.hasNodeParent();
......@@ -304,6 +340,9 @@ void QmlAnchorBindingProxy::setTopTarget(const QString &target)
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchorBindingProxy::setTopTarget"));
m_topTarget = newTarget;
setDefaultRelativeTopTarget();
anchorTop();
emit topTargetChanged();
......@@ -326,6 +365,7 @@ void QmlAnchorBindingProxy::setBottomTarget(const QString &target)
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchorBindingProxy::setBottomTarget"));
m_bottomTarget = newTarget;
setDefaultRelativeBottomTarget();
anchorBottom();
emit bottomTargetChanged();
......@@ -347,6 +387,7 @@ void QmlAnchorBindingProxy::setLeftTarget(const QString &target)
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchorBindingProxy::setLeftTarget"));
m_leftTarget = newTarget;
setDefaultRelativeLeftTarget();
anchorLeft();
emit leftTargetChanged();
......@@ -368,6 +409,7 @@ void QmlAnchorBindingProxy::setRightTarget(const QString &target)
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction(QByteArrayLiteral("QmlAnchorBindingProxy::setRightTarget"));
m_rightTarget = newTarget;
setDefaultRelativeRightTarget();
anchorRight();
emit rightTargetChanged();
......@@ -589,13 +631,7 @@ void QmlAnchorBindingProxy::setBottomAnchor(bool anchor)
if (!anchor) {
removeBottomAnchor();
} else {
if (m_bottomTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeBottomTarget = SameEdge;
} else {
m_relativeBottomTarget = OppositeEdge;
}
setDefaultRelativeBottomTarget();
anchorBottom();
if (topAnchored())
backupPropertyAndRemove(modelNode(), "height");
......@@ -621,12 +657,7 @@ void QmlAnchorBindingProxy::setLeftAnchor(bool anchor)
if (!anchor) {
removeLeftAnchor();
} else {
if (m_leftTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeLeftTarget = SameEdge;
} else {
m_relativeLeftTarget = OppositeEdge;
}
setDefaultRelativeLeftTarget();
anchorLeft();
backupPropertyAndRemove(modelNode(), "x");
......@@ -653,12 +684,7 @@ void QmlAnchorBindingProxy::setRightAnchor(bool anchor)
if (!anchor) {
removeRightAnchor();
} else {
if (m_rightTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeRightTarget = SameEdge;
} else {
m_relativeRightTarget = OppositeEdge;
}
setDefaultRelativeRightTarget();
anchorRight();
if (leftAnchored())
......@@ -847,12 +873,7 @@ void QmlAnchorBindingProxy::setTopAnchor(bool anchor)
if (!anchor) {
removeTopAnchor();
} else {
if (m_topTarget.modelNode() == m_qmlItemNode.modelNode().parentProperty().parentModelNode()) {
m_relativeTopTarget = SameEdge;
} else {
m_relativeTopTarget = OppositeEdge;
}
setDefaultRelativeTopTarget();
anchorTop();
backupPropertyAndRemove(modelNode(), "y");
......
......@@ -205,6 +205,11 @@ private:
void setupAnchorTargets();
void emitAnchorSignals();
void setDefaultRelativeTopTarget();
void setDefaultRelativeBottomTarget();
void setDefaultRelativeLeftTarget();
void setDefaultRelativeRightTarget();
QmlItemNode targetIdToNode(const QString &id) const;
QString idForNode(const QmlItemNode &qmlItemNode) 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