diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-08-18 00:44:15 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-08-18 00:44:15 (GMT) |
commit | b35582c2c08ffdbba91f83f0cdf775dda47af3a9 (patch) | |
tree | 80c85d1c8539c656289ede63fc4bbe03342173cd /src | |
parent | 8f5e72298fc4b8a5838bee1291a2cc422750b6b8 (diff) | |
parent | 39a2e72700aa481fefc7df7fa64d8dc8c1670d2e (diff) | |
download | Qt-b35582c2c08ffdbba91f83f0cdf775dda47af3a9.zip Qt-b35582c2c08ffdbba91f83f0cdf775dda47af3a9.tar.gz Qt-b35582c2c08ffdbba91f83f0cdf775dda47af3a9.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/fx/qfximage.cpp | 34 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.cpp | 54 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem.h | 37 | ||||
-rw-r--r-- | src/declarative/fx/qfxitem_p.h | 27 |
4 files changed, 70 insertions, 82 deletions
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 |