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

Fix the border handling

Task-number: BAUHAUS-259
parent 84732bea
......@@ -185,7 +185,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
boundingRect.setTop(boundingRect.top() - minimumHeight + boundingRect.height());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft()));
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Top)) {
......@@ -226,7 +226,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
boundingRect.setWidth(minimumWidth);
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft()));
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Top)) {
anchors.setMargin(AnchorLine::Top,
......@@ -266,7 +266,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
boundingRect.setLeft(boundingRect.left() - minimumWidth + boundingRect.width());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft()));
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Left)) {
anchors.setMargin(AnchorLine::Left,
......@@ -320,7 +320,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
boundingRect.setTop(boundingRect.top() - minimumHeight + boundingRect.height());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft()));
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Top)) {
anchors.setMargin(AnchorLine::Top,
......@@ -370,7 +370,7 @@ void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
boundingRect.setLeft(boundingRect.left() - minimumWidth + boundingRect.width());
formEditorItem->qmlItemNode().setSize(boundingRect.size());
formEditorItem->qmlItemNode().setPosition(m_beginToParentTransform.map(boundingRect.topLeft()));
formEditorItem->qmlItemNode().setPositionWithBorder(m_beginToParentTransform.map(boundingRect.topLeft()));
if (anchors.instanceHasAnchor(AnchorLine::Left)) {
anchors.setMargin(AnchorLine::Left,
......
......@@ -129,6 +129,8 @@ public:
bool isAnchoredBy() const;
QPair<QString, NodeInstance> anchor(const QString &name) const;
int penWidth() const;
private: // functions
NodeInstance(const QSharedPointer<Internal::ObjectNodeInstance> &abstractInstance);
......
......@@ -76,6 +76,7 @@ public:
void setSize(const QSizeF &size);
void setPosition(const QPointF &position);
void setPositionWithBorder(const QPointF &position);
void selectNode();
void deselectNode();
......
......@@ -455,6 +455,11 @@ bool NodeInstance::hasAnchor(const QString &name) const
return m_nodeInstance->hasAnchor(name);
}
int NodeInstance::penWidth() const
{
return m_nodeInstance->penWidth();
}
bool NodeInstance::isAnchoredBy() const
{
return m_nodeInstance->isAnchoredBy();
......
......@@ -661,6 +661,11 @@ QSizeF ObjectNodeInstance::size() const
return QSizeF();
}
int ObjectNodeInstance::penWidth() const
{
return 0;
}
bool ObjectNodeInstance::isVisible() const
{
return false;
......
......@@ -122,6 +122,8 @@ public:
virtual QTransform sceneTransform() const;
virtual double opacity() const;
virtual int penWidth() const;
virtual bool hasAnchor(const QString &name) const;
virtual QPair<QString, NodeInstance> anchor(const QString &name) const;
virtual bool isAnchoredBy() const;
......
......@@ -40,7 +40,7 @@
#include <private/qmlgraphicsanchors_p.h>
#include <private/qmlgraphicsanchors_p_p.h>
#include <private/qmlgraphicsrectangle_p.h>
#include <private/qmlexpression_p.h>
#include <cmath>
......@@ -226,6 +226,14 @@ void QmlGraphicsItemNodeInstance::resetVertical()
setPropertyVariant("height", qmlGraphicsItem()->implicitHeight());
}
int QmlGraphicsItemNodeInstance::penWidth() const
{
QmlGraphicsRectangle *qmlGraphcisRectangle = qobject_cast<QmlGraphicsRectangle*>(object());
if (qmlGraphcisRectangle)
return qmlGraphcisRectangle->border()->width();
return GraphicsObjectNodeInstance::penWidth();
}
void QmlGraphicsItemNodeInstance::resetProperty(const QString &name)
{
......
......@@ -60,6 +60,8 @@ public:
QVariant property(const QString &name) const;
void resetProperty(const QString &name);
int penWidth() const;
bool hasAnchor(const QString &name) const;
QPair<QString, NodeInstance> anchor(const QString &name) const;
bool isAnchoredBy() const;
......
......@@ -200,8 +200,8 @@ void QmlItemNode::paintInstance(QPainter *painter) const
void QmlItemNode::setSize(const QSizeF &size)
{
RewriterTransaction transaction = qmlModelView()->beginRewriterTransaction();
setVariantProperty("width", qRound(size.width()));
setVariantProperty("height", qRound(size.height()));
setVariantProperty("width", qRound(size.width()) - (nodeInstance().penWidth()));
setVariantProperty("height", qRound(size.height()) - (nodeInstance().penWidth()));
}
void QmlItemNode::setPosition(const QPointF &position)
......@@ -211,6 +211,13 @@ void QmlItemNode::setPosition(const QPointF &position)
setVariantProperty("y", qRound(position.y()));
}
void QmlItemNode::setPositionWithBorder(const QPointF &position)
{
RewriterTransaction transaction = qmlModelView()->beginRewriterTransaction();
setVariantProperty("x", qRound(position.x()) + (nodeInstance().penWidth() / 2));
setVariantProperty("y", qRound(position.y()) + (nodeInstance().penWidth() / 2));
}
void QmlItemNode::selectNode()
{
modelNode().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