From 009e825d2da38b95fb2efbfbdefc4b58c8bf0fa8 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 8 May 2009 13:32:30 +1000 Subject: More Transform work. Add Rotatation. Mark poorly documented transforms as internal for now. --- doc/src/declarative/elements.qdoc | 2 - src/declarative/fx/qfxtransform.cpp | 96 ++++++++++++++++++++++++++++++++----- src/declarative/fx/qfxtransform.h | 40 ++++++++++++++-- 3 files changed, 118 insertions(+), 20 deletions(-) diff --git a/doc/src/declarative/elements.qdoc b/doc/src/declarative/elements.qdoc index ae1428a..976e2f1 100644 --- a/doc/src/declarative/elements.qdoc +++ b/doc/src/declarative/elements.qdoc @@ -141,9 +141,7 @@ The following table lists the Qml elements provided by the Qt Declarative module \o \list \o \l Squish -\o \l Perspective \o \l Rotation3D -\o \l Translation3D \endlist \o diff --git a/src/declarative/fx/qfxtransform.cpp b/src/declarative/fx/qfxtransform.cpp index cc2c21c..15edc5f 100644 --- a/src/declarative/fx/qfxtransform.cpp +++ b/src/declarative/fx/qfxtransform.cpp @@ -179,6 +179,85 @@ void QFxAxis::setEndZ(qreal z) emit updated(); } +QFxRotation::QFxRotation(QObject *parent) +: QFxTransform(parent), _angle(0), _originX(0), _originY(0), _dirty(true) +{ +} + +QFxRotation::~QFxRotation() +{ +} + +qreal QFxRotation::originX() const +{ + return _originX; +} + +void QFxRotation::setOriginX(qreal ox) +{ + _originX = ox; + update(); +} + +qreal QFxRotation::originY() const +{ + return _originY; +} + +void QFxRotation::setOriginY(qreal oy) +{ + _originY = oy; + update(); +} + +qreal QFxRotation::angle() const +{ + return _angle; +} + +void QFxRotation::setAngle(qreal angle) +{ + _angle = angle; + update(); +} + +bool QFxRotation::isIdentity() const +{ + return (_angle == 0.); +} + +#if defined(QFX_RENDER_QPAINTER) +QTransform QFxRotation::transform() const +{ + if (_dirty) { + _transform = QTransform(); + _dirty = false; + _transform.translate(_originX, _originY); + _transform.rotate(_angle); + _transform.translate(-_originX, -_originY); + } + return _transform; +} +#elif defined(QFX_RENDER_OPENGL) +QMatrix4x4 QFxRotation::transform() const +{ + if (_dirty) { + _transform = QMatrix4x4(); + _dirty = false; + _transform.rotate(_angle, _originX, _originY); + } + return _transform; +} +#endif + +void QFxRotation::update() +{ + _dirty = true; + QFxTransform::update(); +} + +QML_DEFINE_TYPE(QFxRotation, Rotation); + /*! \qmlclass Rotation3D \brief A Rotation3D object provides a way to rotate an Item around an axis. @@ -314,12 +393,11 @@ QMatrix4x4 QFxRotation3D::transform() const void QFxRotation3D::update() { _dirty = true; - QFxItem *item = qobject_cast(parent()); - if (item) - item->updateTransform(); + QFxTransform::update(); } /*! + \internal \qmlclass Translation3D \brief A Translation3D object provides a way to move an Item along an axis. @@ -448,12 +526,11 @@ void QFxTranslation3D::update() } #endif - QFxItem *item = qobject_cast(parent()); - if (item) - item->updateTransform(); + QFxTransform::update(); } /*! + \internal \qmlclass Perspective \brief A Perspective object specifies a perspective transformation. @@ -751,13 +828,6 @@ void QFxSquish::setbottomRight_y(qreal v) update(); } -void QFxSquish::update() -{ - QFxItem *item = qobject_cast(parent()); - if (item) - item->updateTransform(); -} - bool QFxSquish::isIdentity() const { return false; diff --git a/src/declarative/fx/qfxtransform.h b/src/declarative/fx/qfxtransform.h index 14bce9b..a3a1a83 100644 --- a/src/declarative/fx/qfxtransform.h +++ b/src/declarative/fx/qfxtransform.h @@ -109,6 +109,41 @@ private: }; QML_DECLARE_TYPE(QFxAxis); +class Q_DECLARATIVE_EXPORT QFxRotation : public QFxTransform +{ + Q_OBJECT + + Q_PROPERTY(qreal originX READ originX WRITE setOriginX) + Q_PROPERTY(qreal originY READ originY WRITE setOriginY) + Q_PROPERTY(qreal angle READ angle WRITE setAngle) +public: + QFxRotation(QObject *parent=0); + ~QFxRotation(); + + qreal originX() const; + void setOriginX(qreal); + + qreal originY() const; + void setOriginY(qreal); + + qreal angle() const; + void setAngle(qreal); + + virtual bool isIdentity() const; + virtual QSimpleCanvas::Matrix transform() const; + +private Q_SLOTS: + void update(); +private: + qreal _originX; + qreal _originY; + qreal _angle; + + mutable bool _dirty; + mutable QSimpleCanvas::Matrix _transform; +}; +QML_DECLARE_TYPE(QFxRotation); + class Q_DECLARATIVE_EXPORT QFxRotation3D : public QFxTransform { Q_OBJECT @@ -124,9 +159,6 @@ public: qreal angle() const; void setAngle(qreal); - qreal distanceToPlane() const; - void setDistanceToPlane(qreal); - virtual bool isIdentity() const; virtual QSimpleCanvas::Matrix transform() const; @@ -271,8 +303,6 @@ public: virtual QSimpleCanvas::Matrix transform() const; private: - void update(); - QPointF p; QSizeF s; QPointF p1, p2, p3, p4; -- cgit v0.12