summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/declarative/clock/display.qml4
-rw-r--r--examples/declarative/tutorials/contacts/1_Drawing_and_Animation/1_Drawing_and_animation.qml2
-rw-r--r--examples/declarative/tutorials/contacts/2_Reuse/2_Reuse.qml2
-rw-r--r--examples/declarative/tutorials/contacts/3_Collections/3_Collections.qml4
-rw-r--r--examples/declarative/xmldata/daringfireball.qml2
-rw-r--r--examples/declarative/xmldata/yahoonews.qml2
-rw-r--r--src/declarative/fx/qfximage.cpp34
-rw-r--r--src/declarative/fx/qfxitem.cpp54
-rw-r--r--src/declarative/fx/qfxitem.h37
-rw-r--r--src/declarative/fx/qfxitem_p.h27
10 files changed, 78 insertions, 90 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/qfximage.cpp b/src/declarative/fx/qfximage.cpp
index ec3fdab..61c1411 100644
--- a/src/declarative/fx/qfximage.cpp
+++ b/src/declarative/fx/qfximage.cpp
@@ -258,77 +258,75 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *)
if (d->smooth)
p->setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform, d->smooth);
- QPixmap pix = d->pix;
-
- if (width() != pix.width() || height() != pix.height()) {
+ if (width() != d->pix.width() || height() != d->pix.height()) {
if (d->fillMode >= Tile) {
p->save();
p->setClipRect(0, 0, width(), height(), Qt::IntersectClip);
if (d->fillMode == Tile) {
- const int pw = pix.width();
- const int ph = pix.height();
+ const int pw = d->pix.width();
+ const int ph = d->pix.height();
int yy = 0;
while(yy < height()) {
int xx = 0;
while(xx < width()) {
- p->drawPixmap(xx, yy, pix);
+ p->drawPixmap(xx, yy, d->pix);
xx += pw;
}
yy += ph;
}
} else if (d->fillMode == TileVertically) {
- const int ph = pix.height();
+ const int ph = d->pix.height();
int yy = 0;
while(yy < height()) {
- p->drawPixmap(QRect(0, yy, width(), ph), pix);
+ p->drawPixmap(QRect(0, yy, width(), ph), d->pix);
yy += ph;
}
} else {
- const int pw = pix.width();
+ const int pw = d->pix.width();
int xx = 0;
while(xx < width()) {
- p->drawPixmap(QRect(xx, 0, pw, height()), pix);
+ p->drawPixmap(QRect(xx, 0, pw, height()), d->pix);
xx += pw;
}
}
p->restore();
} else {
- qreal widthScale = width() / qreal(pix.width());
- qreal heightScale = height() / qreal(pix.height());
+ qreal widthScale = width() / qreal(d->pix.width());
+ qreal heightScale = height() / qreal(d->pix.height());
QTransform scale;
if (d->fillMode == PreserveAspectFit) {
if (widthScale < heightScale) {
heightScale = widthScale;
- scale.translate(0, (height() - heightScale * pix.height()) / 2);
+ scale.translate(0, (height() - heightScale * d->pix.height()) / 2);
} else if(heightScale < widthScale) {
widthScale = heightScale;
- scale.translate((width() - widthScale * pix.width()) / 2, 0);
+ scale.translate((width() - widthScale * d->pix.width()) / 2, 0);
}
} else if (d->fillMode == PreserveAspectCrop) {
if (widthScale < heightScale) {
widthScale = heightScale;
- scale.translate((width() - widthScale * pix.width()) / 2, 0);
+ scale.translate((width() - widthScale * d->pix.width()) / 2, 0);
} else if(heightScale < widthScale) {
heightScale = widthScale;
- scale.translate(0, (height() - heightScale * pix.height()) / 2);
+ scale.translate(0, (height() - heightScale * d->pix.height()) / 2);
}
}
scale.scale(widthScale, heightScale);
QTransform old = p->transform();
p->setWorldTransform(scale * old);
- p->drawPixmap(0, 0, pix);
+ p->drawPixmap(0, 0, d->pix);
p->setWorldTransform(old);
}
} else {
- p->drawPixmap(0, 0, pix);
+ p->drawPixmap(0, 0, d->pix);
}
if (d->smooth) {
diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp
index 04fc5d9..572fcc7 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();
@@ -1287,13 +1282,12 @@ QmlList<QObject *> *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) {
@@ -1301,7 +1295,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<QObject *> *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