QmlDesigner: Split between bounding rectangle and painted bounding rectangle

In qml the interactive bounding rectangle is always
QRectF(0, 0, width, height). The painted bounding rectangle can differ from
this logical one. This change is much more near to the qml description.

Change-Id: I139cb70512fa1ed003b28ca2ae512f4e33e915e5
Reviewed-on: http://codereview.qt.nokia.com/812
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
Marco Bubke
2011-06-27 21:56:01 +02:00
committed by Thomas Hartmann
parent 415680d6e8
commit 0fcc6afd8f
5 changed files with 11 additions and 92 deletions

View File

@@ -90,9 +90,6 @@ QmlGraphicsItemNodeInstance::Pointer QmlGraphicsItemNodeInstance::create(QObject
instance->setHasContent(anyItemHasContent(qmlGraphicsItem));
qmlGraphicsItem->setFlag(QGraphicsItem::ItemHasNoContents, false);
if (qmlGraphicsItem->inherits("QDeclarativeText"))
instance->setResizable(false);
static_cast<QDeclarativeParserStatus*>(qmlGraphicsItem)->classBegin();
instance->populateResetValueHash();
@@ -107,93 +104,11 @@ bool QmlGraphicsItemNodeInstance::isQmlGraphicsItem() const
QSizeF QmlGraphicsItemNodeInstance::size() const
{
if (isValid()) {
double implicitWidth = qmlGraphicsItem()->implicitWidth();
if (!m_hasWidth
&& implicitWidth // WORKAROUND
&& qmlGraphicsItem()->width() <= 0
&& implicitWidth != qmlGraphicsItem()->width()
&& !hasBindingForProperty("width")) {
qmlGraphicsItem()->blockSignals(true);
qmlGraphicsItem()->setWidth(implicitWidth);
qmlGraphicsItem()->blockSignals(false);
}
double implicitHeight = qmlGraphicsItem()->implicitHeight();
if (!m_hasHeight
&& implicitWidth // WORKAROUND
&& qmlGraphicsItem()->height() <= 0
&& implicitHeight != qmlGraphicsItem()->height()
&& !hasBindingForProperty("height")) {
qmlGraphicsItem()->blockSignals(true);
qmlGraphicsItem()->setHeight(implicitHeight);
qmlGraphicsItem()->blockSignals(false);
}
}
if (isRootNodeInstance()) {
if (!m_hasWidth) {
qmlGraphicsItem()->blockSignals(true);
if (qmlGraphicsItem()->width() < 10.)
qmlGraphicsItem()->setWidth(100.);
qmlGraphicsItem()->blockSignals(false);
}
if (!m_hasHeight) {
qmlGraphicsItem()->blockSignals(true);
if (qmlGraphicsItem()->height() < 10.)
qmlGraphicsItem()->setHeight(100.);
qmlGraphicsItem()->blockSignals(false);
}
}
return QSizeF(qmlGraphicsItem()->width(), qmlGraphicsItem()->height());
}
QRectF QmlGraphicsItemNodeInstance::boundingRect() const
{
if (isValid()) {
double implicitWidth = qmlGraphicsItem()->implicitWidth();
if (!m_hasWidth
&& implicitWidth // WORKAROUND
&& qmlGraphicsItem()->width() <= 0
&& implicitWidth != qmlGraphicsItem()->width()
&& !hasBindingForProperty("width")) {
qmlGraphicsItem()->blockSignals(true);
qmlGraphicsItem()->setWidth(implicitWidth);
qmlGraphicsItem()->blockSignals(false);
}
double implicitHeight = qmlGraphicsItem()->implicitHeight();
if (!m_hasHeight
&& implicitWidth // WORKAROUND
&& qmlGraphicsItem()->height() <= 0
&& implicitHeight != qmlGraphicsItem()->height()
&& !hasBindingForProperty("height")) {
qmlGraphicsItem()->blockSignals(true);
qmlGraphicsItem()->setHeight(implicitHeight);
qmlGraphicsItem()->blockSignals(false);
}
}
if (isRootNodeInstance()) {
if (!m_hasWidth) {
qmlGraphicsItem()->blockSignals(true);
if (qmlGraphicsItem()->width() < 10.)
qmlGraphicsItem()->setWidth(100.);
qmlGraphicsItem()->blockSignals(false);
}
if (!m_hasHeight) {
qmlGraphicsItem()->blockSignals(true);
if (qmlGraphicsItem()->height() < 10.)
qmlGraphicsItem()->setHeight(100.);
qmlGraphicsItem()->blockSignals(false);
}
}
if (qmlGraphicsItem())
return qmlGraphicsItem()->boundingRect();

View File

@@ -99,7 +99,7 @@ QRectF FormEditorItem::boundingRect() const
void FormEditorItem::updateGeometry()
{
prepareGeometryChange();
m_boundingRect = qmlItemNode().instanceBoundingRect().adjusted(0, 0, 1., 1.);
m_boundingRect = qmlItemNode().instancePaintedBoundingRect().adjusted(0, 0, 1., 1.);
setTransform(qmlItemNode().instanceTransform());
setTransform(m_attentionTransform, true);
//the property for zValue is called z in QGraphicsObject

View File

@@ -518,21 +518,19 @@ bool ResizeManipulator::isActive() const
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);
itemNode.setVariantProperty("width", qRound(size.width()));
if (!itemNode.hasBindingProperty("height"))
itemNode.setVariantProperty("height", qRound(size.height()) - penWidth);
itemNode.setVariantProperty("height", qRound(size.height()));
}
void ResizeManipulator::setPosition(QmlItemNode itemNode, const QPointF &position)
{
if (!itemNode.hasBindingProperty("x"))
itemNode.setVariantProperty("x", qRound(position.x()) + (itemNode.instancePenWidth() / 2));
itemNode.setVariantProperty("x", qRound(position.x()));
if (!itemNode.hasBindingProperty("y"))
itemNode.setVariantProperty("y", qRound(position.y()) + (itemNode.instancePenWidth() / 2));
itemNode.setVariantProperty("y", qRound(position.y()));
}
}

View File

@@ -76,6 +76,7 @@ public:
bool instanceIsInPositioner() const;
QRectF instanceBoundingRect() const;
QRectF instancePaintedBoundingRect() const;
QTransform instanceTransform() const;
QTransform instanceSceneTransform() const;
QPointF instancePosition() const;

View File

@@ -220,6 +220,11 @@ bool QmlItemNode::instanceIsInPositioner() const
}
QRectF QmlItemNode::instanceBoundingRect() const
{
return QRectF(QPointF(0, 0), nodeInstance().size());
}
QRectF QmlItemNode::instancePaintedBoundingRect() const
{
return nodeInstance().boundingRect();
}