diff options
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativeitem.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativeitem.cpp | 255 |
1 files changed, 135 insertions, 120 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp index ccad8f1..e8f3652 100644 --- a/src/declarative/graphicsitems/qdeclarativeitem.cpp +++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp @@ -83,7 +83,44 @@ QT_BEGIN_NAMESPACE You can assign any number of Transform elements to an Item. Each Transform is applied in order, one at a time, to the Item it's assigned to. - \sa Rotation, Scale + \sa Rotation, Scale, Translate +*/ + +/*! + \qmlclass Translate QGraphicsTranslate + \since 4.7 + \brief The Translate object provides a way to move an Item without changing its x or y properties. + + The Translate object independent control over position in addition to the Item's x and y properties. + + The following example moves the Y axis of the Rectangles while still allowing the Row element + to lay the items out as if they had not been transformed: + \qml + Row { + Rectangle { + width: 100; height: 100 + color: "blue" + transform: Translate { y: 20 } + } + Rectangle { + width: 100; height: 100 + color: "red" + transform: Translate { y: -20 } + } + } + \endqml +*/ + +/*! + \qmlproperty real Translate::x + + The translation along the X axis. +*/ + +/*! + \qmlproperty real Translate::yTranslate + + The translation along the Y axis. */ /*! @@ -312,9 +349,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 +1310,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 */ @@ -1411,10 +1438,6 @@ QDeclarativeItem::~QDeclarativeItem() */ void QDeclarativeItem::setParentItem(QDeclarativeItem *parent) { - QDeclarativeItem *oldParent = parentItem(); - if (parent == oldParent || !parent) return; - - QObject::setParent(parent); QGraphicsObject::setParentItem(parent); } @@ -1462,11 +1485,6 @@ QDeclarativeItem *QDeclarativeItem::parentItem() const */ /*! - \property QDeclarativeItem::children - \internal -*/ - -/*! \property QDeclarativeItem::resources \internal */ @@ -1500,11 +1518,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 +1545,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); @@ -1561,8 +1559,8 @@ int QDeclarativeItemPrivate::transform_count(QDeclarativeListProperty<QGraphicsT void QDeclarativeItemPrivate::transform_append(QDeclarativeListProperty<QGraphicsTransform> *list, QGraphicsTransform *item) { QGraphicsObject *object = qobject_cast<QGraphicsObject *>(list->object); - if (object) - QGraphicsItemPrivate::get(object)->appendGraphicsTransform(item); + if (object) // QGraphicsItem applies the list in the wrong order, so we prepend. + QGraphicsItemPrivate::get(object)->prependGraphicsTransform(item); } QGraphicsTransform *QDeclarativeItemPrivate::transform_at(QDeclarativeListProperty<QGraphicsTransform> *list, int idx) @@ -1589,6 +1587,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 @@ -1602,7 +1608,7 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics Item { Text {} Rectangle {} - Script {} + Timer {} } \endqml @@ -1614,7 +1620,7 @@ void QDeclarativeItemPrivate::transform_clear(QDeclarativeListProperty<QGraphics Rectangle {} ] resources: [ - Script {} + Timer {} ] } \endqml @@ -1678,18 +1684,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 +1795,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 +2275,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, @@ -2403,13 +2389,11 @@ QDeclarativeListProperty<QDeclarativeTransition> QDeclarativeItem::transitions() example: \qml - Script { - function toggle() { - if (button.state == 'On') - button.state = 'Off'; - else - button.state = 'On'; - } + function toggle() { + if (button.state == 'On') + button.state = 'Off'; + else + button.state = 'On'; } \endqml @@ -2594,14 +2578,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()); - break; - case ItemChildAddedChange: - case ItemChildRemovedChange: - emit childrenChanged(); + d->parentNotifier.notify(); break; case ItemVisibleHasChanged: { for(int ii = 0; ii < d->changeListeners.count(); ++ii) { @@ -2632,7 +2613,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 +2698,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 +2761,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 +2785,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 +2848,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 +2876,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)); |