From c9f4ad424949085209acda6cff07babbe8d29001 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Tue, 18 Aug 2009 10:22:01 +1000 Subject: Change Item.contents to Item.childrenRect. --- examples/declarative/clock/display.qml | 4 +- .../1_Drawing_and_animation.qml | 2 +- .../tutorials/contacts/2_Reuse/2_Reuse.qml | 2 +- .../contacts/3_Collections/3_Collections.qml | 4 +- examples/declarative/xmldata/daringfireball.qml | 2 +- examples/declarative/xmldata/yahoonews.qml | 2 +- src/declarative/fx/qfxitem.cpp | 54 ++++++++++------------ src/declarative/fx/qfxitem.h | 37 ++------------- src/declarative/fx/qfxitem_p.h | 27 +++++++++++ 9 files changed, 62 insertions(+), 72 deletions(-) diff --git a/examples/declarative/clock/display.qml b/examples/declarative/clock/display.qml index cd6dcf7..00af9b3 100644 --- a/examples/declarative/clock/display.qml +++ b/examples/declarative/clock/display.qml @@ -1,7 +1,7 @@ import Qt 4.6 Rect { - width: contents.width - height: contents.height + width: childrenRect.width + height: childrenRect.height Clock { id: Clock } } diff --git a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/1_Drawing_and_animation.qml b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/1_Drawing_and_animation.qml index a70ef16..1087d6a 100644 --- a/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/1_Drawing_and_animation.qml +++ b/examples/declarative/tutorials/contacts/1_Drawing_and_Animation/1_Drawing_and_animation.qml @@ -7,7 +7,7 @@ Rect { color: "white" VerticalPositioner { id: layout - width: contents.width + width: childrenRect.width GroupBox { contents: "1/RemoveButton.qml" label: "Rectangle Component" diff --git a/examples/declarative/tutorials/contacts/2_Reuse/2_Reuse.qml b/examples/declarative/tutorials/contacts/2_Reuse/2_Reuse.qml index 7ac513e..70b8b95 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/2_Reuse.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/2_Reuse.qml @@ -9,7 +9,7 @@ Rect { id: layout columns: 2 rows: 4 - width: contents.width + width: childrenRect.width GroupBox { contents: "1/ContactField.qml" label: "Loading: simple" diff --git a/examples/declarative/tutorials/contacts/3_Collections/3_Collections.qml b/examples/declarative/tutorials/contacts/3_Collections/3_Collections.qml index d61705c..5a22b1c 100644 --- a/examples/declarative/tutorials/contacts/3_Collections/3_Collections.qml +++ b/examples/declarative/tutorials/contacts/3_Collections/3_Collections.qml @@ -13,8 +13,8 @@ Rect { // component removes focus from any previous element GridPositioner { id: layout - width: contents.width - height: contents.height + width: childrenRect.width + height: childrenRect.height GroupBox { contents: "1/ContactView.qml" label: "list only" diff --git a/examples/declarative/xmldata/daringfireball.qml b/examples/declarative/xmldata/daringfireball.qml index 4fb12af..a93483e 100644 --- a/examples/declarative/xmldata/daringfireball.qml +++ b/examples/declarative/xmldata/daringfireball.qml @@ -26,7 +26,7 @@ Rect { Component { id: feedDelegate Item { - height: contents.height + 20 + height: childrenRect.height + 20 Text { x: 10 id: TitleText diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index 156eb31..22586b8 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -66,7 +66,7 @@ Rect { states: [ State { name: "Details" - SetProperties { target: Wrapper; height: contents.height + 10 } + SetProperties { target: Wrapper; height: childrenRect.height + 10 } SetProperties { target: Description; opacity: 1 } } ] diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index 0b86a54..f5f502c 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -69,7 +69,6 @@ QT_BEGIN_NAMESPACE #define FLT_MAX 1E+37 #endif -QML_DEFINE_NOCREATE_TYPE(QFxContents) QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Item,QFxItem) QML_DEFINE_NOCREATE_TYPE(QGraphicsTransform); @@ -210,40 +209,30 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Rotation,QGraphicsRotation) */ -QFxContents::QFxContents() : m_height(0), m_width(0) +QFxContents::QFxContents() : m_x(0), m_y(0), m_width(0), m_height(0) { } /*! - \qmlproperty qreal Item::contents.width - \qmlproperty qreal Item::contents.height + \qmlproperty qreal Item::childrenRect.x + \qmlproperty qreal Item::childrenRect.y + \qmlproperty qreal Item::childrenRect.width + \qmlproperty qreal Item::childrenRect.height - The contents properties allow an item access to the size of its + The childrenRect properties allow an item access to the geometry of its children. This property is useful if you have an item that needs to be sized to fit its children. */ -/*! - \property QFxContents::height - \brief The height of the contents. -*/ -qreal QFxContents::height() const +QRectF QFxContents::rectF() const { - return m_height; -} - -/*! - \property QFxContents::width - \brief The width of the contents. -*/ -qreal QFxContents::width() const -{ - return m_width; + return QRectF(m_x, m_y, m_width, m_height); } //TODO: optimization: only check sender(), if there is one void QFxContents::calcHeight() { + qreal oldy = m_y; qreal oldheight = m_height; qreal top = FLT_MAX; @@ -258,15 +247,18 @@ void QFxContents::calcHeight() if (y < top) top = y; } + if (!children.isEmpty()) + m_y = top; m_height = qMax(bottom - top, qreal(0.0)); - if (m_height != oldheight) - emit heightChanged(); + if (m_height != oldheight || m_y != oldy) + emit rectChanged(); } //TODO: optimization: only check sender(), if there is one void QFxContents::calcWidth() { + qreal oldx = m_x; qreal oldwidth = m_width; qreal left = FLT_MAX; @@ -281,10 +273,12 @@ void QFxContents::calcWidth() if (x < left) left = x; } + if (!children.isEmpty()) + m_x = left; m_width = qMax(right - left, qreal(0.0)); - if (m_width != oldwidth) - emit widthChanged(); + if (m_width != oldwidth || m_x != oldx) + emit rectChanged(); } void QFxContents::setItem(QFxItem *item) @@ -298,6 +292,7 @@ void QFxContents::setItem(QFxItem *item) connect(child, SIGNAL(yChanged()), this, SLOT(calcHeight())); connect(child, SIGNAL(widthChanged()), this, SLOT(calcWidth())); connect(child, SIGNAL(xChanged()), this, SLOT(calcWidth())); + connect(this, SIGNAL(rectChanged()), m_item, SIGNAL(childrenRectChanged())); } calcHeight(); @@ -1285,13 +1280,12 @@ QmlList *QFxItem::data() } /*! - \property QFxItem::contents - \brief An object that knows about the size of an item's children. + \property QFxItem::childrenRect + \brief The geometry of an item's children. - contents provides an easy way to access the (collective) width and - height of the item's children. + childrenRect provides an easy way to access the (collective) position and size of the item's children. */ -QFxContents *QFxItem::contents() +QRectF QFxItem::childrenRect() { Q_D(QFxItem); if (!d->_contents) { @@ -1299,7 +1293,7 @@ QFxContents *QFxItem::contents() d->_contents->setParent(this); d->_contents->setItem(this); } - return d->_contents; + return d->_contents->rectF(); } bool QFxItem::clip() const diff --git a/src/declarative/fx/qfxitem.h b/src/declarative/fx/qfxitem.h index d8fb983..3485985 100644 --- a/src/declarative/fx/qfxitem.h +++ b/src/declarative/fx/qfxitem.h @@ -57,37 +57,6 @@ QT_BEGIN_NAMESPACE QT_MODULE(Declarative) -class QGraphicsTransform; - -class QFxItem; -class Q_DECLARATIVE_EXPORT QFxContents : public QObject -{ - Q_OBJECT - Q_PROPERTY(qreal height READ height NOTIFY heightChanged) - Q_PROPERTY(qreal width READ width NOTIFY widthChanged) -public: - QFxContents(); - - qreal height() const; - - qreal width() const; - - void setItem(QFxItem *item); - -public Q_SLOTS: - void calcHeight(); - void calcWidth(); - -Q_SIGNALS: - void heightChanged(); - void widthChanged(); - -private: - QFxItem *m_item; - qreal m_height; - qreal m_width; -}; - class QmlState; class QFxAnchorLine; class QmlTransition; @@ -109,7 +78,7 @@ class Q_DECLARATIVE_EXPORT QFxItem : public QGraphicsObject, public QmlParserSta Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged FINAL) Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged FINAL) - Q_PROPERTY(QFxContents * contents READ contents DESIGNABLE false CONSTANT FINAL) + Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) Q_PROPERTY(QFxAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) Q_PROPERTY(QFxAnchorLine left READ left CONSTANT FINAL) Q_PROPERTY(QFxAnchorLine right READ right CONSTANT FINAL) @@ -147,7 +116,7 @@ public: QmlList *resources(); QFxAnchors *anchors(); - QFxContents *contents(); + QRectF childrenRect(); bool clip() const; void setClip(bool); @@ -190,6 +159,7 @@ Q_SIGNALS: void yChanged(); void widthChanged(); void heightChanged(); + void childrenRectChanged(); void baselineOffsetChanged(); void stateChanged(const QString &); void focusChanged(); @@ -251,7 +221,6 @@ QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QFxItem *item); QT_END_NAMESPACE -QML_DECLARE_TYPE(QFxContents) QML_DECLARE_TYPE(QFxItem) QML_DECLARE_TYPE(QGraphicsTransform) QML_DECLARE_TYPE(QGraphicsScale) diff --git a/src/declarative/fx/qfxitem_p.h b/src/declarative/fx/qfxitem_p.h index 0e916b2..1d4bef3 100644 --- a/src/declarative/fx/qfxitem_p.h +++ b/src/declarative/fx/qfxitem_p.h @@ -69,6 +69,32 @@ QT_BEGIN_NAMESPACE class QNetworkReply; class QFxKeysAttached; +//### merge into private? +class QFxContents : public QObject +{ + Q_OBJECT +public: + QFxContents(); + + QRectF rectF() const; + + void setItem(QFxItem *item); + +public Q_SLOTS: + void calcHeight(); + void calcWidth(); + +Q_SIGNALS: + void rectChanged(); + +private: + QFxItem *m_item; + qreal m_x; + qreal m_y; + qreal m_width; + qreal m_height; +}; + class QFxItemPrivate : public QGraphicsItemPrivate { Q_DECLARE_PUBLIC(QFxItem) @@ -200,4 +226,5 @@ public: }; QT_END_NAMESPACE + #endif // QFXITEM_P_H -- cgit v0.12