summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativeitem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativeitem.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp188
1 files changed, 88 insertions, 100 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index ccad8f1..f575fdb 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -312,9 +312,9 @@ void QDeclarativeContents::setItem(QDeclarativeItem *item)
QDeclarativeItem *child = qobject_cast<QDeclarativeItem *>(children.at(i));
if(!child)//### Should this be ignoring non-QDeclarativeItem graphicsobjects?
continue;
- connect(child, SIGNAL(heightChanged(qreal)), this, SLOT(calcHeight()));
+ connect(child, SIGNAL(heightChanged()), this, SLOT(calcHeight()));
connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight()));
- connect(child, SIGNAL(widthChanged(qreal)), this, SLOT(calcWidth()));
+ connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth()));
connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth()));
connect(this, SIGNAL(rectChanged(QRectF)), m_item, SIGNAL(childrenRectChanged(QRectF)));
}
@@ -1273,16 +1273,6 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec
*/
/*!
- \fn void QDeclarativeItem::widthChanged(qreal)
- \internal
-*/
-
-/*!
- \fn void QDeclarativeItem::heightChanged(qreal)
- \internal
-*/
-
-/*!
\fn void QDeclarativeItem::stateChanged(const QString &state)
\internal
*/
@@ -1462,11 +1452,6 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const
*/
/*!
- \property QDeclarativeItem::children
- \internal
-*/
-
-/*!
\property QDeclarativeItem::resources
\internal
*/
@@ -1500,11 +1485,12 @@ QDeclarativeAnchors *QDeclarativeItem::anchors()
void QDeclarativeItemPrivate::data_append(QDeclarativeListProperty<QObject> *prop, QObject *o)
{
- QDeclarativeItem *i = qobject_cast<QDeclarativeItem *>(o);
- if (i)
+ QGraphicsObject *i = qobject_cast<QGraphicsObject *>(o);
+ if (i) {
i->setParentItem(static_cast<QDeclarativeItem *>(prop->object));
- else
+ } else {
o->setParent(static_cast<QDeclarativeItem *>(prop->object));
+ }
}
QObject *QDeclarativeItemPrivate::resources_at(QDeclarativeListProperty<QObject> *prop, int index)
@@ -1526,27 +1512,6 @@ int QDeclarativeItemPrivate::resources_count(QDeclarativeListProperty<QObject> *
return prop->object->children().count();
}
-QDeclarativeItem *QDeclarativeItemPrivate::children_at(QDeclarativeListProperty<QDeclarativeItem> *prop, int index)
-{
- QList<QGraphicsItem *> children = static_cast<QDeclarativeItem*>(prop->object)->childItems();
-
- if (index < children.count())
- return qobject_cast<QDeclarativeItem *>(children.at(index));
- else
- return 0;
-}
-
-void QDeclarativeItemPrivate::children_append(QDeclarativeListProperty<QDeclarativeItem> *prop, QDeclarativeItem *i)
-{
- if (i)
- i->setParentItem(static_cast<QDeclarativeItem*>(prop->object));
-}
-
-int QDeclarativeItemPrivate::children_count(QDeclarativeListProperty<QDeclarativeItem> *prop)
-{
- return static_cast<QDeclarativeItem*>(prop->object)->childItems().count();
-}
-
int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsTransform> *list)
{
QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object);
@@ -1589,6 +1554,14 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics
}
}
+void QDeclarativeItemPrivate::parentProperty(QObject *o, void *rv, QDeclarativeNotifierEndpoint *e)
+{
+ QDeclarativeItem *item = static_cast<QDeclarativeItem*>(o);
+ if (e)
+ e->connect(&item->d_func()->parentNotifier);
+ *((QDeclarativeItem **)rv) = item->parentItem();
+}
+
/*!
\qmlproperty list<Object> Item::data
\default
@@ -1678,18 +1651,6 @@ void QDeclarativeItem::setClip(bool c)
*/
/*!
- \property QDeclarativeItem::width
-
- Defines the item's width relative to its parent.
- */
-
-/*!
- \property QDeclarativeItem::height
-
- Defines the item's height relative to its parent.
- */
-
-/*!
\qmlproperty real Item::z
Sets the stacking order of the item. By default the stacking order is 0.
@@ -1801,11 +1762,11 @@ void QDeclarativeItem::geometryChanged(const QRectF &newGeometry,
if (newGeometry.x() != oldGeometry.x())
emit xChanged();
if (newGeometry.width() != oldGeometry.width())
- emit widthChanged(newGeometry.width());
+ emit widthChanged();
if (newGeometry.y() != oldGeometry.y())
emit yChanged();
if (newGeometry.height() != oldGeometry.height())
- emit heightChanged(newGeometry.height());
+ emit heightChanged();
for(int ii = 0; ii < d->changeListeners.count(); ++ii) {
const QDeclarativeItemPrivate::ChangeListener &change = d->changeListeners.at(ii);
@@ -2281,14 +2242,6 @@ void QDeclarativeItemPrivate::focusChanged(bool flag)
}
/*! \internal */
-QDeclarativeListProperty<QDeclarativeItem> QDeclarativeItem::fxChildren()
-{
- return QDeclarativeListProperty<QDeclarativeItem>(this, 0, QDeclarativeItemPrivate::children_append,
- QDeclarativeItemPrivate::children_count,
- QDeclarativeItemPrivate::children_at);
-}
-
-/*! \internal */
QDeclarativeListProperty<QObject> QDeclarativeItem::resources()
{
return QDeclarativeListProperty<QObject>(this, 0, QDeclarativeItemPrivate::resources_append,
@@ -2594,10 +2547,11 @@ bool QDeclarativeItem::sceneEvent(QEvent *event)
QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
const QVariant &value)
{
- Q_D(const QDeclarativeItem);
+ Q_D(QDeclarativeItem);
switch (change) {
case ItemParentHasChanged:
emit parentChanged(parentItem());
+ d->parentNotifier.notify();
break;
case ItemChildAddedChange:
case ItemChildRemovedChange:
@@ -2632,7 +2586,7 @@ QVariant QDeclarativeItem::itemChange(GraphicsItemChange change,
QRectF QDeclarativeItem::boundingRect() const
{
Q_D(const QDeclarativeItem);
- return QRectF(0, 0, d->width, d->height);
+ return QRectF(0, 0, d->mWidth, d->mHeight);
}
/*!
@@ -2717,33 +2671,50 @@ void QDeclarativeItem::setSmooth(bool smooth)
qreal QDeclarativeItem::width() const
{
Q_D(const QDeclarativeItem);
- return d->width;
+ return d->width();
}
void QDeclarativeItem::setWidth(qreal w)
{
Q_D(QDeclarativeItem);
+ d->setWidth(w);
+}
+
+void QDeclarativeItem::resetWidth()
+{
+ Q_D(QDeclarativeItem);
+ d->resetWidth();
+}
+
+qreal QDeclarativeItemPrivate::width() const
+{
+ return mWidth;
+}
+
+void QDeclarativeItemPrivate::setWidth(qreal w)
+{
+ Q_Q(QDeclarativeItem);
if (qIsNaN(w))
return;
- d->widthValid = true;
- if (d->width == w)
+ widthValid = true;
+ if (mWidth == w)
return;
- qreal oldWidth = d->width;
+ qreal oldWidth = mWidth;
- prepareGeometryChange();
- d->width = w;
+ q->prepareGeometryChange();
+ mWidth = w;
- geometryChanged(QRectF(x(), y(), width(), height()),
- QRectF(x(), y(), oldWidth, height()));
+ q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
+ QRectF(q->x(), q->y(), oldWidth, height()));
}
-void QDeclarativeItem::resetWidth()
+void QDeclarativeItemPrivate ::resetWidth()
{
- Q_D(QDeclarativeItem);
- d->widthValid = false;
- setImplicitWidth(implicitWidth());
+ Q_Q(QDeclarativeItem);
+ widthValid = false;
+ q->setImplicitWidth(q->implicitWidth());
}
/*!
@@ -2763,13 +2734,13 @@ void QDeclarativeItem::setImplicitWidth(qreal w)
{
Q_D(QDeclarativeItem);
d->implicitWidth = w;
- if (d->width == w || widthValid())
+ if (d->mWidth == w || widthValid())
return;
- qreal oldWidth = d->width;
+ qreal oldWidth = d->mWidth;
prepareGeometryChange();
- d->width = w;
+ d->mWidth = w;
geometryChanged(QRectF(x(), y(), width(), height()),
QRectF(x(), y(), oldWidth, height()));
@@ -2787,33 +2758,50 @@ bool QDeclarativeItem::widthValid() const
qreal QDeclarativeItem::height() const
{
Q_D(const QDeclarativeItem);
- return d->height;
+ return d->height();
}
void QDeclarativeItem::setHeight(qreal h)
{
Q_D(QDeclarativeItem);
+ d->setHeight(h);
+}
+
+void QDeclarativeItem::resetHeight()
+{
+ Q_D(QDeclarativeItem);
+ d->resetHeight();
+}
+
+qreal QDeclarativeItemPrivate::height() const
+{
+ return mHeight;
+}
+
+void QDeclarativeItemPrivate::setHeight(qreal h)
+{
+ Q_Q(QDeclarativeItem);
if (qIsNaN(h))
return;
- d->heightValid = true;
- if (d->height == h)
+ heightValid = true;
+ if (mHeight == h)
return;
- qreal oldHeight = d->height;
+ qreal oldHeight = mHeight;
- prepareGeometryChange();
- d->height = h;
+ q->prepareGeometryChange();
+ mHeight = h;
- geometryChanged(QRectF(x(), y(), width(), height()),
- QRectF(x(), y(), width(), oldHeight));
+ q->geometryChanged(QRectF(q->x(), q->y(), width(), height()),
+ QRectF(q->x(), q->y(), width(), oldHeight));
}
-void QDeclarativeItem::resetHeight()
+void QDeclarativeItemPrivate::resetHeight()
{
- Q_D(QDeclarativeItem);
- d->heightValid = false;
- setImplicitHeight(implicitHeight());
+ Q_Q(QDeclarativeItem);
+ heightValid = false;
+ q->setImplicitHeight(q->implicitHeight());
}
/*!
@@ -2833,13 +2821,13 @@ void QDeclarativeItem::setImplicitHeight(qreal h)
{
Q_D(QDeclarativeItem);
d->implicitHeight = h;
- if (d->height == h || heightValid())
+ if (d->mHeight == h || heightValid())
return;
- qreal oldHeight = d->height;
+ qreal oldHeight = d->mHeight;
prepareGeometryChange();
- d->height = h;
+ d->mHeight = h;
geometryChanged(QRectF(x(), y(), width(), height()),
QRectF(x(), y(), width(), oldHeight));
@@ -2861,15 +2849,15 @@ void QDeclarativeItem::setSize(const QSizeF &size)
d->heightValid = true;
d->widthValid = true;
- if (d->height == size.height() && d->width == size.width())
+ if (d->height() == size.height() && d->width() == size.width())
return;
- qreal oldHeight = d->height;
- qreal oldWidth = d->width;
+ qreal oldHeight = d->height();
+ qreal oldWidth = d->width();
prepareGeometryChange();
- d->height = size.height();
- d->width = size.width();
+ d->setHeight(size.height());
+ d->setWidth(size.width());
geometryChanged(QRectF(x(), y(), width(), height()),
QRectF(x(), y(), oldWidth, oldHeight));