forked from qt-creator/qt-creator
QmlDesigner: Fix painted bounding rectangle for step childs
We used only the bounding rectangle of the item under our control. But child items which are created in a component can be out side of the bounding rectangle. To fix compute a combined bounding rectangle of the item and all stepchildren. Stepchildren described the child not create directly by us. Change-Id: I7f25f112aa5eb2f80cfccec5d358221ab5e35d9b Reviewed-on: http://codereview.qt.nokia.com/839 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
This commit is contained in:
committed by
Thomas Hartmann
parent
014ef6e2db
commit
ddb602536c
@@ -244,9 +244,6 @@ SGItemNodeInstance::Pointer SGItemNodeInstance::create(QObject *object)
|
||||
instance->setHasContent(anyItemHasContent(sgItem));
|
||||
sgItem->setFlag(QSGItem::ItemHasContents, true);
|
||||
|
||||
if (sgItem->inherits("QSGText"))
|
||||
instance->setResizable(false);
|
||||
|
||||
static_cast<QDeclarativeParserStatus*>(sgItem)->classBegin();
|
||||
|
||||
instance->populateResetValueHash();
|
||||
@@ -274,96 +271,33 @@ bool SGItemNodeInstance::isSGItem() const
|
||||
|
||||
QSizeF SGItemNodeInstance::size() const
|
||||
{
|
||||
if (isValid()) {
|
||||
double implicitWidth = sgItem()->implicitWidth();
|
||||
if (!m_hasWidth
|
||||
&& implicitWidth // WORKAROUND
|
||||
&& sgItem()->width() <= 0
|
||||
&& implicitWidth != sgItem()->width()
|
||||
&& !hasBindingForProperty("width")) {
|
||||
sgItem()->blockSignals(true);
|
||||
sgItem()->setWidth(implicitWidth);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
|
||||
double implicitHeight = sgItem()->implicitHeight();
|
||||
if (!m_hasHeight
|
||||
&& implicitWidth // WORKAROUND
|
||||
&& sgItem()->height() <= 0
|
||||
&& implicitHeight != sgItem()->height()
|
||||
&& !hasBindingForProperty("height")) {
|
||||
sgItem()->blockSignals(true);
|
||||
sgItem()->setHeight(implicitHeight);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isRootNodeInstance()) {
|
||||
if (!m_hasWidth) {
|
||||
sgItem()->blockSignals(true);
|
||||
if (sgItem()->width() < 10.)
|
||||
sgItem()->setWidth(100.);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
|
||||
if (!m_hasHeight) {
|
||||
sgItem()->blockSignals(true);
|
||||
if (sgItem()->height() < 10.)
|
||||
sgItem()->setHeight(100.);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
return QSizeF(sgItem()->width(), sgItem()->height());
|
||||
}
|
||||
|
||||
QRectF SGItemNodeInstance::boundingRectWithStepChilds(QSGItem *parentItem) const
|
||||
{
|
||||
QRectF boundingRect = parentItem->boundingRect();
|
||||
|
||||
foreach (QSGItem *childItem, parentItem->childItems()) {
|
||||
if (nodeInstanceServer()->hasInstanceForObject(childItem)) {
|
||||
QRectF transformedRect = childItem->mapRectToItem(parentItem, childItemBoundingRect(childItem));
|
||||
boundingRect = boundingRect.united(transformedRect);
|
||||
}
|
||||
}
|
||||
|
||||
return boundingRect;
|
||||
}
|
||||
|
||||
QRectF SGItemNodeInstance::boundingRect() const
|
||||
{
|
||||
if (isValid()) {
|
||||
double implicitWidth = sgItem()->implicitWidth();
|
||||
if (!m_hasWidth
|
||||
&& implicitWidth // WORKAROUND
|
||||
&& sgItem()->width() <= 0
|
||||
&& implicitWidth != sgItem()->width()
|
||||
&& !hasBindingForProperty("width")) {
|
||||
sgItem()->blockSignals(true);
|
||||
sgItem()->setWidth(implicitWidth);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
|
||||
double implicitHeight = sgItem()->implicitHeight();
|
||||
if (!m_hasHeight
|
||||
&& implicitWidth // WORKAROUND
|
||||
&& sgItem()->height() <= 0
|
||||
&& implicitHeight != sgItem()->height()
|
||||
&& !hasBindingForProperty("height")) {
|
||||
sgItem()->blockSignals(true);
|
||||
sgItem()->setHeight(implicitHeight);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isRootNodeInstance()) {
|
||||
if (!m_hasWidth) {
|
||||
sgItem()->blockSignals(true);
|
||||
if (sgItem()->width() < 10.)
|
||||
sgItem()->setWidth(100.);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
|
||||
if (!m_hasHeight) {
|
||||
sgItem()->blockSignals(true);
|
||||
if (sgItem()->height() < 10.)
|
||||
sgItem()->setHeight(100.);
|
||||
sgItem()->blockSignals(false);
|
||||
if (sgItem()) {
|
||||
if (sgItem()->clip()) {
|
||||
return sgItem()->boundingRect();
|
||||
} else {
|
||||
return boundingRectWithStepChilds();
|
||||
}
|
||||
}
|
||||
|
||||
if (sgItem())
|
||||
return sgItem()->boundingRect();
|
||||
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
@@ -409,30 +343,6 @@ void SGItemNodeInstance::setPropertyBinding(const QString &name, const QString &
|
||||
|
||||
QVariant SGItemNodeInstance::property(const QString &name) const
|
||||
{
|
||||
if (name == "width" && !hasBindingForProperty("width")) {
|
||||
double implicitWidth = sgItem()->implicitWidth();
|
||||
if (!m_hasWidth
|
||||
&& implicitWidth // WORKAROUND
|
||||
&& sgItem()->width() <= 0
|
||||
&& implicitWidth != sgItem()->width()) {
|
||||
sgItem()->blockSignals(true);
|
||||
sgItem()->setWidth(implicitWidth);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (name == "height" && !hasBindingForProperty("height")) {
|
||||
double implicitHeight = sgItem()->implicitHeight();
|
||||
if (!m_hasHeight
|
||||
&& implicitHeight // WORKAROUND
|
||||
&& sgItem()->width() <= 0
|
||||
&& implicitHeight != sgItem()->height()) {
|
||||
sgItem()->blockSignals(true);
|
||||
sgItem()->setHeight(implicitHeight);
|
||||
sgItem()->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
return ObjectNodeInstance::property(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,6 +149,7 @@ protected:
|
||||
void resetHorizontal();
|
||||
void resetVertical();
|
||||
void refresh();
|
||||
QRectF boundingRectWithStepChilds(QSGItem *parentItem) const;
|
||||
|
||||
private: //variables
|
||||
bool m_hasHeight;
|
||||
|
||||
@@ -179,9 +179,32 @@ QObject *GraphicsObjectNodeInstance::parent() const
|
||||
return graphicsObject()->parentItem()->toGraphicsObject();
|
||||
}
|
||||
|
||||
QRectF GraphicsObjectNodeInstance::boundingRectWithStepChilds(QGraphicsItem *parentItem) const
|
||||
{
|
||||
QRectF boundingRect = parentItem->boundingRect();
|
||||
|
||||
foreach (QGraphicsItem *childItem, parentItem->childItems()) {
|
||||
QGraphicsObject *childObject = childItem->toGraphicsObject();
|
||||
if (!(childObject && nodeInstanceServer()->hasInstanceForObject(childObject))) {
|
||||
QRectF transformedRect = childItem->mapRectToParent(boundingRectWithStepChilds(childItem));
|
||||
boundingRect = boundingRect.united(transformedRect);
|
||||
}
|
||||
}
|
||||
|
||||
return boundingRect;
|
||||
}
|
||||
|
||||
QRectF GraphicsObjectNodeInstance::boundingRect() const
|
||||
{
|
||||
return graphicsObject()->boundingRect();
|
||||
if (graphicsObject()) {
|
||||
if (graphicsObject()->flags() & QGraphicsItem::ItemClipsChildrenToShape) {
|
||||
return graphicsObject()->boundingRect();
|
||||
} else {
|
||||
return boundingRectWithStepChilds(graphicsObject());
|
||||
}
|
||||
}
|
||||
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
bool GraphicsObjectNodeInstance::isGraphicsObject() const
|
||||
@@ -217,7 +240,7 @@ void initOption(QGraphicsItem *item, QStyleOptionGraphicsItem *option, const QTr
|
||||
|
||||
QImage GraphicsObjectNodeInstance::renderImage() const
|
||||
{
|
||||
QRectF boundingRect = graphicsObject()->boundingRect();
|
||||
QRectF boundingRect = GraphicsObjectNodeInstance::boundingRect();
|
||||
QSize boundingSize = boundingRect.size().toSize();
|
||||
|
||||
QImage image(boundingSize, QImage::Format_ARGB32_Premultiplied);
|
||||
|
||||
@@ -87,6 +87,8 @@ protected:
|
||||
void setHasContent(bool hasContent);
|
||||
QGraphicsObject *graphicsObject() const;
|
||||
void paintRecursively(QGraphicsItem *graphicsItem, QPainter *painter) const;
|
||||
QRectF boundingRectWithStepChilds(QGraphicsItem *parentItem) const;
|
||||
|
||||
|
||||
private: // variables
|
||||
bool m_hasContent;
|
||||
|
||||
@@ -107,14 +107,6 @@ QSizeF QmlGraphicsItemNodeInstance::size() const
|
||||
return QSizeF(qmlGraphicsItem()->width(), qmlGraphicsItem()->height());
|
||||
}
|
||||
|
||||
QRectF QmlGraphicsItemNodeInstance::boundingRect() const
|
||||
{
|
||||
if (qmlGraphicsItem())
|
||||
return qmlGraphicsItem()->boundingRect();
|
||||
|
||||
return QRectF();
|
||||
}
|
||||
|
||||
void QmlGraphicsItemNodeInstance::setPropertyVariant(const QString &name, const QVariant &value)
|
||||
{
|
||||
if (name == "state")
|
||||
@@ -157,30 +149,6 @@ void QmlGraphicsItemNodeInstance::setPropertyBinding(const QString &name, const
|
||||
|
||||
QVariant QmlGraphicsItemNodeInstance::property(const QString &name) const
|
||||
{
|
||||
if (name == "width" && !hasBindingForProperty("width")) {
|
||||
double implicitWidth = qmlGraphicsItem()->implicitWidth();
|
||||
if (!m_hasWidth
|
||||
&& implicitWidth // WORKAROUND
|
||||
&& qmlGraphicsItem()->width() <= 0
|
||||
&& implicitWidth != qmlGraphicsItem()->width()) {
|
||||
qmlGraphicsItem()->blockSignals(true);
|
||||
qmlGraphicsItem()->setWidth(implicitWidth);
|
||||
qmlGraphicsItem()->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (name == "height" && !hasBindingForProperty("height")) {
|
||||
double implicitHeight = qmlGraphicsItem()->implicitHeight();
|
||||
if (!m_hasHeight
|
||||
&& implicitHeight // WORKAROUND
|
||||
&& qmlGraphicsItem()->width() <= 0
|
||||
&& implicitHeight != qmlGraphicsItem()->height()) {
|
||||
qmlGraphicsItem()->blockSignals(true);
|
||||
qmlGraphicsItem()->setHeight(implicitHeight);
|
||||
qmlGraphicsItem()->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
||||
return GraphicsObjectNodeInstance::property(name);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,6 @@ public:
|
||||
bool isQmlGraphicsItem() const;
|
||||
|
||||
QSizeF size() const;
|
||||
QRectF boundingRect() const;
|
||||
// void updateAnchors();
|
||||
|
||||
void setPropertyVariant(const QString &name, const QVariant &value);
|
||||
|
||||
@@ -105,8 +105,8 @@ void ResizeManipulator::begin(const QPointF &/*beginPoint*/)
|
||||
|
||||
void ResizeManipulator::update(const QPointF& updatePoint, Snapping useSnapping)
|
||||
{
|
||||
const double minimumWidth = 15.0;
|
||||
const double minimumHeight = 15.0;
|
||||
const double minimumWidth = 0.0;
|
||||
const double minimumHeight = 0.0;
|
||||
|
||||
deleteSnapLines();
|
||||
|
||||
@@ -471,7 +471,7 @@ void ResizeManipulator::moveBy(double deltaX, double deltaY)
|
||||
|
||||
bool ResizeManipulator::isInvalidSize(const QSizeF & size)
|
||||
{
|
||||
if (size.width() < 15 || size.height() < 15)
|
||||
if (size.width() < 0 || size.height() < 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user